-
Notifications
You must be signed in to change notification settings - Fork 4.2k
fix: Add check before show signature help #80945
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
base: main
Are you sure you want to change the base?
Conversation
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.
| private static bool IsPositionInLambdaBlock(SyntaxNode root, int position) | ||
| { | ||
| var token = root.FindToken(position); | ||
| var lambda = token.Parent?.AncestorsAndSelf().OfType<LambdaExpressionSyntax>().FirstOrDefault(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably be AnonymousMethodExpressionSyntax
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| void M1(Action a) { } | ||
| void M2() | ||
| { | ||
| M1(() => |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.

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:
SignatureHelpUtilitiesto detect when the cursor is inside a lambda block and prevent signature help from appearing in these cases. [1] [2]Testing:
NoSignatureHelpInsideLambdaBlockinInvocationExpressionSignatureHelpProviderTests.csto ensure signature help is not triggered inside lambda blocks.Fixes #79733