Skip to content

Commit

Permalink
Fix type argument tmlanguage (#4089)
Browse files Browse the repository at this point in the history
Fix #3524
  • Loading branch information
timotheeguerin authored Aug 8, 2024
1 parent 630bdd4 commit 675e6d4
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: fix
packages:
- "@typespec/compiler"
---

Fix tmlanguage for named type argument in type reference.
2 changes: 1 addition & 1 deletion grammars/typespec.json
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@
"name": "keyword.operator.assignment.tsp"
}
},
"end": "=",
"end": "(?=>)|(?=,|;|@|\\)|\\}|\\b(?:extern)\\b|\\b(?:namespace|model|op|using|import|enum|alias|union|interface|dec|fn)\\b)",
"endCaptures": {
"0": {
"name": "keyword.operator.assignment.tsp"
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 @@ -343,7 +343,7 @@ const typeArgument: BeginEndRule = {
"1": { scope: "entity.name.type.tsp" },
"2": { scope: "keyword.operator.assignment.tsp" },
},
end: `=`,
end: `(?=>)|${universalEnd}`,
endCaptures: {
"0": { scope: "keyword.operator.assignment.tsp" },
},
Expand Down
72 changes: 52 additions & 20 deletions packages/compiler/test/server/colorization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -827,26 +827,58 @@ function testColorization(description: string, tokenize: Tokenize) {
});
});

it("named template argument list", async () => {
const tokens = await tokenize("alias X = Foo<boolean, T = string, U = int32>;");
deepStrictEqual(tokens, [
Token.keywords.alias,
Token.identifiers.type("X"),
Token.operators.assignment,
Token.identifiers.type("Foo"),
Token.punctuation.typeParameters.begin,
Token.identifiers.type("boolean"),
Token.punctuation.comma,
Token.identifiers.type("T"),
Token.operators.assignment,
Token.identifiers.type("string"),
Token.punctuation.comma,
Token.identifiers.type("U"),
Token.operators.assignment,
Token.identifiers.type("int32"),
Token.punctuation.typeParameters.end,
Token.punctuation.semicolon,
]);
describe("template argument", () => {
it("multiple named arguments", async () => {
const tokens = await tokenize("alias X = Foo<boolean, T = string, U = int32>;");
deepStrictEqual(tokens, [
Token.keywords.alias,
Token.identifiers.type("X"),
Token.operators.assignment,
Token.identifiers.type("Foo"),
Token.punctuation.typeParameters.begin,
Token.identifiers.type("boolean"),
Token.punctuation.comma,
Token.identifiers.type("T"),
Token.operators.assignment,
Token.identifiers.type("string"),
Token.punctuation.comma,
Token.identifiers.type("U"),
Token.operators.assignment,
Token.identifiers.type("int32"),
Token.punctuation.typeParameters.end,
Token.punctuation.semicolon,
]);
});

it("multiple references", async () => {
const tokens = await tokenize(`
alias A = Foo<Parameters=string>;
alias B = Foo<Parameters=string>;
`);
deepStrictEqual(tokens, [
Token.keywords.alias,
Token.identifiers.type("A"),
Token.operators.assignment,
Token.identifiers.type("Foo"),
Token.punctuation.typeParameters.begin,
Token.identifiers.type("Parameters"),
Token.operators.assignment,
Token.identifiers.type("string"),
Token.punctuation.typeParameters.end,
Token.punctuation.semicolon,
// --
Token.keywords.alias,
Token.identifiers.type("B"),
Token.operators.assignment,
Token.identifiers.type("Foo"),
Token.punctuation.typeParameters.begin,
Token.identifiers.type("Parameters"),
Token.operators.assignment,
Token.identifiers.type("string"),
Token.punctuation.typeParameters.end,
Token.punctuation.semicolon,
]);
});
});

describe("enums", () => {
Expand Down

0 comments on commit 675e6d4

Please sign in to comment.