Skip to content

Conversation

@sami-daniel
Copy link
Contributor

Add a check before displaying Signature Help by verifying if we are inside a lambda block so the signature is shown correctly only when appropriate.

This pull request addresses an issue where signature help was incorrectly triggered inside the body of lambda expressions in C#.

The main change is to prevent signature help from appearing when the cursor is inside a lambda block, improving the user
experience in scenarios involving lambdas. The update includes both the implementation of the fix and an associated unit test to verify the new behavior.

Signature Help Behavior Improvements:

  • Added logic in SignatureHelpUtilities to detect when the cursor is inside a lambda block and prevent signature help from appearing in these cases. [1] [2]

Testing:

  • Added a unit test NoSignatureHelpInsideLambdaBlock in InvocationExpressionSignatureHelpProviderTests.cs to ensure signature help is not triggered inside lambda blocks.

Fixes #79733

Add a check before displaying Signature Help by verifying if we are
inside a lambda block so the signature is shown correctly only when appropriate.
@sami-daniel sami-daniel requested a review from a team as a code owner October 28, 2025 22:58
@dotnet-policy-service dotnet-policy-service bot added Community The pull request was submitted by a contributor who is not a Microsoft employee. VSCode labels Oct 28, 2025
private static bool IsPositionInLambdaBlock(SyntaxNode root, int position)
{
var token = root.FindToken(position);
var lambda = token.Parent?.AncestorsAndSelf().OfType<LambdaExpressionSyntax>().FirstOrDefault();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably be AnonymousMethodExpressionSyntax

Copy link
Contributor Author

@sami-daniel sami-daniel Oct 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{399FB61A-1345-41B9-9A97-B5E3F3EA7F44}

Just a question, because the error appear in both cases. Shouldn't this statement be an AND checking for AnonymousMethodExpressionSyntax or LambdaExpressionSyntax (since they cannot be coerced into each other from the standpoint of inheritance)? Because the error appear for both cases...

void M1(Action a) { }
void M2()
{
M1(() =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add tests for a=> and then an anonymous delegate as well.

… lambda expression and statementes, including parenthesized and anonymous block
private static TextSpan? GetSyntaxSpan(SyntaxNode? node)
{
var ancestors = node?.AncestorsAndSelf();
var lambda = ancestors?.OfType<LambdaExpressionSyntax>().FirstOrDefault();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use the common super type of these types just once. Greatly simplifying things

Now is using a super type for it called AnonymousFunctionExpressionSyntax, reducing the nescessary code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee. VSCode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unexpected parameter info pop-up when typing certain tokens inside expression as argument

2 participants