Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
rust: Prevent declarative macro completion flicker (#63185)
Austin Shijoe7c03209fc16
diff --git a/crates/languages/src/rust.rs b/crates/languages/src/rust.rsindex d0f468a6b27..2cfa0590762 100644--- a/crates/languages/src/rust.rs+++ b/crates/languages/src/rust.rs@@ -443,11 +443,7 @@ impl LspAdapter for RustLspAdapter {let run_start = prefix.len() + 1;let runs = language.highlight_text(&source, run_start..run_start + text.len());mk_label(text, &|| 0..label.len(), runs)- } else if completion- .detail- .as_ref()- .is_some_and(|detail| detail.starts_with("macro_rules! "))- {+ } else if detail_right.is_some_and(|detail| detail.starts_with("macro_rules! ")) {let text = completion.label.clone();let len = text.len();let source = Rope::from(text.as_str());@@ -1575,6 +1571,58 @@ mod tests {let highlight_keyword = grammar.highlight_id_for_name("keyword").unwrap();let highlight_field = grammar.highlight_id_for_name("property").unwrap();+ let macro_detail_label = adapter+ .label_for_completion(+ &lsp::CompletionItem {+ kind: Some(lsp::CompletionItemKind::FUNCTION),+ label: "println!".to_string(),+ detail: Some("macro_rules! println".to_string()),+ ..Default::default()+ },+ &language,+ )+ .await;++ let macro_description_label = adapter+ .label_for_completion(+ &lsp::CompletionItem {+ kind: Some(lsp::CompletionItemKind::FUNCTION),+ label: "println!".to_string(),+ label_details: Some(CompletionItemLabelDetails {+ detail: None,+ description: Some("macro_rules! println".to_string()),+ }),+ ..Default::default()+ },+ &language,+ )+ .await;++ assert_eq!(macro_detail_label, macro_description_label);++ let macro_label = macro_detail_label.unwrap();+ assert_eq!(macro_label.text, "println!");+ assert_eq!(macro_label.filter_range, 0..8);++ let macro_import_label = adapter+ .label_for_completion(+ &lsp::CompletionItem {+ kind: Some(lsp::CompletionItemKind::FUNCTION),+ label: "println!".to_string(),+ label_details: Some(CompletionItemLabelDetails {+ detail: Some("(use std::println)".to_string()),+ description: Some("macro_rules! println".to_string()),+ }),+ ..Default::default()+ },+ &language,+ )+ .await+ .unwrap();++ assert_eq!(macro_import_label.text, "println! (use std::println)");+ assert_eq!(macro_import_label.filter_range, 0..8);+assert_eq!(adapter.label_for_completion(