Skip to content

fix: mark optional members with a trailing ? in completion labels (#3043)#3044

Merged
dummdidumm merged 4 commits into
sveltejs:masterfrom
MohammadYusif:fix/issue-3043
Jun 3, 2026
Merged

fix: mark optional members with a trailing ? in completion labels (#3043)#3044
dummdidumm merged 4 commits into
sveltejs:masterfrom
MohammadYusif:fix/issue-3043

Conversation

@MohammadYusif

Copy link
Copy Markdown
Contributor

Summary

  • Optional object/class members were missing the trailing ? in their completion labels (e.g. baz?: number completed as baz), unlike the TypeScript language service / vtsls.
  • TypeScript reports optionality via the optional kind modifier on the completion entry, which getCompletionLabelAndInsert ignored.

Changes

  • packages/language-server/src/plugins/typescript/features/CompletionProvider.ts: detect ts.ScriptElementKindModifier.optionalModifier and append ? to the label, keeping insertText as 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 the baz? label and bare insert text.
  • .changeset/optional-completion-label.md: patch changeset for svelte-language-server.

Test plan

pnpm --filter svelte-language-server test — 69/69 pass; new test fails without the source change.

Fixes #3043

…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-bot

changeset-bot Bot commented Jun 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b79282a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte-language-server Patch

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 dummdidumm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thank you

@dummdidumm dummdidumm merged commit f2bcbda into sveltejs:master Jun 3, 2026
3 checks passed
@github-actions github-actions Bot mentioned this pull request Jun 3, 2026
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>
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.

Optionally is missing from completions

2 participants