[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
This commit is contained in:
Micha Reiser 2025-08-22 18:32:53 +02:00 committed by GitHub
parent 0b6ce1c788
commit 5d217b7f46
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 5 additions and 0 deletions

View file

@ -71,6 +71,7 @@ impl BackgroundDocumentRequestHandler for CompletionRequestHandler {
label: comp.inner.name.into(), label: comp.inner.name.into(),
kind, kind,
sort_text: Some(format!("{i:-max_index_len$}")), sort_text: Some(format!("{i:-max_index_len$}")),
detail: comp.inner.ty.display(db).to_string().into(),
documentation: comp documentation: comp
.documentation .documentation
.map(|docstring| Documentation::String(docstring.render_plaintext())), .map(|docstring| Documentation::String(docstring.render_plaintext())),

View file

@ -425,6 +425,7 @@ impl Workspace {
documentation: completion documentation: completion
.documentation .documentation
.map(|documentation| documentation.render_plaintext()), .map(|documentation| documentation.render_plaintext()),
detail: completion.inner.ty.display(&self.db).to_string().into(),
}) })
.collect()) .collect())
} }
@ -914,6 +915,8 @@ pub struct Completion {
pub kind: Option<CompletionKind>, pub kind: Option<CompletionKind>,
#[wasm_bindgen(getter_with_clone)] #[wasm_bindgen(getter_with_clone)]
pub documentation: Option<String>, pub documentation: Option<String>,
#[wasm_bindgen(getter_with_clone)]
pub detail: Option<String>,
} }
#[wasm_bindgen] #[wasm_bindgen]

View file

@ -321,6 +321,7 @@ class PlaygroundServer
: mapCompletionKind(completion.kind), : mapCompletionKind(completion.kind),
insertText: completion.name, insertText: completion.name,
documentation: completion.documentation, documentation: completion.documentation,
detail: completion.detail,
// TODO(micha): It's unclear why this field is required for monaco but not VS Code. // 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 // and omitting it works just fine? The LSP doesn't expose this information right now
// which is why we go with undefined for now. // which is why we go with undefined for now.