Skip to content

Add support for local function attributes #312

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -4784,6 +4784,10 @@
<key>include</key>
<string>#local-variable-declaration</string>
</dict>
<dict>
<key>include</key>
<string>#attribute-section</string>
</dict>
<dict>
<key>include</key>
<string>#local-function-declaration</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 @@ -2920,6 +2920,9 @@ repository:
{
include: "#local-variable-declaration"
}
{
include: "#attribute-section"
}
{
include: "#local-function-declaration"
}
Expand Down
1 change: 1 addition & 0 deletions src/csharp.tmLanguage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1732,6 +1732,7 @@ repository:
patterns:
- include: '#local-constant-declaration'
- include: '#local-variable-declaration'
- include: '#attribute-section'
- include: '#local-function-declaration'
- include: '#local-tuple-var-deconstruction'

Expand Down
26 changes: 26 additions & 0 deletions test/local.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,5 +280,31 @@ int Add(int x, int y)
Token.Punctuation.CloseBrace
]);
});

it("local function with attribute (issue #304)", async () => {
const input = Input.InMethod(`
[Attribute]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Man, I do not know what we're going to do for collection expressions here. It's not going to be fun.

static void M([Attribute]object obj) {}
`);
const tokens = await tokenize(input);

tokens.should.deep.equal([
Token.Punctuation.OpenBracket,
Token.Type("Attribute"),
Token.Punctuation.CloseBracket,
Token.Keyword.Modifier.Static,
Token.PrimitiveType.Void,
Token.Identifier.MethodName("M"),
Token.Punctuation.OpenParen,
Token.Punctuation.OpenBracket,
Token.Type("Attribute"),
Token.Punctuation.CloseBracket,
Token.PrimitiveType.Object,
Token.Identifier.ParameterName("obj"),
Token.Punctuation.CloseParen,
Token.Punctuation.OpenBrace,
Token.Punctuation.CloseBrace
]);
});
});
});