Fix completions for contextually constrained types in JSDoc#3011
Fix completions for contextually constrained types in JSDoc#3011DanielRosenwasser wants to merge 4 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a crash in the language service when requesting completions for contextual type-argument constraints inside JSDoc object types (nil symbol on a PropertySignature), and adds coverage to prevent regressions.
Changes:
- Update
getConstraintOfTypeArgumentPropertyto prefer a reparsed (JSDoc-cloned) node’s symbol when available, with a fallback to the property’s declared name. - Add a new fourslash test that exercises the two reported JSDoc scenarios (with and without an attachable declaration) and verifies string-literal completions.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
internal/ls/completions.go |
Avoids nil dereference by using the reparsed node’s symbol (or property name text) to look up the contextual property type for constraint-based completions. |
internal/fourslash/tests/completionsForContextualConstraintTypeInJsDoc_test.go |
Adds regression coverage for contextual-constraint completions in JSDoc object type arguments. |
|
|
||
| f.VerifyCompletions(t, f.Markers(), &fourslash.CompletionsExpectedList{ | ||
| IsIncomplete: false, | ||
| ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{CommitCharacters: &[]string{".", ",", ";"}}, |
There was a problem hiding this comment.
CompletionsExpectedItemDefaults.EditRange is left as nil here, which will assert that the server returns a nil CompletionItemDefaults.EditRange. For type-literal completions the server typically sets an edit range; this test should set EditRange to Ignored (or assert the exact range) to avoid a hard failure.
| ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{CommitCharacters: &[]string{".", ",", ";"}}, | |
| ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{ | |
| CommitCharacters: &[]string{".", ",", ";"}, | |
| EditRange: fourslash.Ignored, | |
| }, |
There was a problem hiding this comment.
Hard failure? What?
I do wonder if we need to specify any of these ItemDefaults though.
Basically we had a missing symbol because we were navigating the "original" syntax tree, and we were not grabbing the reparsed node. Unfortunately, that's not sufficient because not every JSDoc type node will have a corresponding reparsed node - in some cases, JSDoc nodes will never be re-attached to the resulting tree.
The code is resilient to these edge-cases and checks for an actual symbol, but tries to use the name of a syntax node as a fallback.
Fixes #3010.