diff --git a/grammars/csharp.tmLanguage b/grammars/csharp.tmLanguage index 25fb7b4..037851c 100644 --- a/grammars/csharp.tmLanguage +++ b/grammars/csharp.tmLanguage @@ -721,6 +721,10 @@ include #type-name + + include + #type-arguments + include #attribute-arguments diff --git a/grammars/csharp.tmLanguage.cson b/grammars/csharp.tmLanguage.cson index e61aaf8..09a93ba 100644 --- a/grammars/csharp.tmLanguage.cson +++ b/grammars/csharp.tmLanguage.cson @@ -475,6 +475,9 @@ repository: { include: "#type-name" } + { + include: "#type-arguments" + } { include: "#attribute-arguments" } diff --git a/src/csharp.tmLanguage.yml b/src/csharp.tmLanguage.yml index fe43f6b..e15c354 100644 --- a/src/csharp.tmLanguage.yml +++ b/src/csharp.tmLanguage.yml @@ -205,6 +205,7 @@ repository: attribute: patterns: - include: '#type-name' + - include: '#type-arguments' - include: '#attribute-arguments' attribute-arguments: diff --git a/test/attribute.tests.ts b/test/attribute.tests.ts index 4df1697..e1f9def 100644 --- a/test/attribute.tests.ts +++ b/test/attribute.tests.ts @@ -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]`; + 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]`; + 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(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]); + }); }); -}); \ No newline at end of file +});