From d63e2661d4e0c83b6c7810eb1d0eedc5da843b04 Mon Sep 17 00:00:00 2001 From: Fredric Silberberg Date: Fri, 14 Jun 2024 14:08:44 -0700 Subject: [PATCH 1/2] Support generic type arguments in attributes --- grammars/csharp.tmLanguage | 4 +++ grammars/csharp.tmLanguage.cson | 3 ++ src/csharp.tmLanguage.yml | 1 + test/attribute.tests.ts | 59 ++++++++++++++++++++++++++++++++- 4 files changed, 66 insertions(+), 1 deletion(-) 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..0b05888 100644 --- a/test/attribute.tests.ts +++ b/test/attribute.tests.ts @@ -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]`; + 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 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 +}); From ae5d30d9de32bb8b7000355250d9e3cd720da869 Mon Sep 17 00:00:00 2001 From: Fredric Silberberg Date: Fri, 14 Jun 2024 14:11:52 -0700 Subject: [PATCH 2/2] Add 1 more test --- test/attribute.tests.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/attribute.tests.ts b/test/attribute.tests.ts index 0b05888..e1f9def 100644 --- a/test/attribute.tests.ts +++ b/test/attribute.tests.ts @@ -208,6 +208,25 @@ describe("Attributes", () => { 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<>]`;