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 6 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
179 changes: 179 additions & 0 deletions src/EditorFeatures/CSharpTest/Classification/TotalClassifierTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2292,5 +2292,184 @@ static void Main(string[] args)
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);
}

[Theory]
[CombinatorialData]
[WorkItem(60399, "https://github.com/dotnet/roslyn/issues/60339")]
public async Task TestAsyncAsLocalMemberType(TestHost testHost)
{
await TestAsync(
@"class Test
{
void M()
{
[|async a;|]
}
}",
testHost,
parseOptions: null,
Identifier("async"),
Local("a"),
Punctuation.Semicolon);
}

[Theory]
[CombinatorialData]
[WorkItem(60399, "https://github.com/dotnet/roslyn/issues/60339")]
public async Task TestAsyncAsPropertyType(TestHost testHost)
{
await TestAsync(
@"class Test
{
[|public async Prop { get; set; }|]
}",
testHost,
parseOptions: null,
Keyword("public"),
Identifier("async"),
Property("Prop"),
Punctuation.OpenCurly,
Keyword("get"),
Punctuation.Semicolon,
Keyword("set"),
Punctuation.Semicolon,
Punctuation.CloseCurly);
}

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

[Theory]
[CombinatorialData]
[WorkItem(60399, "https://github.com/dotnet/roslyn/issues/60339")]
public async Task TestAsyncAsAccessingName(TestHost testHost)
{
await TestAsync(
@"class Test
{
void M()
{
var a = [|C.async;|]
}
}

class C
{
public static int async;
}",
testHost,
parseOptions: null,
Class("C"),
Operators.Dot,
Field("async"),
Static("async"),
Punctuation.Semicolon);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,31 @@ CandidateReason.Ambiguous or
return true;
}

if (name is IdentifierNameSyntax { Identifier.Text: "async" } && symbol is null)
DoctorKrolic marked this conversation as resolved.
Show resolved Hide resolved
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 IncompleteMemberSyntax incompletemember && !incompletemember.Modifiers.Any(SyntaxKind.AsyncKeyword)) ||
name.Parent is ExpressionStatementSyntax)
DoctorKrolic marked this conversation as resolved.
Show resolved Hide resolved
{
result.Add(new(name.Span, ClassificationTypeNames.Keyword));
return true;
}
}

return false;
}

Expand Down