-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add metadata to diagnostic messages' json output #1855
Conversation
Annotate the diagnostic messages with metadata for tools and terminal colorized output.
I am in favor of the ideas here, but I think we should go ahead and expand the scope of the RFC slightly to cover the JSON format in full. As far as I know we have no RFC on this topic, right? The closest thing I can find is this internals discussion, but I also found an old sketch of a JSON format proposal that @nrc and I mocked up, which I copied into a gist. |
Also, the need for having a "fully rendered" version in the JSON, in addition to the semantic markup, came up in a random thread recently. |
I already expressed my optinion elsewhere; I’ll reproduce it here for posterity. I think at this point everybody would be better served by actually structured json errors. Not the sort of messages that are still pretty much a text with attached span, and now, some other data, but fully structured stuff that could be inspected programatically. Something like this:
with accompanying stable library to figure out these structured jsons into textual representations if necessary. IMO The problem here is more general. Tools (probably?) want to inspect semantic information in the error messages. They should be able to do it without parsing every single variant of the error message rustc could emit. Adding metadata helps with the issue only marginally (“hey, look these parts might be interesting, but its still up to you to figure out stuff”), and it seems to me like the RFC is proposing to work around the actual problem instead of really solving it. |
@nagisa Hmm, I think that could be a useful component to the message, but I think many tools will want to work generically across all messages without having to understand them semantically. It seems to me that there is little harm in stuffing tons of data into these JSON messages. At least that has been our theory thus far. So I suspect we could start with a relatively generic format, close to what we have, but that doesn't preclude us from adding richer semantic content later, right? |
That’s where a shared library with something like
in it would come in. |
@nagisa but (a) not all consumers are in Rust and (b) even those that are will not necessarily want to be recompiled to work with new versions of rustc that have more errors than the old versions, right? |
That’s why
I guess that’s true to some extent. The whole point of dylibs is to make them match the rest of the stuff on the system and I don’t see an usecase in having something like such library and rustc installation separate. |
OK, this RFC isn't getting much attention. Let me see if I can get it back off the ground. There have so far been two major comments here:
I think the key ingredient from my POV was that we include both semantic and presentation information. I envisioned the presentation output being something like an "html-ified" version of rustc's output, except with some additional semantic content (e.g., for each line in a snippet, we should give the filename/line-number that it is quoting, and also indicate what is the error-code and so forth -- you could think of this as "HTML-like tags" w/ descriptive classes and attributes). In particular, we want to give consumers the ability to easily reproduce rustc's diagnostic output if they wanted, and to have that reproduction keep up as the compiler changes. I think there are a number of use cases for this:
cc @rust-lang/tools -- thoughts? @estebank, I'd be happy to work with you to expand the RFC slightly, or perhaps propose such edit, if you like. |
Ideally I'd love to take both routes simultaneously. I think it makes sense to include a sort of visual markup in the error message so tools can implement the rendering however they like, and then it'd also be neat to include a library to parse these messages that does it all for you (either with a Rust or a C API). Both, however, seem like very ambitious projects that seems unlikely to reach completion any time soon. I would be skeptical that anything short of full-blown HTML would be suitable for our purposes in terms of being maximally forwards-compatible while also representing errors faithfully. Similarly I can see how maintaining such a library would be burdensome on us as it's just yet more API stability we have to consider. My personal preference would be to be as conservative as possible here. Let's only expose semantic information which is easily provided far into the future, and then we can see what builds up externally to work with these messages and display them. |
OK, so @alexcrichton I think you're saying you'd be happy to go with the RFC roughly as is? I can get behind that. I do agree it'd take a bit of iteration and experimentation to find a JSON format we are happy with. |
I'm not intimately familiar with the error message/json message area this RFC is modifying, but yes to me it looks like a semantic extension that we should always be able to implement, so I'd be in favor of this. |
This RFC appears to've stalled. @alexcrichton, @nikomatsakis, from a quick read it seems like you are both roughly in favor of heading in the direction of this RFC? Either of you want to move toward FCP? |
I fear that I've mostly just commented on this RFC in an "advisory capacity" in the sense that I don't personally have enough understanding of all the nuances here to propose an FCP. I would basically just being doing so because it "seems good" and it's conservative enough to not cause undue maintenance burden if we change course later. I continue to also think that a "markup" version of compiler error messages, while mega useful, need not block this RFC as it's compatible. |
Oh I also mean to cc @matklad with his IntelliJ eyes |
I would love to see some concrete examples of tools and use cases in the RFC. My gut feeling is that this actually adds relatively little value. We don't use JSON errors in IntelliJ, so having more semantic information won't be useful for us. If you want to go really fancy with errors, chances are you need something like compiler as an API / RLS to ask some custom questions, to get info beyond that presented in the error message directly, or to query about valid code. |
@matklad what does IntelliJ use to display type and lifetime errors? Or, rather, what does IntelliJ use |
Currently, we just present the usual text output from the compiler/cargo and then hyperlink file locations in the text output, much like Emacs compilation mode. We don't display errors inline with the code, so we don't need spans. We could have done inline errors, but I believe that it's fundamentally wrong to launch compilation of the whole project on every code modification (even with a proper incremental compilation, although I can be convinced otherwise on this particular point :) ), and there's no way to get errors for a subset of files on demand at the moment. |
The RLS as it is doesn't, I don't think, have an adequate way of exposing error messages -- mostly because the language server protocol is too simplistic, I think (i.e., it doesn't support the richly structured errors that Rust produces). @jonathandturner or @nrc could confirm though. But I imagine we'll have to grow such a thing, and then it might make sense to have |
Confirmed, it is very restricted. |
As @nagisa said, I'd rather have a properly structued error, than one with annotations. I would also like to have the fully rendered output - we have a field for it already, but don't use it much. |
Ping @nrc and @nikomatsakis, what's up with this RFC? |
I'm going to close this RFC as inactive. Stakeholder, please feel free to reopen if you'd like to pick back up this topic! |
Annotate the diagnostic messages with metadata for tools and terminal
colorized output.
Rendered.