From 5d217b7f461e3fa02900deb7b4c7f4dace43c0b6 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Fri, 22 Aug 2025 18:32:53 +0200 Subject: [PATCH] [ty] Add type as detail to completion items (#20047) ## Summary @BurntSushi was so kind as to find me an easy task to do some coding before I'm off to PTO. This PR adds the type to completion items (see the gray little text at the end of a completion item). https://github.com/user-attachments/assets/c0a86061-fa12-47b4-b43c-3c646771a69d --- crates/ty_server/src/server/api/requests/completion.rs | 1 + crates/ty_wasm/src/lib.rs | 3 +++ playground/ty/src/Editor/Editor.tsx | 1 + 3 files changed, 5 insertions(+) diff --git a/crates/ty_server/src/server/api/requests/completion.rs b/crates/ty_server/src/server/api/requests/completion.rs index 214c04582f..e175ed49fe 100644 --- a/crates/ty_server/src/server/api/requests/completion.rs +++ b/crates/ty_server/src/server/api/requests/completion.rs @@ -71,6 +71,7 @@ impl BackgroundDocumentRequestHandler for CompletionRequestHandler { label: comp.inner.name.into(), kind, sort_text: Some(format!("{i:-max_index_len$}")), + detail: comp.inner.ty.display(db).to_string().into(), documentation: comp .documentation .map(|docstring| Documentation::String(docstring.render_plaintext())), diff --git a/crates/ty_wasm/src/lib.rs b/crates/ty_wasm/src/lib.rs index f835ea9112..413699866a 100644 --- a/crates/ty_wasm/src/lib.rs +++ b/crates/ty_wasm/src/lib.rs @@ -425,6 +425,7 @@ impl Workspace { documentation: completion .documentation .map(|documentation| documentation.render_plaintext()), + detail: completion.inner.ty.display(&self.db).to_string().into(), }) .collect()) } @@ -914,6 +915,8 @@ pub struct Completion { pub kind: Option, #[wasm_bindgen(getter_with_clone)] pub documentation: Option, + #[wasm_bindgen(getter_with_clone)] + pub detail: Option, } #[wasm_bindgen] diff --git a/playground/ty/src/Editor/Editor.tsx b/playground/ty/src/Editor/Editor.tsx index 5abcba0705..75bcf9d119 100644 --- a/playground/ty/src/Editor/Editor.tsx +++ b/playground/ty/src/Editor/Editor.tsx @@ -321,6 +321,7 @@ class PlaygroundServer : mapCompletionKind(completion.kind), insertText: completion.name, documentation: completion.documentation, + detail: completion.detail, // TODO(micha): It's unclear why this field is required for monaco but not VS Code. // and omitting it works just fine? The LSP doesn't expose this information right now // which is why we go with undefined for now.