-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Teach Diagnostics to highlight text #38955
Conversation
40ba66c
to
b9a04cc
Compare
Cool! |
The travis failures look legit:
|
@nikomatsakis they're. I'll fix them but will have to wait for #38916 to be merged before approving this as I think there'll be merge conflicts between that PR and this one. How does the approach to this change look overall? |
@estebank seems pretty good to me. |
☔ The latest upstream changes (presumably #38916) made this pull request unmergeable. Please resolve the merge conflicts. |
#38916 is now merged; r=me after rebase. |
I would not approach the problem in this way, I think that code which creates error messages should supply semantic information (e.g., 'this is a type') and the error handling code should decide how to format it (e.g., all types in notes will be highlighted). That allows easier customisation of error display in the compiler and allows more information to be reflected in JSON errors for IDEs and other tools which might want to do more sophisticated things than just highlight. |
@nrc in principle I would agree with you, but I'm foreseeing cases where we want to highlight things that do not match one to one to semantic information, like the ones outlined in #21025 where'd it be nice to have something like the following output: expected type `core::result::Result<lossfunction::scenario::PredictionRecord, Box<misc::OMErrorT + 'static>>` found type `core::result::Result<&str, Box<misc::OMErrorT + 'static>>` I can imagine this also being used for emphasis in places where asterisks might be used now. And of course, I feel that even though the feature is needed it should be used extremely sparingly. As for IDEs, each segment of the path of every part of the expected and found types should potentially have links to their definition. I feel all that semantic information could be presented out of line (with span like information) in the JSON output for IDEs to be easily capable of using that type info, but at the same time have simple text for clients that do not wish to use it. Leaving this PR as merely a display embellishment, and I can create a new PR that allows to associate semantic type information to parts of the diagnostics' text. |
c99fe7f
to
5b0efef
Compare
Rebased after #38916 and turned the |
5b0efef
to
c56ec9a
Compare
This seems exactly like something that should have a semantic identification - something that indicates that it is a type and the element of a type which is of interest to the user.
This is somewhat harder than it sounds. However, we are already outputting this kind of information for IDEs separately from the error messages, so there is no need to duplicate that info here (it might make sense to link in to that information by id or something, but that is probably future work). We already sort of do what you describe next - we have a 'rendered' field in the JSON error which has the message rendered as the compiler would do. The rest of the JSON message is a structural representation of the error. I think it is best to avoid embellishing the structural elements with presentation information; this ought to be kept as plain data. The highlighting might have a place in the |
I considered this, but I thought this would be a reasonable step in that direction. That said, it wouldn't be so hard to make this semantic now, I suppose, just basically needs a new enum, right?
This isn't necessarily in conflict, is it? That is, you might imagine a semantic tag for "type" (that encloses the entire type in both instances) and a semantic tag for "diff" (that encloses the diffed parts, which you showed in bold). |
c56ec9a
to
5cda1c4
Compare
True, @nikomatsakis. Given that the current json output in this PR for the epected note is: {
"message": "expected type `usize`\n found type `&'static str`",
"code":null,
"level":"note",
"spans":[],
"children":[],
"rendered":null
} Would it make sense to turn it into {
"message": "expected type `usize`\n found type `&'static str`",
"message_highlights": [
{"start": 15, "end": 20},
{"start": 37, "end": 49},
],
"code":null,
"level":"note",
"spans":[],
"children":[],
"rendered":null
} or, more closely to what @nrc advocates: {
"message": "expected type `usize`\n found type `&'static str`",
"message_annotations": [
{"start": 15, "end": 20, "type": "type", "content": "usize"},
{"start": 37, "end": 49, "type": "type", "content": "&'static str"},
],
"code":null,
"level":"note",
"spans":[],
"children":[],
"rendered":null
} |
5cda1c4
to
7578549
Compare
@estebank I'd be fine with either of those. It seems good to at least include the what kind of highlight it is. But overall I think it'd be nice to write up an RFC documenting what our JSON output ought to look like, and then implement it bit by bit. I'm wary because changes to the JSON are kind of "insta-stable" -- people can rely on them! So I might be inclined to leave the JSON alone until we at least come up with an end-to-end plan that is written down. |
@nikomatsakis does it make sense then to merge this PR as is? The places that would need to change to allow for semantic meaning instead of style are self contained and should be easy to implement once a consensus on the expected output is reached in the RFC. |
@estebank to be clear, the highlights are not currently visible in the JSON form, right? |
@nikomatsakis, correct. Only the CLI output is affected.
|
📌 Commit 7578549 has been approved by |
⌛ Testing commit 7578549 with merge 848b0a3... |
💔 Test failed - status-appveyor |
7578549
to
fc774e6
Compare
@nikomatsakis fixed. |
@nikomatsakis, @nrc, created rust-lang/rfcs#1855 for the metadata annotations information. |
@bors r+ |
📌 Commit fc774e6 has been approved by |
@estebank nice, thanks. |
Teach Diagnostics to highlight text Support styled `Diagnostic` output: <img width="469" alt="mismatched types error with colorized types in the note" src="https://cloud.githubusercontent.com/assets/1606434/21871227/93a84198-d815-11e6-88b1-0ede3c7e28ef.png"> Closes #37532 and #38901. r? @nikomatsakis CC @jonathandturner @nagisa @nrc
☀️ Test successful - status-appveyor, status-travis |
Rollup of 28 pull requests - Successful merges: #38603, #38761, #38842, #38847, #38955, #38966, #39062, #39068, #39077, #39111, #39112, #39114, #39118, #39120, #39132, #39135, #39138, #39142, #39143, #39146, #39157, #39166, #39167, #39168, #39179, #39184, #39195, #39197 - Failed merges: #39060, #39145
Rollup of 28 pull requests - Successful merges: #38603, #38761, #38842, #38847, #38955, #38966, #39062, #39068, #39077, #39111, #39112, #39114, #39118, #39120, #39132, #39135, #39138, #39142, #39143, #39146, #39157, #39166, #39167, #39168, #39179, #39184, #39195, #39197 - Failed merges: #39060, #39145
Adjust `multispan_sugg` to rust-lang/rust#38955
Support styled
Diagnostic
output:Closes #37532 and #38901.
r? @nikomatsakis CC @jonathandturner @nagisa @nrc