diff --git a/crates/languages/src/python.rs b/crates/languages/src/python.rs index 3f25a5c5ce50d0aade7b1b575443b5d681f67c63..03ce559b87bb5f318758735c5903bfc51b7c1267 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, + ) -> Option { + 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, delegate: &Arc,