提交 5bd7a6dd 编写于 作者: C CyrusNajmabadi

Add 'throw' keyword ot the completion list in certain contexts.

上级 8730c582
......@@ -143,5 +143,55 @@ public async Task TestInNestedIf()
if (caseOrDefaultKeyword.Kind != SyntaxKind.CaseKeyword && caseOrDefaultKeyword.Kind != SyntaxKind.DefaultKeyword)
$$"));
}
[WorkItem(9099, "https://github.com/dotnet/roslyn/issues/9099")]
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
public async Task TestAfterArrow()
{
await VerifyKeywordAsync(
@"class C
{
void Foo() => $$
");
}
[WorkItem(9099, "https://github.com/dotnet/roslyn/issues/9099")]
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
public async Task TestAfterQuestionQuestion()
{
await VerifyKeywordAsync(
@"class C
{
public C(object o)
{
_o = o ?? $$
");
}
[WorkItem(9099, "https://github.com/dotnet/roslyn/issues/9099")]
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
public async Task TestInConditional1()
{
await VerifyKeywordAsync(
@"class C
{
public C(object o)
{
var v= true ? $$
");
}
[WorkItem(9099, "https://github.com/dotnet/roslyn/issues/9099")]
[Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)]
public async Task TestInConditional2()
{
await VerifyKeywordAsync(
@"class C
{
public C(object o)
{
var v= true ? 0 : $$
");
}
}
}
......@@ -14,9 +14,32 @@ public ThrowKeywordRecommender()
protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
{
return
context.IsStatementContext ||
context.IsGlobalStatementContext;
if (context.IsStatementContext || context.IsGlobalStatementContext)
{
return true;
}
// void M() => throw
if (context.TargetToken.Kind() == SyntaxKind.EqualsGreaterThanToken)
{
return true;
}
// val ?? throw
if (context.TargetToken.Kind() == SyntaxKind.QuestionQuestionToken)
{
return true;
}
// expr ? throw : ...
// expr ? ... : throw
if (context.TargetToken.Kind() == SyntaxKind.QuestionToken ||
context.TargetToken.Kind() == SyntaxKind.ColonToken)
{
return context.TargetToken.Parent.Kind() == SyntaxKind.ConditionalExpression;
}
return false;
}
}
}
}
\ No newline at end of file
......@@ -513,12 +513,7 @@ public static bool IsAfterYieldKeyword(this SyntaxToken targetToken)
// yield |
// yield r|
if (targetToken.IsKindOrHasMatchingText(SyntaxKind.YieldKeyword))
{
return true;
}
return false;
return targetToken.IsKindOrHasMatchingText(SyntaxKind.YieldKeyword);
}
public static bool IsAnyAccessorDeclarationContext(this SyntaxToken targetToken, int position, SyntaxKind kind = SyntaxKind.None)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册