Skip to content
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

Include rustc diagnostic ASCII art in popup #13574

Closed
estebank opened this issue Nov 7, 2022 · 2 comments · Fixed by #13633
Closed

Include rustc diagnostic ASCII art in popup #13574

estebank opened this issue Nov 7, 2022 · 2 comments · Fixed by #13633
Assignees
Labels
A-diagnostics diagnostics / error reporting

Comments

@estebank
Copy link
Contributor

estebank commented Nov 7, 2022

Currently rust-analyzer leverages the structured json output from rustc when presenting diagnostics from rustc. This is great because it translates the provided spans into links that people can click to get to the right place, but removes sometimes critical context (from both newcomers and experts alike).

The rustc ASCII art output isn't perfect, and the one provided by the json output doesn't provide formatting information, and VSCode doesn't let us replicate or even improve over it without writing a full blown webview that would have to handle everything on its own and not be able to pop up in place on hover, but we can use the ASCII art, stick it in a codeblock in the current pop up and gain back some of the context back. We might want to only extend the current output, or we could replace everything but the main error message (this could even be configurable).

I think doing this, even if imperfect, is important because it happens way too often that someone comes to one of our support pages asking for help, and when asked to provide the cli output they finally notice that the solution is already provided for them.

CC @Veykril

@Veykril Veykril added the A-diagnostics diagnostics / error reporting label Nov 8, 2022
@Veykril
Copy link
Member

Veykril commented Nov 8, 2022

So unfortunately, diagnostic popups don't permit markdown, but it is rendered in a monospace font so that should be fine. The other problem though is that the handling of rustc diagnostics is a mess (the Diagnostic struct we parse from the json has way too many different things that I need to wrap my head around first, like what even are child diagnostics? Why can a diagnostic have multiple primary spans or rather what is the difference between a primary and non primary one) so I wouldn't even know where to attach the original rendered diagnostic message to.
And on another note, the VSCode team has a meeting tomorrow where some of our VSCode troubles will be raised (including the diagnostics troubles, see microsoft/vscode#165810)

@estebank
Copy link
Contributor Author

estebank commented Nov 8, 2022

So unfortunately, diagnostic popups don't permit markdown, but it is rendered in a monospace font so that should be fine.

I recall having read the docs some time back that markdown was allowed in popups, but it might have been on custom popups, which I wouldn't want to burden you with trying to get working, this was meant as a "fast an easy" win.

the json has way too many different things that I need to wrap my head around first

Yeah, it has to encode too much info and it wasn't designed, it just grew.

what even are child diagnostics?

note and help blocks.

Why can a diagnostic have multiple primary spans or rather what is the difference between a primary and non primary one)

The primary spans are those that are underlined in red in the main subdiagnostic (and in cyan or yellow in help, notes and warnings), while the secondary spans are all the ones underlined in color blue. The primary span is where the error actually is, and the others "merely" provide context. There can be more than one primary span because we try to underline as little as possible, so if we have an error of a and b not being fields in struct S, for S { a, b } we have two primary spans for a and b (instead of the whole struct literal).

And on another note, the VSCode team has a meeting tomorrow where some of our VSCode troubles will be raised (including the diagnostics troubles, see microsoft/vscode#165810)

For that meeting, I would love it if you could show some good example of a complex diagnostic, like a trait object safety or trait bound error to give them context on what our requirements can be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics diagnostics / error reporting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants