-
Notifications
You must be signed in to change notification settings - Fork 663
Fix signature help ranges to prevent display after closing parentheses #1420
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
…arenthesis Co-authored-by: DanielRosenwasser <[email protected]>
…sues Co-authored-by: DanielRosenwasser <[email protected]>
internal/ls/signaturehelp.go
Outdated
argRange := argumentInfo.argumentsRange | ||
if position < argRange.Pos() || position > argRange.End() { | ||
return nil | ||
} |
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.
I think the real fix is to implement/port the commented out code:
// !!!
// const containingList = findContainingList(startingToken);
// return !!containingList && contains(invocationChildren, containingList);
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.
I've implemented the commented-out code as suggested. The fix includes:
- Proper
findContainingList
logic for comma tokens withcontainsNodeList
helper function - Extended
isSyntacticOwner
to handleCloseParenToken
cases to prevent signature help after closing parentheses - Added
getASTChildren
helper to work with AST structure instead of just tokens - Applied syntactic owner checks for critical cases like
CloseParenToken
even whenonlyUseSyntacticOwners
is false
The range-based fix has been replaced with this more comprehensive TypeScript-compatible solution in commit 8991cdb.
- Implemented the commented-out findContainingList logic for comma tokens in isSyntacticOwner - Added proper NodeList containment checking with containsNodeList helper function - Extended isSyntacticOwner to handle CloseParenToken to prevent signature help after closing parentheses - Modified getCandidateOrTypeInfo to apply syntactic owner checks for critical cases like CloseParenToken - Added getASTChildren helper to get proper AST children instead of just tokens - Added nil check for candidateInfo to prevent crashes when syntactic owner check fails - Reverted the previous range-based fix in favor of this more comprehensive solution Co-authored-by: DanielRosenwasser <[email protected]>
Signature help was incorrectly being shown for positions after closing parentheses and in whitespace following function calls. For example:
Previously, both
afterCall
andafterNewline
positions would incorrectly show signature help for thefoo
method when they should show none.Root Cause
The issue was in
getContainingArgumentInfo
which was finding argument information forKindCloseParenToken
nodes even when the cursor position was at or after the end of the closing parenthesis. This caused signature help to be displayed in positions where it shouldn't appear.Solution
Added logic to skip
KindCloseParenToken
nodes when the position is at or after their end position:Testing
TestSignatureHelpRangeIssue
that validates signature help is shown inside calls but not after closing parenthesesrunSignatureHelpTestWithNil
test helper to validate cases where signature help should NOT be providedTestSignatureHelpNestedCallPrecedence
to document a related issue with nested call precedence (to be addressed separately)Impact
This fix improves the user experience by ensuring signature help only appears in appropriate contexts within function calls, eliminating the confusing behavior where signature help would persist after completing a function call.
Addressing #1419.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.