未验证 提交 8fa41dea 编写于 作者: J Julien Couvreur 提交者: GitHub

Recommend keyword static for static local functions (#32187)

上级 f74016a7
......@@ -81,7 +81,7 @@ private async Task CheckResultAsync(bool absent, int position, CSharpSyntaxConte
}
else
{
var result = (await RecommendKeywordsAsync(position, context)).Single();
var result = (await RecommendKeywordsAsync(position, context)).SingleOrDefault();
Assert.True(result != null, "No recommended keywords");
Assert.Equal(keywordText, result.Keyword);
if (matchPriority != null)
......
......@@ -48,9 +48,10 @@ public async Task TestNotInUsingAlias()
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
public async Task TestNotInEmptyStatement()
[WorkItem(32174, "https://github.com/dotnet/roslyn/issues/32174")]
public async Task TestInEmptyStatement()
{
await VerifyAbsenceAsync(AddInsideMethod(
await VerifyKeywordAsync(AddInsideMethod(
@"$$"));
}
......@@ -276,12 +277,17 @@ public async Task TestNotAfterDelegate()
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(32214, "https://github.com/dotnet/roslyn/issues/32214")]
public async Task TestNotBetweenUsings()
{
await VerifyAbsenceAsync(AddInsideMethod(
@"using Goo;
var source = @"using Goo;
$$
using Bar;"));
using Bar;";
await VerifyWorkerAsync(source, absent: true);
// Recommendation in scripting is not stable. See https://github.com/dotnet/roslyn/issues/32214
//await VerifyWorkerAsync(source, absent: true, Options.Script);
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
......@@ -343,5 +349,28 @@ public async Task TestNotAfterUsingInMethodBody()
void M() {
using $$");
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
[WorkItem(32174, "https://github.com/dotnet/roslyn/issues/32174")]
public async Task TestLocalFunction()
{
await VerifyKeywordAsync(AddInsideMethod(@" $$ void local() { }"));
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
public async Task TestInCase()
{
await VerifyKeywordAsync(AddInsideMethod(@"
switch (i)
{
case 0:
$$"));
}
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
public async Task TestInFor()
{
await VerifyAbsenceAsync(AddInsideMethod(@" for (int i = 0; i < 0; $$) "));
}
}
}
......@@ -55,6 +55,7 @@ protected override bool IsValidContext(int position, CSharpSyntaxContext context
return
context.IsGlobalStatementContext ||
context.TargetToken.IsUsingKeywordInUsingDirective() ||
context.IsStatementContext ||
IsValidContextForType(context, cancellationToken) ||
IsValidContextForMember(context, cancellationToken);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册