Fix #3524
This commit is contained in:
Timothee Guerin 2024-08-08 14:42:27 -07:00 коммит произвёл GitHub
Родитель 630bdd4041
Коммит 675e6d480d
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
4 изменённых файлов: 62 добавлений и 22 удалений

Просмотреть файл

@ -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.

Просмотреть файл

@ -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"

Просмотреть файл

@ -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" },
},

Просмотреть файл

@ -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", () => {