feat: Implement textDocument/documentColor
#20140
Draft
+95
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi, I'd like to add
textDocument/documentColormethod to rust-analyzer, it will allow libraries with a type likeColor { r: u8, g: u8, b: u8 }to annotate this type with special attributes#[rust_analyzer::color::rgb].IDEs can then annotate expressions known at compile time that of type
Colorwith color swatches, similar to how it works for CSS:
I added the feature to Helix from the client side (helix-editor/helix#12308) and think it'd be fun to also add it from the server side.
My current plan is to have an API like this:
This is what I want for a MVP:
const)structof the expression containsan attribute
#[rust_analyzer::color::rgb], proceedf32fields with attribute#[rust_analyzer::color::rgb::{r,g,b}],then we have all the necessary information to construct the type itself
Currently, the problem that I face is that I cannot obtain the
Typeof an expression.type_of_exprreturnsNone:I'm building rust-analyzer with
cargo run --releasethen in.helix/languages.tomlI tell the editor to use the built binary:This works. I get hover information, auto-complete. I get custom logs in Helix's log (
:log-open).The current implementation draws a single hard-coded red square in the file, so I assume the problem isn't with my setup
Closes #13122