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

Allow params keyword completion in lambdas #65043

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 @@ -213,6 +213,20 @@ await VerifyKeywordAsync(
@"delegate void D(int i, [Goo]$$");
}

[Fact]
public async Task TestAfterLambdaOpenParen()
{
await VerifyKeywordAsync(
@"var lam = ($$");
}

[Fact]
public async Task TestAfterLambdaComma()
{
await VerifyKeywordAsync(
@"var lam = (int i, $$");
}

[Fact]
public async Task TestNotAfterOperator()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10151,6 +10151,86 @@ class C
End Using
End Function

<WpfTheory, CombinatorialData>
<Trait(Traits.Feature, Traits.Features.Completion)>
Public Async Function CompletionForLambdaParamsArray(showCompletionInArgumentLists As Boolean) As Task
Using state = TestStateFactory.CreateCSharpTestState(
<Document>
class C
{
void M()
{
var lam = ($$
}
}
</Document>,
showCompletionInArgumentLists:=showCompletionInArgumentLists, languageVersion:=LanguageVersion.Preview)

state.SendTypeChars("p")
Await state.AssertSelectedCompletionItem(displayText:="params")
End Using
End Function

<WpfTheory, CombinatorialData>
<Trait(Traits.Feature, Traits.Features.Completion)>
Public Async Function CompletionForLambdaParamsArray_BeforeParameter(showCompletionInArgumentLists As Boolean) As Task
Using state = TestStateFactory.CreateCSharpTestState(
<Document>
class C
{
void M()
{
var lam = ($$ int[] xs) => { };
}
}
</Document>,
showCompletionInArgumentLists:=showCompletionInArgumentLists, languageVersion:=LanguageVersion.Preview)

state.SendTypeChars("p")
Await state.AssertSelectedCompletionItem(displayText:="params")
End Using
End Function

<WpfTheory, CombinatorialData>
<Trait(Traits.Feature, Traits.Features.Completion)>
Public Async Function CompletionForLambdaParamsArray_AfterParameter(showCompletionInArgumentLists As Boolean) As Task
Using state = TestStateFactory.CreateCSharpTestState(
<Document>
class C
{
void M()
{
var lam = (int x, $$
}
}
</Document>,
showCompletionInArgumentLists:=showCompletionInArgumentLists, languageVersion:=LanguageVersion.Preview)

state.SendTypeChars("p")
Await state.AssertSelectedCompletionItem(displayText:="params")
End Using
End Function

<WpfTheory, CombinatorialData>
<Trait(Traits.Feature, Traits.Features.Completion)>
Public Async Function CompletionForLambdaParamsArray_AfterOptionalParameter(showCompletionInArgumentLists As Boolean) As Task
Using state = TestStateFactory.CreateCSharpTestState(
<Document>
class C
{
void M()
{
var lam = (int x = 1, $$) => { };
}
}
</Document>,
showCompletionInArgumentLists:=showCompletionInArgumentLists, languageVersion:=LanguageVersion.Preview)

state.SendTypeChars("p")
Await state.AssertSelectedCompletionItem(displayText:="params")
End Using
End Function

' Simulate the situation that some provider (e.g. IntelliCode) provides items with higher match priority that only match case-insensitively.
<ExportCompletionProvider(NameOf(PreselectionProvider), LanguageNames.CSharp)>
<[Shared]>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public ParamsKeywordRecommender()
}

protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken)
=> context.SyntaxTree.IsParamsModifierContext(context.Position, context.LeftToken);
=> context.SyntaxTree.IsParamsModifierContext(position, context.LeftToken, cancellationToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1099,14 +1099,20 @@ parameter3.Parent is ParameterListSyntax parameterList3 &&
public static bool IsParamsModifierContext(
this SyntaxTree syntaxTree,
int position,
SyntaxToken tokenOnLeftOfPosition)
SyntaxToken tokenOnLeftOfPosition,
CancellationToken cancellationToken)
{
if (syntaxTree.IsParameterModifierContext(position, tokenOnLeftOfPosition, includeOperators: false, out _, out var previousModifier) &&
previousModifier == SyntaxKind.None)
{
return true;
}

if (syntaxTree.IsPossibleLambdaParameterModifierContext(position, tokenOnLeftOfPosition, cancellationToken))
{
return true;
}

var token = tokenOnLeftOfPosition;
token = token.GetPreviousTokenIfTouchingWord(position);

Expand Down