Skip to content

Commit

Permalink
Add support for completion of extends and is (#3443)
Browse files Browse the repository at this point in the history
fixes #3152
  • Loading branch information
RodgeFu authored Jun 13, 2024
1 parent 5bc98d9 commit e4c4d2b
Show file tree
Hide file tree
Showing 9 changed files with 606 additions and 143 deletions.
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

0 comments on commit e4c4d2b

Please sign in to comment.