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
This commit is contained in:
Boris Vassilev 2025-03-04 14:30:03 +02:00 committed by GitHub
parent 20fc753f2b
commit cbb535f5eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -120,11 +120,21 @@ impl super::LspAdapter for CLspAdapter {
completion: &lsp::CompletionItem,
language: &Arc<Language>,
) -> Option<CodeLabel> {
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() => {