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

@ -666,6 +666,51 @@ message LanguageServerPromptResponse {
optional uint64 action_response = 1;
}
message GetDocumentColor {
uint64 project_id = 1;
uint64 buffer_id = 2;
repeated VectorClockEntry version = 3;
}
message GetDocumentColorResponse {
repeated ColorInformation colors = 1;
repeated VectorClockEntry version = 2;
}
message ColorInformation {
PointUtf16 lsp_range_start = 1;
PointUtf16 lsp_range_end = 2;
float red = 3;
float green = 4;
float blue = 5;
float alpha = 6;
}
message GetColorPresentation {
uint64 project_id = 1;
uint64 buffer_id = 2;
ColorInformation color = 3;
uint64 server_id = 4;
}
message GetColorPresentationResponse {
repeated ColorPresentation presentations = 1;
}
message ColorPresentation {
string label = 1;
optional TextEdit text_edit = 2;
repeated TextEdit additional_text_edits = 3;
}
message TextEdit {
string new_text = 1;
PointUtf16 lsp_range_start = 2;
PointUtf16 lsp_range_end = 3;
}
message MultiLspQuery {
uint64 project_id = 1;
uint64 buffer_id = 2;
@ -679,6 +724,7 @@ message MultiLspQuery {
GetSignatureHelp get_signature_help = 7;
GetCodeLens get_code_lens = 8;
GetDocumentDiagnostics get_document_diagnostics = 9;
GetDocumentColor get_document_color = 10;
}
}
@ -705,7 +751,9 @@ message LspResponse {
GetSignatureHelpResponse get_signature_help_response = 3;
GetCodeLensResponse get_code_lens_response = 4;
GetDocumentDiagnosticsResponse get_document_diagnostics_response = 5;
GetDocumentColorResponse get_document_color_response = 6;
}
uint64 server_id = 7;
}
message LanguageServerIdForName {

View file

@ -391,7 +391,12 @@ message Envelope {
GetDocumentDiagnostics get_document_diagnostics = 350;
GetDocumentDiagnosticsResponse get_document_diagnostics_response = 351;
PullWorkspaceDiagnostics pull_workspace_diagnostics = 352; // current max
PullWorkspaceDiagnostics pull_workspace_diagnostics = 352;
GetDocumentColor get_document_color = 353;
GetDocumentColorResponse get_document_color_response = 354;
GetColorPresentation get_color_presentation = 355;
GetColorPresentationResponse get_color_presentation_response = 356; // current max
}

View file

@ -221,6 +221,10 @@ messages!(
(ResolveCompletionDocumentationResponse, Background),
(ResolveInlayHint, Background),
(ResolveInlayHintResponse, Background),
(GetDocumentColor, Background),
(GetDocumentColorResponse, Background),
(GetColorPresentation, Background),
(GetColorPresentationResponse, Background),
(RefreshCodeLens, Background),
(GetCodeLens, Background),
(GetCodeLensResponse, Background),
@ -400,6 +404,8 @@ request_messages!(
ResolveCompletionDocumentationResponse
),
(ResolveInlayHint, ResolveInlayHintResponse),
(GetDocumentColor, GetDocumentColorResponse),
(GetColorPresentation, GetColorPresentationResponse),
(RespondToChannelInvite, Ack),
(RespondToContactRequest, Ack),
(SaveBuffer, BufferSaved),
@ -487,9 +493,11 @@ entity_messages!(
BufferSaved,
CloseBuffer,
Commit,
GetColorPresentation,
CopyProjectEntry,
CreateBufferForPeer,
CreateProjectEntry,
GetDocumentColor,
DeleteProjectEntry,
ExpandProjectEntry,
ExpandAllForProjectEntry,