[ty] Tweak how we show qualified auto-import completions

Specifically, we make two changes:

1. We only show `import ...` when there is an actual import edit.
2. We now show the text we will insert. This means that when we
insert a qualified symbol, the qualification will show in the
completions suggested.

Ref https://github.com/astral-sh/ty/issues/1274#issuecomment-3352233790
This commit is contained in:
Andrew Gallant 2025-12-12 10:30:42 -05:00
parent 1b5389da57
commit cc4d1190ae
No known key found for this signature in database
GPG Key ID: 5518C8B38E0693E0
2 changed files with 6 additions and 4 deletions

View File

@ -81,8 +81,10 @@ impl BackgroundDocumentRequestHandler for CompletionRequestHandler {
})
});
let name = comp.name.to_string();
let import_suffix = comp.module_name.map(|name| format!(" (import {name})"));
let name = comp.insert.as_deref().unwrap_or(&comp.name).to_string();
let import_suffix = comp
.module_name
.and_then(|name| import_edit.is_some().then(|| format!(" (import {name})")));
let (label, label_details) = if snapshot
.resolved_client_capabilities()
.supports_completion_item_label_details()

View File

@ -110,13 +110,13 @@ TypedDi<CURSOR>
insta::assert_json_snapshot!(completions, @r#"
[
{
"label": "TypedDict (import typing)",
"label": "typing.TypedDict",
"kind": 6,
"sortText": "0",
"insertText": "typing.TypedDict"
},
{
"label": "is_typeddict (import typing)",
"label": "typing.is_typeddict",
"kind": 3,
"sortText": "1",
"insertText": "typing.is_typeddict"