-
Notifications
You must be signed in to change notification settings - Fork 755
Fix inlay hints crash with property access expression #2273
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
Conversation
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.
Pull request overview
This PR fixes a crash in the inlay hints language server feature when processing property access expressions within computed property names. The issue specifically occurred with target: esnext when using expressions like [Symbol.dispose]() in object literals.
Key Changes:
- Added handling for
ast.KindPropertyAccessExpressionin the inlay hints display parts visitor - Added a test case to verify the fix and prevent regression
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| internal/ls/inlay_hints.go | Added a new case to handle PropertyAccessExpression nodes in the getInlayHintLabelParts switch statement, properly visiting the expression, adding a dot separator, and visiting the name |
| internal/fourslash/tests/inlayHintsUsing_test.go | Added a test case that reproduces the crash scenario using Symbol.dispose in a computed property name with target: esnext |
|
Forgot to push the baselines 🙁 |
But this still causes an inlay hint crash. using _defer = {
[Symbol["dispose"]]() {},
};So I think the right thing to do is probably guard early on not providing inlay hints if the name is not a supported node type. |
How does that crash? I can't repro it with my PR. |
Ok, I guess we can produce element accesses too in the node builder, but pretty sure nothing else. Going to update with a test for that too. |
|
What I mean more is that we shouldn't try to produce inlay hints in the first place for those - we should modify |
The function I updated only ever visits type nodes that we ourselves produce from a checker type, so modulo bugs it should only have a limited number of (well-formed) ASTs to deal with. |
|
Oh, duh, I misunderstood, sorry. |
Fixes #2241.
We needed target: esnext to repro the crash in tests.
I think the only kinds of expressions and subexpressions that can appear as a computed property name in type nodes we produce are identifiers and property/element accesses, so I've added support for those.