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:
Jordan Pittman 2024-10-03 14:38:17 -04:00 committed by GitHub
parent cddd7875a4
commit cac98b7bbf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 320 additions and 3 deletions

View file

@ -58,6 +58,8 @@ extend-ignore-re = [
# ProtoLS crate with tree-sitter Protobuf grammar.
"protols",
# x11rb SelectionNotifyEvent struct field
"requestor"
"requestor",
# Not an actual typo but an intentionally invalid color, in `color_extractor`
"#fof"
]
check-filename = true