Show color swatches for LSP completions (#18665)
Closes #11991 Release Notes: - Added support for color swatches for language server completions. <img width="502" alt="Screenshot 2024-10-02 at 19 02 22" src="https://github.com/user-attachments/assets/57e85492-3760-461a-9b17-a846dc40576b"> <img width="534" alt="Screenshot 2024-10-02 at 19 02 48" src="https://github.com/user-attachments/assets/713ac41c-16f0-4ad3-9103-d2c9b3fa8b2e"> This implementation is mostly a port of the VSCode version of the ColorExtractor. It seems reasonable the we should support _at least_ what VSCode does for detecting color swatches from LSP completions. This implementation could definitely be better perf-wise by writing a dedicated color parser. I also think it would be neat if, in the future, Zed handled _more_ color formats — especially wide-gamut colors. There are a few differences to the regexes in the VSCode implementation but mainly so simplify the implementation : - The hex vs rgb/hsl regexes were split into two parts - The rgb/hsl regexes allow 3 or 4 color components whether hsla/rgba or not and the parsing implementation accepts/rejects colors as needed --------- Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
This commit is contained in:
parent
cddd7875a4
commit
cac98b7bbf
4 changed files with 320 additions and 3 deletions
|
@ -1228,6 +1228,10 @@ impl CompletionsMenu {
|
|||
None
|
||||
};
|
||||
|
||||
let color_swatch = completion
|
||||
.color()
|
||||
.map(|color| div().size_4().bg(color).rounded(px(2.)));
|
||||
|
||||
div().min_w(px(220.)).max_w(px(540.)).child(
|
||||
ListItem::new(mat.candidate_id)
|
||||
.inset(true)
|
||||
|
@ -1243,6 +1247,7 @@ impl CompletionsMenu {
|
|||
task.detach_and_log_err(cx)
|
||||
}
|
||||
}))
|
||||
.start_slot::<Div>(color_swatch)
|
||||
.child(h_flex().overflow_hidden().child(completion_label))
|
||||
.end_slot::<Label>(documentation_label),
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue