fix: mark optional members with a trailing ? in completion labels (#3043)#3044
Merged
Conversation
…eltejs#3043) Optional object/class members were shown in completions without the `?` that the TypeScript language service (and vtsls) appends to their labels, so `baz?: number` completed as `baz` instead of `baz?`. TypeScript reports optional members via the `optional` kind modifier on the completion entry. `getCompletionLabelAndInsert` ignored this modifier and always used the bare name as the label. Detect the modifier and append `?` to the label while keeping the inserted text as the bare name, so the `?` is display-only and completion resolution (which keys off `data.name`) is unaffected.
🦋 Changeset detectedLatest commit: b79282a The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
dummdidumm
reviewed
Jun 3, 2026
Merged
ghostdevv
pushed a commit
to ghostdevv/language-tools
that referenced
this pull request
Jun 6, 2026
…eltejs#3043) (sveltejs#3044) Optional object/class members were shown in completions without the `?` that the TypeScript language service (and vtsls) appends to their labels, so `baz?: number` completed as `baz` instead of `baz?`. TypeScript reports optional members via the `optional` kind modifier on the completion entry. `getCompletionLabelAndInsert` ignored this modifier and always used the bare name as the label. Detect the modifier and append `?` to the label while keeping the inserted text as the bare name, so the `?` is display-only and completion resolution (which keys off `data.name`) is unaffected. --------- Co-authored-by: MohammadYusif <MohammadYusif@users.noreply.github.com> Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
?in their completion labels (e.g.baz?: numbercompleted asbaz), unlike the TypeScript language service / vtsls.optionalkind modifier on the completion entry, whichgetCompletionLabelAndInsertignored.Changes
packages/language-server/src/plugins/typescript/features/CompletionProvider.ts: detectts.ScriptElementKindModifier.optionalModifierand append?to the label, keepinginsertTextas the bare name so the?is display-only.packages/language-server/test/plugins/typescript/testfiles/completions/object-member.svelte: add an optional-property scenario.packages/language-server/test/plugins/typescript/features/CompletionProvider.test.ts: regression test asserting thebaz?label and bare insert text..changeset/optional-completion-label.md: patch changeset forsvelte-language-server.Test plan
pnpm --filter svelte-language-server test— 69/69 pass; new test fails without the source change.Fixes #3043