-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Colorize cargo check
diagnostics in VSCode via text decorations
#13848
feat: Colorize cargo check
diagnostics in VSCode via text decorations
#13848
Conversation
☔ The latest upstream changes (presumably #13841) made this pull request unmergeable. Please resolve the merge conflicts. |
e69c7f1
to
687a3bb
Compare
I can test this on windows later |
crates/flycheck/src/lib.rs
Outdated
.arg(self.root.join("Cargo.toml").as_os_str()); | ||
cmd.args([ | ||
"--workspace", | ||
"--message-format=json-diagnostic-rendered-ansi", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be gated behind a config disabled by default, otherwise this may break clients that don't handle color codes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point, I had forgotten about how this would impact other clients. I guess it should be called something like checkOnSave_enableColorOutput
?
Edit: also, does it make sense to make it something like an Option<bool>
and default to true
for VScode using something like https://github.com/rust-lang/rust-analyzer/pull/13699/files#diff-779cb31c0defa0631d570725eb4ca124c0860d6ec07bb5b9deddc2dd34966315R719 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, actually, thinking about again, a config might make sense for the client, but not the server. We might want to make this an experimental client capability instead (and expose an extra config for the vscode client only)
The server side stuff for these capabilities can be found here https://github.com/Veykril/rust-analyzer/blob/17cc78f169538538a10e11251562e0fde8ed4958/crates/rust-analyzer/src/config.rs#L990-L1006, the client side is here https://github.com/Veykril/rust-analyzer/blob/17cc78f169538538a10e11251562e0fde8ed4958/editors/code/src/client.ts#L295-L321
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just pushed a change as suggested. Should this also be exposed as a config in package.json
? Do I need to update #4604 and/or lsp-extensions.md
to document this as a VSCode-specific extension?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to add that to the markdown file as a small entry yes, most likely VSCode is the only client benefiting from this, but its always good to keep that list in sync. If you change that file you'll also have to update the hash (a test will fail otherwise, the test will tell the expected hash)
☔ The latest upstream changes (presumably #13853) made this pull request unmergeable. Please resolve the merge conflicts. |
687a3bb
to
e5a1dac
Compare
lgtm if you could touch up the |
✌️ @ian-h-chamberlain can now approve this pull request |
☔ The latest upstream changes (presumably #13890) made this pull request unmergeable. Please resolve the merge conflicts. |
Use ANSI control characters to display text decorations matching the VScode terminal theme, and strip them out when providing text content for rustc diagnostics. This adds the small `anser` library to parse the control codes, and it also supports HTML output so it should be fairly easy to switch to a rendered HTML/webview implementation if desired.
c03d23e
to
283dfc4
Compare
@bors r+ |
☀️ Test successful - checks-actions |
I've just read about this feature in the Announcements. On the one hand, I think this is great. But I also wonder if it would be a bit better to let the clients decide how they want to color errors, warnings, etc. For example, would it be possible to send a html-like with symbolic formatting instead? I think coupling this feature with the VScode terminal theme is not very portable. Independently from the above, will the ansi-encoded text contain just color information or for example hyperlinks as well? Thanks |
cargo check
diagnostics in VSCode via text decorationscargo check
diagnostics in VSCode via text decorations
The coloring is just passed through from |
Hyperlinks might be a nice addition |
Just upgraded to the latest nightly and it works great, thanks! ❤️ |
Thanks. This wasn't clear for me from the original message. |
Fixes #13648
Use ANSI control characters to display text decorations matching the VScode terminal theme, and strip them out when providing text content for rustc diagnostics.
This adds the small
anser
library (MIT license, no dependencies) to parse the control codes, and it also supports HTML output so it should be fairly easy to switch to a rendered HTML/webview implementation in the futureI also updated the default
cargo check
command to use the rendered ANSI diagnostics, although I'm not sure if it makes sense to put this kind of thing behind a feature flag, or whether it might have any issues on Windows (as I believe ANSI codes are not used for colorization there)?