From cbb535f5ebc1309816bbe3b41425a95472294963 Mon Sep 17 00:00:00 2001 From: Boris Vassilev Date: Tue, 4 Mar 2025 14:30:03 +0200 Subject: [PATCH] Fix completion details on new clangd versions (#25405) Fixes #16057 In newer versions of clangd, the switch labelDetailsSupport in the json passed to the language server modifies the format of the returned json. Zed handles well the old format, but misses the function parameters in the new one. For example: The old format looks like this: ```json ... "label": " Window(int width, int height, const char *name, bool vsync, bool resizable)", ... ``` and with labelDetailsSupport = true: ```json ... "label": " Window", "labelDetails": { "detail": "(int width, int height, const char *name, bool vsync, bool resizable)" }, ... ``` A simple solution is to just to not tell the language server that label details are supported and force it to use the old format. This is a dirty fix, but makes the completions behave like in the old versions of clangd. I do not know if this will break another language server. From what I've found out most lsp-s do not depend on that setting and provide all completion data either way. If not, this switch will need to be exposed in a config or be at least lsp-dependant. Lastly, I do not know Rust, maybe will need help to make a better fix for the issue. Release Notes: - Fixed broken C++ completion suggestions --- crates/languages/src/c.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/languages/src/c.rs b/crates/languages/src/c.rs index 1a07feb2f7..f9bd5bb209 100644 --- a/crates/languages/src/c.rs +++ b/crates/languages/src/c.rs @@ -120,11 +120,21 @@ impl super::LspAdapter for CLspAdapter { completion: &lsp::CompletionItem, language: &Arc, ) -> Option { + let label_detail = match &completion.label_details { + Some(label_detail) => match &label_detail.detail { + Some(detail) => detail.trim(), + None => "", + }, + None => "", + }; + let label = completion .label .strip_prefix('•') .unwrap_or(&completion.label) - .trim(); + .trim() + .to_owned() + + label_detail; match completion.kind { Some(lsp::CompletionItemKind::FIELD) if completion.detail.is_some() => {