Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd formatted compiler message labels & children to diagnostics #664
Conversation
alexheretic
referenced this pull request
Jan 18, 2018
Closed
Explore providing secondary labels and errors/notes using textDocument/hover instead #662
alexheretic
force-pushed the
alexheretic:fuller-diags
branch
2 times, most recently
from
38e5528
to
e69a2f9
Jan 18, 2018
This comment has been minimized.
This comment has been minimized.
|
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? |
This comment has been minimized.
This comment has been minimized.
alexheretic
force-pushed the
alexheretic:fuller-diags
branch
from
e69a2f9
to
3d42368
Jan 20, 2018
This comment has been minimized.
This comment has been minimized.
|
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 => {},
}
} |
alexheretic
force-pushed the
alexheretic:fuller-diags
branch
from
3d42368
to
86c4e53
Jan 20, 2018
alexheretic
added some commits
Jan 18, 2018
alexheretic
force-pushed the
alexheretic:fuller-diags
branch
from
86c4e53
to
ec77c1c
Jan 20, 2018
This comment has been minimized.
This comment has been minimized.
|
@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. |
This comment has been minimized.
This comment has been minimized.
|
@alexheretic, @Xanewok Thanks for working on this ! @alexheretic I like the additionals diagnostics per each secondary span. |
This comment has been minimized.
This comment has been minimized.
|
@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. |
Xanewok
and others
added some commits
Jan 20, 2018
This comment has been minimized.
This comment has been minimized.
|
Correct me if I'm wrong, but differents errors could have the same heading, no ? |
alexheretic
force-pushed the
alexheretic:fuller-diags
branch
from
3dbae18
to
685917b
Jan 20, 2018
This comment has been minimized.
This comment has been minimized.
|
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? |
This comment has been minimized.
This comment has been minimized.
|
Yes sure, I see your point. |
This comment has been minimized.
This comment has been minimized.
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 |
Xanewok
merged commit a786358
into
rust-lang:master
Jan 21, 2018
This comment has been minimized.
This comment has been minimized.
|
Once again, @alexheretic thanks for working on this! |




alexheretic commentedJan 18, 2018
•
edited
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.