-
Notifications
You must be signed in to change notification settings - Fork 799
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
Proposal: related locations for Diagnostics #260
Comments
❤️ cc @damieng |
Summary: Lots of languages (including Hack and Flow) want to report additional related locations for each diagnostic. LSP doesn't currently allow this. I put out a proposal for what LSP should do: microsoft/language-server-protocol#260 Atom does already allow it. This diff adds the proposed support for relatedLocations, and hooks it into Atom. Reviewed By: hansonw Differential Revision: D5267143 fbshipit-source-id: 77b48725abdcf3e58dfc5b85db870a2ab11e48a0
Summary: Hack sometimes (often\!) emits multiple locations per diagnostic. LSP doesn't current allow for multiple locations. So I wrote a proposal for it: microsoft/language-server-protocol#260 This diff implements the proposal, and uses it to report the multiple locations that come out of hh_server. Reviewed By: arxanas Differential Revision: D5267184 fbshipit-source-id: 79a5d33b94020b8b98a2674df3d902be9653f852
There's also a feature-request from Rust folks for VSCode to display related locations: It's related to the VSCode feature request for "multiline errors". (although multiline errors are a different concept from related locations) cc @sandy081 |
I like the proposal, however I would change one thing. Since related locations are to 99% in the same file I would not reuse the location definition since it has a mandatory uri property. I would instead do: interface RelatedDiagnosticInfo {
uri?: string;
range: Range;
message: string;
} For consistency reason I would add a client capability for it. It is easy to set by the clients. @jrieken do you have any comments on this? For completeness: |
👎 it was a mistake to do that in the |
I see the problem when the structure is reused in two requests. But I also see the problem of sending lots of identical strings (which in this case might not be huge, I agree). May be such an optimization must be more explicit so that users need to provide a value. |
This has been added to the protocol. See 69028bf and e361dca. microsoft/vscode-languageserver-node#324 was the original PR that introduced the change to the VS Code Language Server packages. |
Yep, this should now work end to end, LSP, VS Code Extension API, and VS Code UX |
Closing the issue. |
Publish new version of the LSP node libraries today which already implement the LSP protocol on top of the VS Code protocol. |
Lots of languages want to show "related locations" for diagnostics. I propose
I think that we don't need capability flags for this. The language server should always blindly send related locations if it has any. If the client doesn't support the display of related locations, or if it does but the user has turned that display off, then only the primary Diagnostic will be displayed, and the language server should make sure that the primary Diagnostic makes sense on its own.
Here are some example languages which report related locations. I've added squiggles to show conveniently which are the related locations.
C#
Note that the C# plugin for VSCode doesn't currently display related locations. Actually, I know that the previous-generative native C# compiler used to report related locations, but I don't know if the current Roslyn-based C# compiler still does. I do know that
AdditionalLocations
are central to Roslyn analyzers: link.Hack
Flow
SARIF
Microsoft's SARIF, the Static Analysis Results Interchange Format, also uses relatedLocations similarly:
Discussion
I don't have good thoughts on how VSCode should best display related locations. Here are illustrations of how Atom/Nuclide displays related locations. Observe in the error list there's a checkbox to turn on or off the display of those additional locations. (Typically, users prefer to see just the single line report when they're working through lots of diagnostics, but they prefer to either hover or see multiple related locations when they're drilling down into a complicated diagnostic).
There is a related issue #250 which suggests that diagnostics should change to being markdown rather than plain text. That would theoretically allow related locations to be embedded into the markdown string, e.g.
Markdown may or may not be a good idea for formatting the diagnostics. But I think it would be bad to use this markdown approach as the vehicle for related locations because (1) it's information-overload, (2) it doesn't let users turn off the related locations in their error list, (3) there's nothing in the file URL that lets it specify a range, (4) the "hit box" of each location is much smaller and it no longer indicates easily which file the target is in.
C# doesn't have a unique message for each related location. That's why it merely says "(Location of the symbol related to previous error)". I understand the C# team don't really like this message. That's why I believe it's important that LSP should allow the language server to specify its own message, on a per-related-location basis.
I proposed that the
message
property inRelatedLocation
should be mandatory. That's because I don't think the client should be in the business of synthesizing a default message along the lines "(Location of the symbol related to the previous error)". That should be the domain of the LSP server, and indeed the LSP server is the one that knows how to localize the message properly.The text was updated successfully, but these errors were encountered: