Show inline previews for LSP document colors (#32816)

https://github.com/user-attachments/assets/ad0fa304-e4fb-4598-877d-c02141f35d6f

Closes https://github.com/zed-industries/zed/issues/4678

Also adds the code to support `textDocument/colorPresentation`
counterpart that serves as a resolve mechanism for the document colors.
The resolve itself is not run though, and the editor does not
accommodate color presentations in the editor yet — until a well
described use case is provided.

Use `lsp_document_colors` editor settings to alter the presentation and
turn the feature off.

Release Notes:

- Start showing inline previews for LSP document colors
This commit is contained in:
Kirill Bulatov 2025-06-17 16:46:21 +03:00 committed by GitHub
parent acb0210d26
commit f46957584f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 1796 additions and 268 deletions

View file

@ -768,6 +768,21 @@ pub struct DirectoryItem {
pub is_dir: bool,
}
#[derive(Clone, Debug, PartialEq)]
pub struct DocumentColor {
pub lsp_range: lsp::Range,
pub color: lsp::Color,
pub resolved: bool,
pub color_presentations: Vec<ColorPresentation>,
}
#[derive(Clone, Debug, PartialEq)]
pub struct ColorPresentation {
pub label: String,
pub text_edit: Option<lsp::TextEdit>,
pub additional_text_edits: Vec<lsp::TextEdit>,
}
#[derive(Clone)]
pub enum DirectoryLister {
Project(Entity<Project>),
@ -3721,16 +3736,6 @@ impl Project {
})
}
pub fn document_diagnostics(
&mut self,
buffer_handle: Entity<Buffer>,
cx: &mut Context<Self>,
) -> Task<Result<Vec<LspPullDiagnostics>>> {
self.lsp_store.update(cx, |lsp_store, cx| {
lsp_store.pull_diagnostics(buffer_handle, cx)
})
}
pub fn update_diagnostics(
&mut self,
language_server_id: LanguageServerId,