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

Colorize async as keyword in some cases #60558

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -2290,6 +2290,96 @@ static void Main(string[] args)
Parameter("args"),
Punctuation.CloseParen,
Punctuation.OpenCurly,
Punctuation.CloseCurly);
}

[Theory]
[CombinatorialData]
[WorkItem(60399, "https://github.com/dotnet/roslyn/issues/60339")]
public async Task TestAsyncInIncompleteMember(TestHost testHost)
{
await TestAsync(
@"class Test
{
public async
}",
testHost,
parseOptions: null,
Keyword("class"),
Class("Test"),
Punctuation.OpenCurly,
Keyword("public"),
Keyword("async"),
Punctuation.CloseCurly);
}

[Theory]
[CombinatorialData]
[WorkItem(60399, "https://github.com/dotnet/roslyn/issues/60339")]
public async Task TestAsyncInIncompleteMemberWhenAsyncTypeIsDefined(TestHost testHost)
{
await TestAsync(
@"[|class Test
{
public async
}|]

class async
{
}",
testHost,
parseOptions: null,
Keyword("class"),
Class("Test"),
Punctuation.OpenCurly,
Keyword("public"),
Class("async"),
Punctuation.CloseCurly);
}

[Theory]
[CombinatorialData]
[WorkItem(60399, "https://github.com/dotnet/roslyn/issues/60339")]
public async Task TestAsyncInPotentialLocalFunctionDeclaration(TestHost testHost)
{
await TestAsync(
@"void M()
{
async
}",
testHost,
parseOptions: null,
Keyword("void"),
Method("M"),
Punctuation.OpenParen,
Punctuation.CloseParen,
Punctuation.OpenCurly,
Keyword("async"),
Punctuation.CloseCurly);
}

[Theory]
[CombinatorialData]
[WorkItem(60399, "https://github.com/dotnet/roslyn/issues/60339")]
public async Task TestAsyncInPotentialLocalFunctionDeclarationWhenAsyncTypeIsDefined(TestHost testHost)
{
await TestAsync(
@"[|void M()
{
async
}|]

class async
{
}",
testHost,
parseOptions: null,
Keyword("void"),
Method("M"),
Punctuation.OpenParen,
Punctuation.CloseParen,
Punctuation.OpenCurly,
Class("async"),
Punctuation.CloseCurly);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,31 @@ private static bool TryClassifySymbol(
return true;
}

if (name is IdentifierNameSyntax { Identifier.Text: "async" } && symbol is null)
DoctorKrolic marked this conversation as resolved.
Show resolved Hide resolved
{
// MemberDeclarationSyntax examle:
//
// class Test
// {
// public async
// }
//
// ExpressionStatementSyntax example:
//
// void M()
// {
// async
// }
//
// User is probably defining an async local function here
if ((name.Parent is MemberDeclarationSyntax memberDeclaration && !memberDeclaration.Modifiers.Any(SyntaxKind.AsyncKeyword)) ||
name.Parent is ExpressionStatementSyntax)
{
classifiedSpan = new ClassifiedSpan(name.Span, ClassificationTypeNames.Keyword);
return true;
}
}

if (name.IsNint || name.IsNuint)
{
if (symbol is ITypeSymbol type && type.IsNativeIntegerType)
Expand Down