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

@ -11,6 +11,8 @@ use text::*;
pub use proto::{BufferState, File, Operation};
use super::{point_from_lsp, point_to_lsp};
/// Deserializes a `[text::LineEnding]` from the RPC representation.
pub fn deserialize_line_ending(message: proto::LineEnding) -> text::LineEnding {
match message {
@ -582,3 +584,33 @@ pub fn serialize_version(version: &clock::Global) -> Vec<proto::VectorClockEntry
})
.collect()
}
pub fn serialize_lsp_edit(edit: lsp::TextEdit) -> proto::TextEdit {
let start = point_from_lsp(edit.range.start).0;
let end = point_from_lsp(edit.range.end).0;
proto::TextEdit {
new_text: edit.new_text,
lsp_range_start: Some(proto::PointUtf16 {
row: start.row,
column: start.column,
}),
lsp_range_end: Some(proto::PointUtf16 {
row: end.row,
column: end.column,
}),
}
}
pub fn deserialize_lsp_edit(edit: proto::TextEdit) -> Option<lsp::TextEdit> {
let start = edit.lsp_range_start?;
let start = PointUtf16::new(start.row, start.column);
let end = edit.lsp_range_end?;
let end = PointUtf16::new(end.row, end.column);
Some(lsp::TextEdit {
range: lsp::Range {
start: point_to_lsp(start),
end: point_to_lsp(end),
},
new_text: edit.new_text,
})
}