Fix token cache parent mismatch panics#2789
Conversation
|
In an ideal world we wouldn't need a |
There was a problem hiding this comment.
Pull request overview
This PR fixes panics caused by token cache mismatches where tokens were cached by position alone, but different parent nodes could exist at the same position after reparsing. The solution changes the cache key to include both the parent node and position, and adds checks to skip reparsed nodes during traversal.
Changes:
- Modified token cache to use parent + position as key instead of position alone
- Added checks to skip reparsed nodes in AST traversal functions
- Added regression test for JSDoc completion crash scenario
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| internal/ast/ast.go | Introduced TokenCacheKey struct combining parent and position; updated tokenCache map key type and removed redundant parent validation |
| internal/astnav/tokens.go | Added reparsed node checks to early-exit visitor functions, preventing traversal of stale AST nodes |
| internal/ls/lsutil/children.go | Fixed logic to properly skip reparsed nodes using positive condition instead of double-negative |
| internal/fourslash/tests/completionJSDocNoCrash_test.go | Added regression test verifying JSDoc completion doesn't crash |
|
@jakebailey Is there a typescript-bot command that'll kick off another fuzzer run? |
|
Nope, that run was manual, as Gabriela just added the pipeline. |
This PR fixes the 11 occurrences of "Token cache mismatch: parent" panics observed in #2778.
The PR includes a fourslash test that reproduces the issue in this run. The others are of a similar nature, so no need for further tests.