Skip to content

[ty] Render import <...> in completions when "label details" isn't supported#21109

Merged
BurntSushi merged 1 commit intomainfrom
ag/fix-label-details
Oct 29, 2025
Merged

[ty] Render import <...> in completions when "label details" isn't supported#21109
BurntSushi merged 1 commit intomainfrom
ag/fix-label-details

Conversation

@BurntSushi
Copy link
Member

This fixes a bug where the import module part of a completion for
unimported candidates would be missing. This makes it especially
confusing because the user can't tell where the symbol is coming from,
and there is no hint that an import statement will be inserted.

Previously, we were using CompletionItemLabelDetails to render the
import module part of the suggestion. But this is only supported in
clients that support version 3.17 (or newer) of the LSP specification.
It turns out that this support isn't widespread yet. In particular,
Heliex doesn't seem to support "label details."

To fix this, we take a cue from rust-analyzer.
We detect if the client supports "label details," and if so, use it.
Otherwise, we push the import module text into the completion label
itself.

Fixes #20439 (comment)

…supported

This fixes a bug where the `import module` part of a completion for
unimported candidates would be missing. This makes it especially
confusing because the user can't tell where the symbol is coming from,
and there is no hint that an `import` statement will be inserted.

Previously, we were using [`CompletionItemLabelDetails`] to render the
`import module` part of the suggestion. But this is only supported in
clients that support version 3.17 (or newer) of the LSP specification.
It turns out that this support isn't widespread yet. In particular,
Heliex doesn't seem to support "label details."

To fix this, we take a [cue from rust-analyzer][rust-analyzer-details].
We detect if the client supports "label details," and if so, use it.
Otherwise, we push the `import module` text into the completion label
itself.

Fixes #20439 (comment)

[`CompletionItemLabelDetails`]: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#completionItemLabelDetails
[rust-analyzer-details]: https://github.com/rust-lang/rust-analyzer/blob/5d905576d49233ed843bb40df4ed57e5534558f5/crates/rust-analyzer/src/lsp/to_proto.rs#L391-L404
@BurntSushi
Copy link
Member Author

Demo:

2025-10-28T11.29.54-04.00.mp4

In this demo, I show the VS Code rendering, which is unchanged. Then I show Helix. Previously, it didn't include the modules for unimported symbols. But now it does!

@github-actions
Copy link
Contributor

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

@github-actions
Copy link
Contributor

mypy_primer results

No ecosystem changes detected ✅
No memory usage changes detected ✅

@MichaReiser MichaReiser added server Related to the LSP server ty Multi-file analysis & type inference labels Oct 28, 2025
@BurntSushi BurntSushi merged commit 196a68e into main Oct 29, 2025
43 checks passed
@BurntSushi BurntSushi deleted the ag/fix-label-details branch October 29, 2025 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

server Related to the LSP server ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments