Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Add better labels for completions for ty lsp (#42233)

Caleb Van Dyke8d632958db19
diff --git a/crates/languages/src/python.rs b/crates/languages/src/python.rs
index 3f25a5c5ce5..03ce559b87b 100644
--- a/crates/languages/src/python.rs
+++ b/crates/languages/src/python.rs
@@ -163,6 +163,45 @@ impl LspAdapter for TyLspAdapter {
Self::SERVER_NAME
}
+ async fn label_for_completion(
+ &self,
+ item: &lsp::CompletionItem,
+ language: &Arc<language::Language>,
+ ) -> Option<language::CodeLabel> {
+ let label = &item.label;
+ let label_len = label.len();
+ let grammar = language.grammar()?;
+ let highlight_id = match item.kind? {
+ lsp::CompletionItemKind::METHOD => grammar.highlight_id_for_name("function.method"),
+ lsp::CompletionItemKind::FUNCTION => grammar.highlight_id_for_name("function"),
+ lsp::CompletionItemKind::CLASS => grammar.highlight_id_for_name("type"),
+ lsp::CompletionItemKind::CONSTANT => grammar.highlight_id_for_name("constant"),
+ lsp::CompletionItemKind::VARIABLE => grammar.highlight_id_for_name("variable"),
+ _ => {
+ return None;
+ }
+ };
+
+ let mut text = label.clone();
+ if let Some(completion_details) = item
+ .label_details
+ .as_ref()
+ .and_then(|details| details.detail.as_ref())
+ {
+ write!(&mut text, " {}", completion_details).ok();
+ }
+
+ Some(language::CodeLabel::filtered(
+ text,
+ label_len,
+ item.filter_text.as_deref(),
+ highlight_id
+ .map(|id| (0..label_len, id))
+ .into_iter()
+ .collect(),
+ ))
+ }
+
async fn workspace_configuration(
self: Arc<Self>,
delegate: &Arc<dyn LspAdapterDelegate>,