Skip to content

Commit

Permalink
Fix syntax highlighting when using decorator before escaped identifier (
Browse files Browse the repository at this point in the history
#6125)

fix [#4720](#4720)
  • Loading branch information
timotheeguerin authored Feb 24, 2025
1 parent 566f175 commit e9cd6e6
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@typespec/compiler"
---

Fix tmlanguage syntax highlighting when using decorator before escaped identifier
6 changes: 3 additions & 3 deletions grammars/typespec.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"name": "entity.name.tag.tsp"
}
},
"end": "(?=[_$[:alpha:]])|(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b)",
"end": "(?=([_$[:alpha:]]|`))|(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b)",
"patterns": [
{
"include": "#token"
Expand Down Expand Up @@ -141,7 +141,7 @@
"name": "entity.name.tag.tsp"
}
},
"end": "(?=[_$[:alpha:]])|(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b)",
"end": "(?=([_$[:alpha:]]|`))|(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b)",
"patterns": [
{
"include": "#token"
Expand Down Expand Up @@ -737,7 +737,7 @@
},
"namespace-name": {
"name": "meta.namespace-name.typespec",
"begin": "(?=[_$[:alpha:]])",
"begin": "(?=([_$[:alpha:]]|`))",
"end": "((?=\\{)|(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b))",
"patterns": [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler/src/server/tmlanguage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const meta: typeof tm.meta = tm.meta;
const identifierStart = "[_$[:alpha:]]";
// cspell:disable-next-line
const identifierContinue = "[_$[:alnum:]]";
const beforeIdentifier = `(?=${identifierStart})`;
const beforeIdentifier = `(?=(${identifierStart}|\`))`;
const escapedIdentifier = "`(?:[^`\\\\]|\\\\.)*`";
const simpleIdentifier = `\\b${identifierStart}${identifierContinue}*\\b`;
const identifier = `${simpleIdentifier}|${escapedIdentifier}`;
Expand Down
20 changes: 20 additions & 0 deletions packages/compiler/test/server/colorization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,26 @@ function testColorization(description: string, tokenize: Tokenize) {
]);
});

it("decorators on escaped members", async () => {
const tokens = await tokenize("enum Direction { @foo `Val 123`, @foo(123) `456 after`}");
deepStrictEqual(tokens, [
Token.keywords.enum,
Token.identifiers.type("Direction"),
Token.punctuation.openBrace,
Token.identifiers.tag("@"),
Token.identifiers.tag("foo"),
Token.identifiers.variable("`Val 123`"),
Token.punctuation.comma,
Token.identifiers.tag("@"),
Token.identifiers.tag("foo"),
Token.punctuation.openParen,
Token.literals.numeric("123"),
Token.punctuation.closeParen,
Token.identifiers.variable("`456 after`"),
Token.punctuation.closeBrace,
]);
});

it("enum with string values", async () => {
const tokens = await tokenize(`enum Direction { up: "Up", down: "Down"}`);
deepStrictEqual(tokens, [
Expand Down

0 comments on commit e9cd6e6

Please sign in to comment.