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

Highlight await and return in top-level statements #60401

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -323,5 +323,14 @@ class C
}
}");
}

[WorkItem(60400, "https://github.com/dotnet/roslyn/issues/60400")]
[Fact, Trait(Traits.Feature, Traits.Features.KeywordHighlighting)]
public async Task TestTopLevelStatements()
{
await TestAsync(
@"[|await|] Task.Delay(1000);
{|Cursor:[|await|]|} Task.Run(() => { })");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -462,5 +462,13 @@ void M()
}
}");
}

[Fact, Trait(Traits.Feature, Traits.Features.KeywordHighlighting)]
public async Task TestInTopLevelStatements()
{
await TestAsync(
@"if (args.Length > 0) [|return|] 0;
{|Cursor:[|return|]|} 1;");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public AsyncAwaitHighlighter()
}

protected override bool IsHighlightableNode(SyntaxNode node)
=> node.IsReturnableConstruct();
=> node.IsReturnableConstructOrTopLevelCompilationUnit();

protected override void AddHighlightsForNode(SyntaxNode node, List<TextSpan> highlights, CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected override void AddHighlights(
{
var parent = returnStatement
.GetAncestorsOrThis<SyntaxNode>()
.FirstOrDefault(n => n.IsReturnableConstruct());
.FirstOrDefault(n => n.IsReturnableConstructOrTopLevelCompilationUnit());

if (parent == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
#nullable disable

using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.Highlighting
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,9 @@ public static bool IsReturnableConstruct(this SyntaxNode node)
return false;
}

public static bool IsReturnableConstructOrTopLevelCompilationUnit(this SyntaxNode node)
=> node.IsReturnableConstruct() || (node is CompilationUnitSyntax compilationUnit && compilationUnit.Members.Any(SyntaxKind.GlobalStatement));

public static bool SpansPreprocessorDirective<TSyntaxNode>(this IEnumerable<TSyntaxNode> list) where TSyntaxNode : SyntaxNode
=> CSharpSyntaxFacts.Instance.SpansPreprocessorDirective(list);

Expand Down