Add formatted compiler message labels & children to diagnostics#664
Add formatted compiler message labels & children to diagnostics#664Xanewok merged 8 commits intorust-lang:masterfrom
Conversation
38e5528 to
e69a2f9
Compare
|
Looks like we're getting our own ui-test suite! However, there's also another reason to consider using textDocument/hover (as per @nrc's suggestion) for displaying secondary diagnostics: it supports Markdown (which means we'll get some more formatting for free, that's already there), whereas diagnostic messages does not. Also it'd possibly mean less clutter in Problems pane in vscode. @alexheretic @nrc thoughts? |
e69a2f9 to
3d42368
Compare
|
I wanted to see if it was feasible to generate additional diagnostic per each secondary span, and I'd say the result is good enough (my branch): Each span, primary or secondary, has the compiler diagnostic message on top, then spaced out, is a label for each span (I found it most readable, personally) and on the bottom there are notes and whatnot, like before. @alexheretic what do you think? Here's the file I've been testing on: use std::env;
fn takes_string(_: String) { }
fn takes_borrow(_: &String) { }
fn main() {
// Case #1 (multiline)
let string = String::new();
takes_string(string);
takes_string(string);
// Case #2 (same line, multiple secondaries)
let _shim = env::current_exe().ok().and_then(|path| path.to_str()).map(String::from);
// Case #3 (primary/secondary overlap, secondary has "suggestions" -
// actually it's only a label, with no machine-readable suggestions)
match &Some(String::new()) {
&Some(string) => takes_borrow(&string),
&None => {},
}
} |
3d42368 to
86c4e53
Compare
Provides "consider giving `v` a type" on type_annotations_needed scenarios
86c4e53 to
ec77c1c
Compare
|
@Xanewok great stuff! I've removed the heading from secondary spans that are within the primary (ie your 'cannot move out of borrowed context' example), fixed up the tests and added a test case for that. |
|
@alexheretic, @Xanewok Thanks for working on this ! @alexheretic I like the additionals diagnostics per each secondary span. |
|
@sebastiencs They do have common headings so should in most cases be clear what they relate to. What you suggest would be really nice, but I'm not sure the language server protocol can do it. The Perhaps this could be added to the protocol or there's another way. But first lets just try to do all that we can within the current protocol. |
Fix tests add test `message_move_out_of_borrow`
|
Correct me if I'm wrong, but differents errors could have the same heading, no ? |
3dbae18 to
685917b
Compare
|
That's right, most of the clients seem to not use the But it would be non-standard client behaviour, requiring custom code in each client. I think if the functionality is desired it should be added to the protocol, that way the client libraries will naturally pick it up. In any case shall we say it's out of this pr's scope, maybe raise a seperate issue here and/or on https://github.com/Microsoft/language-server-protocol after we merge this pr in? |
|
Yes sure, I see your point. |
The exact discussion about linking the diagnostics can be found in #17. There are some proposals to extend the LSP for this and to see how that works out for us. Thanks for updating the tests! I think we can merge this now. One thing keeps me wondering is, how should this interact with I'd go with what we have and see if the secondary spans really lead to too much noise - if so, we can implement a (separate to |
|
Once again, @alexheretic thanks for working on this! |




Related to #649, #662 this pr adds
CompilerMessagesecondary.span&.childreninformation to diagnostics. This really helps the diagnostics in being useful.Atom
before


vvv
Vscode
before


vvv
With vscode it cuts off the message mid-word at the max width. Atom wraps properly. I think this is the responsibility of the client, as wrapping isn't too arduous. Even so the messages are quite usable in vscode and I'm sure people will appreciate them even cut in half.
Implementation notes
I've gone to some pains to avoid showing messages meant for different areas of the code by only including children-spans that are 'within' the primary span and secondary spans that are on the same line. There is some more work for generating additional diagnostics for the other spans.
Testing
Since there will be many compiler messages to get right I've added unit tests for my cases (which are fast / can scale to many tests). The compiler output generated by cargo with
--mesage-format=jsonare stored in test_data/compiler_message/*.json files. We can add more cases as we discover suboptimal output.