Skip to content

Commit

Permalink
Support generic type arguments in attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
333fred committed Jun 14, 2024
1 parent 7a7482f commit d63e266
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
4 changes: 4 additions & 0 deletions grammars/csharp.tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,10 @@
<key>include</key>
<string>#type-name</string>
</dict>
<dict>
<key>include</key>
<string>#type-arguments</string>
</dict>
<dict>
<key>include</key>
<string>#attribute-arguments</string>
Expand Down
3 changes: 3 additions & 0 deletions grammars/csharp.tmLanguage.cson
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,9 @@ repository:
{
include: "#type-name"
}
{
include: "#type-arguments"
}
{
include: "#attribute-arguments"
}
Expand Down
1 change: 1 addition & 0 deletions src/csharp.tmLanguage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ repository:
attribute:
patterns:
- include: '#type-name'
- include: '#type-arguments'
- include: '#attribute-arguments'

attribute-arguments:
Expand Down
59 changes: 58 additions & 1 deletion test/attribute.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,62 @@ describe("Attributes", () => {
Token.Punctuation.CloseParen,
Token.Punctuation.CloseBracket]);
});

it("Generic attributes should be highlighted single type parameter", async () => {

const input = `[Foo<T1>]`;
const tokens = await tokenize(input);

tokens.should.deep.equal([
Token.Punctuation.OpenBracket,
Token.Type("Foo"),
Token.Punctuation.TypeParameter.Begin,
Token.Type("T1"),
Token.Punctuation.TypeParameter.End,
Token.Punctuation.CloseBracket]);
});

it("Generic attributes should be highlighted multiple type parameters", async () => {

const input = `[Foo<T1, T2>]`;
const tokens = await tokenize(input);

tokens.should.deep.equal([
Token.Punctuation.OpenBracket,
Token.Type("Foo"),
Token.Punctuation.TypeParameter.Begin,
Token.Type("T1"),
Token.Punctuation.Comma,
Token.Type("T2"),
Token.Punctuation.TypeParameter.End,
Token.Punctuation.CloseBracket]);
});

it("Generic attributes should be highlighted empty", async () => {

const input = `[Foo<>]`;
const tokens = await tokenize(input);

tokens.should.deep.equal([
Token.Punctuation.OpenBracket,
Token.Type("Foo"),
Token.Punctuation.TypeParameter.Begin,
Token.Punctuation.TypeParameter.End,
Token.Punctuation.CloseBracket]);
});

it("Generic attributes should be highlighted empty with comma", async () => {

const input = `[Foo<,>]`;
const tokens = await tokenize(input);

tokens.should.deep.equal([
Token.Punctuation.OpenBracket,
Token.Type("Foo"),
Token.Punctuation.TypeParameter.Begin,
Token.Punctuation.Comma,
Token.Punctuation.TypeParameter.End,
Token.Punctuation.CloseBracket]);
});
});
});
});

0 comments on commit d63e266

Please sign in to comment.