Skip to content

Commit 60f8c60

Browse files
authored
Merge pull request #323 from 333fred/generic-attributes
Support generic type arguments in attributes
2 parents 7a7482f + ae5d30d commit 60f8c60

File tree

4 files changed

+85
-1
lines changed

4 files changed

+85
-1
lines changed

grammars/csharp.tmLanguage

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,10 @@
721721
<key>include</key>
722722
<string>#type-name</string>
723723
</dict>
724+
<dict>
725+
<key>include</key>
726+
<string>#type-arguments</string>
727+
</dict>
724728
<dict>
725729
<key>include</key>
726730
<string>#attribute-arguments</string>

grammars/csharp.tmLanguage.cson

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,9 @@ repository:
475475
{
476476
include: "#type-name"
477477
}
478+
{
479+
include: "#type-arguments"
480+
}
478481
{
479482
include: "#attribute-arguments"
480483
}

src/csharp.tmLanguage.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ repository:
205205
attribute:
206206
patterns:
207207
- include: '#type-name'
208+
- include: '#type-arguments'
208209
- include: '#attribute-arguments'
209210

210211
attribute-arguments:

test/attribute.tests.ts

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,5 +177,81 @@ describe("Attributes", () => {
177177
Token.Punctuation.CloseParen,
178178
Token.Punctuation.CloseBracket]);
179179
});
180+
181+
it("Generic attributes should be highlighted single type parameter", async () => {
182+
183+
const input = `[Foo<T1>]`;
184+
const tokens = await tokenize(input);
185+
186+
tokens.should.deep.equal([
187+
Token.Punctuation.OpenBracket,
188+
Token.Type("Foo"),
189+
Token.Punctuation.TypeParameter.Begin,
190+
Token.Type("T1"),
191+
Token.Punctuation.TypeParameter.End,
192+
Token.Punctuation.CloseBracket]);
193+
});
194+
195+
it("Generic attributes should be highlighted multiple type parameters", async () => {
196+
197+
const input = `[Foo<T1, T2>]`;
198+
const tokens = await tokenize(input);
199+
200+
tokens.should.deep.equal([
201+
Token.Punctuation.OpenBracket,
202+
Token.Type("Foo"),
203+
Token.Punctuation.TypeParameter.Begin,
204+
Token.Type("T1"),
205+
Token.Punctuation.Comma,
206+
Token.Type("T2"),
207+
Token.Punctuation.TypeParameter.End,
208+
Token.Punctuation.CloseBracket]);
209+
});
210+
211+
it("Generic attributes should be highlighted multiple type parameters with regular arguments", async () => {
212+
213+
const input = `[Foo<T1, T2>(true)]`;
214+
const tokens = await tokenize(input);
215+
216+
tokens.should.deep.equal([
217+
Token.Punctuation.OpenBracket,
218+
Token.Type("Foo"),
219+
Token.Punctuation.TypeParameter.Begin,
220+
Token.Type("T1"),
221+
Token.Punctuation.Comma,
222+
Token.Type("T2"),
223+
Token.Punctuation.TypeParameter.End,
224+
Token.Punctuation.OpenParen,
225+
Token.Literal.Boolean.True,
226+
Token.Punctuation.CloseParen,
227+
Token.Punctuation.CloseBracket]);
228+
});
229+
230+
it("Generic attributes should be highlighted empty", async () => {
231+
232+
const input = `[Foo<>]`;
233+
const tokens = await tokenize(input);
234+
235+
tokens.should.deep.equal([
236+
Token.Punctuation.OpenBracket,
237+
Token.Type("Foo"),
238+
Token.Punctuation.TypeParameter.Begin,
239+
Token.Punctuation.TypeParameter.End,
240+
Token.Punctuation.CloseBracket]);
241+
});
242+
243+
it("Generic attributes should be highlighted empty with comma", async () => {
244+
245+
const input = `[Foo<,>]`;
246+
const tokens = await tokenize(input);
247+
248+
tokens.should.deep.equal([
249+
Token.Punctuation.OpenBracket,
250+
Token.Type("Foo"),
251+
Token.Punctuation.TypeParameter.Begin,
252+
Token.Punctuation.Comma,
253+
Token.Punctuation.TypeParameter.End,
254+
Token.Punctuation.CloseBracket]);
255+
});
180256
});
181-
});
257+
});

0 commit comments

Comments
 (0)