-
Notifications
You must be signed in to change notification settings - Fork 657
Fix token cache parent mismatch panic in signature help #1338
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
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
This is all totally wrong. Revert everything you've done. Your test should be put into |
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Reverted all previous changes and implemented the proper fix in |
This is still wrong. Your test passes without any of the other changes. Revert |
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Reverted |
I'm pretty sure the problem here is that Instead, I think:
|
I'll implement the proper fix by rewriting |
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
You were so close until that last commit. Revert that last commit and then make |
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Reverted the last commit and implemented |
The signature help functionality was panicking with "Token cache mismatch: parent. Expected parent of kind KindAsExpression, got KindCallExpression" when the AST structure changed during refactoring operations like wrapping expressions with parentheses.
Problem
The issue occurred in the
GetOrCreateToken
method ininternal/ast/ast.go
. The token cache used only text position as the cache key, but when AST structure changes (e.g., when a user selectsarray
inarray?.at(offset)
and wraps it with parentheses to get(array)?.at(offset)
), the same token positions could legitimately have different parent nodes. The original implementation panicked on any parent mismatch.Root Cause
In
getTokensFromNode
(called during signature help processing), all tokens within a node's range were created with the same parent node, regardless of their actual position in the AST hierarchy. When the AST structure changed due to refactoring, this assumption broke and caused the panic.Solution
Modified
GetOrCreateToken
to handle parent mismatches gracefully:Testing
Added comprehensive tests to verify:
The fix ensures the language server remains stable during common refactoring operations while maintaining performance benefits of the token cache.
Fixes #1298.
💡 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.