Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support generic type arguments in attributes #323

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
78 changes: 77 additions & 1 deletion test/attribute.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,81 @@ 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 multiple type parameters with regular arguments", async () => {

const input = `[Foo<T1, T2>(true)]`;
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.OpenParen,
Token.Literal.Boolean.True,
Token.Punctuation.CloseParen,
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]);
});
});
});
});
Loading