From 7ad862673d748f669c2170b36df937a6c42bbf85 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 1 Apr 2022 15:05:03 -0700 Subject: [PATCH] Add basic syntax highlight colors for typescript completions --- crates/zed/src/languages/typescript.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/crates/zed/src/languages/typescript.rs b/crates/zed/src/languages/typescript.rs index d08da116a5..aca8cdef52 100644 --- a/crates/zed/src/languages/typescript.rs +++ b/crates/zed/src/languages/typescript.rs @@ -115,6 +115,29 @@ impl LspAdapter for TypeScriptLspAdapter { fn process_diagnostics(&self, _: &mut lsp::PublishDiagnosticsParams) {} + fn label_for_completion( + &self, + item: &lsp::CompletionItem, + language: &language::Language, + ) -> Option { + use lsp::CompletionItemKind as Kind; + let len = item.label.len(); + let grammar = language.grammar()?; + let highlight_id = match item.kind? { + Kind::CLASS | Kind::INTERFACE => grammar.highlight_id_for_name("type"), + Kind::CONSTRUCTOR => grammar.highlight_id_for_name("type"), + Kind::CONSTANT => grammar.highlight_id_for_name("constant"), + Kind::FUNCTION | Kind::METHOD => grammar.highlight_id_for_name("function"), + Kind::PROPERTY | Kind::FIELD => grammar.highlight_id_for_name("property"), + _ => None, + }?; + Some(language::CodeLabel { + text: item.label.clone(), + runs: vec![(0..len, highlight_id)], + filter_range: 0..len, + }) + } + fn initialization_options(&self) -> Option { Some(json!({ "provideFormatter": true