From 1ebbe73a1dbc3fdcbd000228aec92c6d190de700 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Thu, 18 Sep 2025 08:28:01 -0400 Subject: [PATCH] [ty] Swap `detail` and `description` fields for `CompletionItemLabelDetails` This seems to be more consistent with how other LSPs work (like `rust-analyzer`), and also I think is more consistent with how `CompletionItem.detail` is itself rendered. Namely, in VS Code, it is right-aligned. And it's also where we put the type signature. But `CompletionItemLabelDetails.detail` is left-aligned where as `CompletionItemLabelDetails.description` is right-aligned. So let's swap them such that type signatures go in the latter and not the former. This also adds a space before the module name and contextualizes it with `(import )` to help aide the end user in figuring out selecting the completion will do. Fixes #1200 --- crates/ty_server/src/server/api/requests/completion.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ty_server/src/server/api/requests/completion.rs b/crates/ty_server/src/server/api/requests/completion.rs index 1bc2211a4f..55b8b91074 100644 --- a/crates/ty_server/src/server/api/requests/completion.rs +++ b/crates/ty_server/src/server/api/requests/completion.rs @@ -87,8 +87,8 @@ impl BackgroundDocumentRequestHandler for CompletionRequestHandler { sort_text: Some(format!("{i:-max_index_len$}")), detail: type_display.clone(), label_details: Some(CompletionItemLabelDetails { - detail: type_display, - description: comp.module_name.map(ToString::to_string), + detail: comp.module_name.map(|name| format!(" (import {name})")), + description: type_display, }), insert_text: comp.insert.map(String::from), additional_text_edits: import_edit.map(|edit| vec![edit]),