debugger: Improve debug console autocompletions (#33868)

Partially fixes:
https://github.com/zed-industries/zed/discussions/33777#discussioncomment-13646294

### Improves debug console autocompletion behavior

This PR fixes a regression in completion trigger support for the debug
console, as we only looked if a completion trigger, was in the beginning
of the search text, but we also had to check if the current text is a
word so we also show completions for variables/input that doesn't start
with any of the completion triggers.

We now also leverage DAP provided information to sort completion items
more effectively. This results in improved prioritization, showing
variable completions above classes and global scope types.

I also added for completion the documentation field, that directly comes
from the DAP server. NOTE: I haven't found an adapter that returns this,
but it needs to have.

**Before**
<img width="1200" alt="Screenshot 2025-07-03 at 21 00 19"
src="https://github.com/user-attachments/assets/611e8d38-e302-4995-a425-ce2c0a1843d4"
/>

**After**
<img width="1200" alt="Screenshot 2025-07-03 at 20 59 38"
src="https://github.com/user-attachments/assets/ab1312db-bbad-49b7-872d-712d6ec708d7"
/>

Release Notes:

- Debugger: Improve autocompletion sorting for debug console
- Debugger: Fix autocompletion menu now shown when you type
- Debugger: Fix completion item showing up twice for some adapters
This commit is contained in:
Remco Smits 2025-07-05 16:20:41 +02:00 committed by GitHub
parent 76fe33245f
commit 66e45818af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 95 additions and 29 deletions

View file

@ -6043,7 +6043,9 @@ impl LspStore {
);
server.request::<lsp::request::ResolveCompletionItem>(*lsp_completion.clone())
}
CompletionSource::BufferWord { .. } | CompletionSource::Custom => {
CompletionSource::BufferWord { .. }
| CompletionSource::Dap { .. }
| CompletionSource::Custom => {
return Ok(());
}
}
@ -6195,7 +6197,9 @@ impl LspStore {
}
serde_json::to_string(lsp_completion).unwrap().into_bytes()
}
CompletionSource::Custom | CompletionSource::BufferWord { .. } => {
CompletionSource::Custom
| CompletionSource::Dap { .. }
| CompletionSource::BufferWord { .. } => {
return Ok(());
}
}
@ -11081,6 +11085,10 @@ impl LspStore {
serialized_completion.source = proto::completion::Source::Custom as i32;
serialized_completion.resolved = true;
}
CompletionSource::Dap { sort_text } => {
serialized_completion.source = proto::completion::Source::Dap as i32;
serialized_completion.sort_text = Some(sort_text.clone());
}
}
serialized_completion
@ -11135,6 +11143,11 @@ impl LspStore {
resolved: completion.resolved,
}
}
Some(proto::completion::Source::Dap) => CompletionSource::Dap {
sort_text: completion
.sort_text
.context("expected sort text to exist")?,
},
_ => anyhow::bail!("Unexpected completion source {}", completion.source),
},
})