From cc23af944f4a0b3e8930d4d9a7b7847c9baaf625 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Fri, 12 Dec 2025 10:30:42 -0500 Subject: [PATCH] [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 --- crates/ty_server/src/server/api/requests/completion.rs | 6 ++++-- crates/ty_server/tests/e2e/completions.rs | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/ty_server/src/server/api/requests/completion.rs b/crates/ty_server/src/server/api/requests/completion.rs index 540546cf49..8ba6d14281 100644 --- a/crates/ty_server/src/server/api/requests/completion.rs +++ b/crates/ty_server/src/server/api/requests/completion.rs @@ -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() diff --git a/crates/ty_server/tests/e2e/completions.rs b/crates/ty_server/tests/e2e/completions.rs index 24efe82ea9..23e074a715 100644 --- a/crates/ty_server/tests/e2e/completions.rs +++ b/crates/ty_server/tests/e2e/completions.rs @@ -110,13 +110,13 @@ TypedDi 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"