Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat: Colorize cargo check diagnostics in VSCode via text decorations - #13848

#13848
Merged
bors merged 6 commits into
rust-lang:masterrust-lang/rust-analyzer:masterfrom
ian-h-chamberlain:feature/color-compiler-diagnosticsian-h-chamberlain/rust-analyzer:feature/color-compiler-diagnosticsCopy head branch name to clipboard
Jan 9, 2023
Merged

feat: Colorize cargo check diagnostics in VSCode via text decorations#13848
bors merged 6 commits into
rust-lang:masterrust-lang/rust-analyzer:masterfrom
ian-h-chamberlain:feature/color-compiler-diagnosticsian-h-chamberlain/rust-analyzer:feature/color-compiler-diagnosticsCopy head branch name to clipboard

Conversation

@ian-h-chamberlain

@ian-h-chamberlain ian-h-chamberlain commented Dec 25, 2022

Copy link
Copy Markdown
Contributor

Fixes #13648

colored-rustc-diagnostics

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 future

I 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)?

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 25, 2022
@bors

bors commented Dec 27, 2022

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #13841) made this pull request unmergeable. Please resolve the merge conflicts.

@ian-h-chamberlain
ian-h-chamberlain force-pushed the feature/color-compiler-diagnostics branch from e69c7f1 to 687a3bb Compare December 28, 2022 14:42
@Veykril

Veykril commented Dec 30, 2022

Copy link
Copy Markdown
Member

I can test this on windows later

Comment thread crates/flycheck/src/lib.rs Outdated
.arg(self.root.join("Cargo.toml").as_os_str());
cmd.args([
"--workspace",
"--message-format=json-diagnostic-rendered-ansi",

Copy link
Copy Markdown
Member

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.

@ian-h-chamberlain ian-h-chamberlain Jan 3, 2023

Copy link
Copy Markdown
Contributor Author

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 ?

@Veykril Veykril Jan 3, 2023

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Contributor Author

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?

@Veykril Veykril Jan 9, 2023

Copy link
Copy Markdown
Member

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)

Comment thread editors/code/src/client.ts
@bors

bors commented Jan 3, 2023

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #13853) made this pull request unmergeable. Please resolve the merge conflicts.

@ian-h-chamberlain
ian-h-chamberlain force-pushed the feature/color-compiler-diagnostics branch from 687a3bb to e5a1dac Compare January 4, 2023 17:05
@Veykril

Veykril commented Jan 9, 2023

Copy link
Copy Markdown
Member

lgtm if you could touch up the lsp-extension.md!
@bors delegate+

@bors

bors commented Jan 9, 2023

Copy link
Copy Markdown
Contributor

✌️ @ian-h-chamberlain can now approve this pull request

@Veykril Veykril added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 9, 2023
@bors

bors commented Jan 9, 2023

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #13890) made this pull request unmergeable. Please resolve the merge conflicts.

ian-h-chamberlain and others added 6 commits January 9, 2023 11:46
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.
@ian-h-chamberlain

Copy link
Copy Markdown
Contributor Author

@bors r+

@bors

bors commented Jan 9, 2023

Copy link
Copy Markdown
Contributor

📌 Commit 283dfc4 has been approved by ian-h-chamberlain

It is now in the queue for this repository.

@bors

bors commented Jan 9, 2023

Copy link
Copy Markdown
Contributor

⌛ Testing commit 283dfc4 with merge 368e0bb...

@bors

bors commented Jan 9, 2023

Copy link
Copy Markdown
Contributor

☀️ Test successful - checks-actions
Approved by: ian-h-chamberlain
Pushing 368e0bb to master...

@bors
bors merged commit 368e0bb into rust-lang:master Jan 9, 2023
@nemethf

nemethf commented Jan 9, 2023

Copy link
Copy Markdown
Contributor

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

@lnicola lnicola changed the title Colorize cargo check diagnostics in VSCode via text decorations feat: Colorize cargo check diagnostics in VSCode via text decorations Jan 9, 2023
@Veykril

Veykril commented Jan 9, 2023

Copy link
Copy Markdown
Member

The coloring is just passed through from cargo, the server doesn't generate the coloring itself. The clients are free to re-map the color codes as other colors as they like, but that's not something that rust-analyzer would be interested in doing.

@Veykril

Veykril commented Jan 9, 2023

Copy link
Copy Markdown
Member

Hyperlinks might be a nice addition

@ian-h-chamberlain
ian-h-chamberlain deleted the feature/color-compiler-diagnostics branch January 9, 2023 20:22
@jplatte

jplatte commented Jan 10, 2023

Copy link
Copy Markdown
Contributor

Just upgraded to the latest nightly and it works great, thanks! ❤️

@nemethf

nemethf commented Jan 10, 2023

Copy link
Copy Markdown
Contributor

The coloring is just passed through from cargo, the server doesn't generate the coloring itself.

Thanks. This wasn't clear for me from the original message.

AlexWaygood added a commit to astral-sh/ty-vscode that referenced this pull request Jun 26, 2026
## Context

This builds on the original **Click for full diagnostic** feature
implemented in
[astral-sh/ruff#26269](astral-sh/ruff#26269) and
[#462](#462).
The colored rendering follows the approach established by
[rust-lang/rust-analyzer#13848](rust-lang/rust-analyzer#13848).

## Summary

- advertise support for colored full diagnostic output
- strip ANSI sequences from the virtual document and recreate their
styles with VS Code decorations
- support named terminal colors, 256-color palette entries, truecolor,
and text decorations

## Companion PRs

- [astral-sh/ruff#26384](astral-sh/ruff#26384)
- [astral-sh/ty#3858](astral-sh/ty#3858)

## Test plan



https://github.com/user-attachments/assets/36638263-fe48-4ba7-8abe-95db353f1257
AlexWaygood added a commit to astral-sh/ty that referenced this pull request Jun 26, 2026
## Context

This builds on the original **Click for full diagnostic** feature
implemented in
[astral-sh/ruff#26269](astral-sh/ruff#26269) and
[astral-sh/ty-vscode#462](astral-sh/ty-vscode#462).
The colored rendering follows the approach established by
[rust-lang/rust-analyzer#13848](rust-lang/rust-analyzer#13848).

## Summary

Explain that `fullDiagnosticOutput` can include ANSI colour codes and
clients are expected to be able to handle this

## Companion PRs

- [astral-sh/ruff#26384](astral-sh/ruff#26384)
-
[astral-sh/ty-vscode#463](astral-sh/ty-vscode#463)
AlexWaygood added a commit to astral-sh/ruff that referenced this pull request Jun 26, 2026
## Context

This builds on the original **Click for full diagnostic** feature
implemented in
[#26269](#26269) and
[astral-sh/ty-vscode#462](astral-sh/ty-vscode#462).
The colored rendering follows the approach established by
[rust-lang/rust-analyzer#13848](rust-lang/rust-analyzer#13848).

## Summary

- render full ty diagnostics with ANSI color and styling when the client
opts in
- negotiate color support separately from `fullDiagnosticOutput` for
rollout compatibility
- disable terminal hyperlinks in LSP output and cover the behavior under
forced hyperlink support

## Companion PRs

-
[astral-sh/ty-vscode#463](astral-sh/ty-vscode#463)
- [astral-sh/ty#3858](astral-sh/ty#3858)

## Test plan



https://github.com/user-attachments/assets/dc7e7538-ae2b-4870-9e9b-f59943ee804a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New "full compiler diagnostic" view could use some color

6 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.