Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for completion of extends and is #3443

Merged
merged 7 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
changeKind: feature
packages:
- "@typespec/compiler"
---

Support completion for keyword 'extends' and 'is'

Example
```tsp
model Dog ┆ {}
| [extends]
| [is]

scalar Addresss ┆
| [extends]

op jump ┆
| [is]

interface ResourceA ┆ {}
| [extends]

model Cat<T ┆> {}
| [extends]
```

13 changes: 8 additions & 5 deletions packages/compiler/src/core/charcode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,17 +247,20 @@ export function isNonAsciiIdentifierCharacter(codePoint: number) {
return lookupInNonAsciiMap(codePoint, nonAsciiIdentifierMap);
}

export function codePointBefore(text: string, pos: number): number | undefined {
if (pos <= 0 || pos >= text.length) {
return undefined;
export function codePointBefore(
text: string,
pos: number
): { char: number | undefined; size: number } {
if (pos <= 0 || pos > text.length) {
return { char: undefined, size: 0 };
}

const ch = text.charCodeAt(pos - 1);
if (!isLowSurrogate(ch) || !isHighSurrogate(text.charCodeAt(pos - 2))) {
return ch;
return { char: ch, size: 1 };
}

return text.codePointAt(pos - 2);
return { char: text.codePointAt(pos - 2), size: 2 };
}

function lookupInNonAsciiMap(codePoint: number, map: readonly number[]) {
Expand Down
Loading
Loading