Skip to content

Fix completions for contextually constrained types in JSDoc#3011

Open
DanielRosenwasser wants to merge 4 commits intomainfrom
completionsConstraintInJsDocObjectType
Open

Fix completions for contextually constrained types in JSDoc#3011
DanielRosenwasser wants to merge 4 commits intomainfrom
completionsConstraintInJsDocObjectType

Conversation

@DanielRosenwasser
Copy link
Member

@DanielRosenwasser DanielRosenwasser commented Mar 6, 2026

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.

Copilot AI review requested due to automatic review settings March 6, 2026 23:52
@DanielRosenwasser DanielRosenwasser changed the title Completions constraint in js doc object type Fix completions for contextually constrained types in JSDoc Mar 6, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 getConstraintOfTypeArgumentProperty to 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{".", ",", ";"}},
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{CommitCharacters: &[]string{".", ",", ";"}},
ItemDefaults: &fourslash.CompletionsExpectedItemDefaults{
CommitCharacters: &[]string{".", ",", ";"},
EditRange: fourslash.Ignored,
},

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard failure? What?

I do wonder if we need to specify any of these ItemDefaults though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nil pointer dereference for contextual constraint completions in JSDoc

2 participants