-
Notifications
You must be signed in to change notification settings - Fork 185
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
Moved diagnostic panel contributions from SessionBuffer to Session (#1868) #1881
Conversation
…ublimelsp#1868). * created DiagnosticsManager, owned by Session * Session.m_textDocument_publishDiagnostics() now does the following: - add incoming diagnostics to DiagnosticsManager (new) - notify WindowManager about diagnostics update via WindowManager.update_diagnostics_panel_async() (new) - if there is a SessionBuffer for this uri, notify it via SessionBuffer.on_diagnostics_async() (unchanged, for in-view diagnostics) * WindowManager.update_diagnostics_panel_async() now queries the Session DiagnosticsManagers for contributions (instead of DocumentSyncListeners) * removed sorting of diagnostics: the order in which diagnostics are reported by the server carries meaning (maybe add optional sorting controlled by user setting?) * file paths in diagnostics panel are now absolute (same as in Sublime's "Find Results"): in multi-folder projects the full path is needed; besides, WindowManager.get_project_path() appears to be buggy * removed "result_base_dir" from diagnostics panel settings: with absolute file paths it isn't needed anymore and it didn't work with multi-folder projects anyway * removed all diagnostics panel related code from SessionBuffer, DiagnosticSeverityData and DocumentSyncListener (handling of in-view diagnostics is unchanged)
The diags seem to be keyed by the string representation of their URI. Have you checked if things keep working as expected for case-insensitive file systems and symlinks? |
No, but the uri is taken directly as sent by the language server, so I think we can assume that the language server is taking care of it. The same uri is used in LSP as key for the session buffers all the time, nothing new here. |
I've run into a problem with this using Pyright on Windows: it seems that the URI for the file in the focused view does not have the colon (in "c:/") percent-encoded, while the URIs for other files have it encoded as %3A. This means that if a diagnostic is generated for a file in the background and then fixed while that file is focused, it won't be removed from the diagnostic panel (until another diagnostic is generated while the file is in the background). I'm not sure if this is LSP or the server doing something wrong, but in any event I'm working around it for now by passing the URI to parse_uri (from plugin/core/url.py) before using it as a dict key. |
Could you maybe turn on |
Maybe this is related to #1796? |
This also adds some Windows path normalisation.
On second thought, it's better to parse the URI early and use the path as key anyway. |
From the logs, it seems like Pyright is being inconsistent while LSP is sending non-RFC-compliant URIs, so I'm not sure which should be changed. The second and fifth lines are reports for the same file with different URIs, and Pyright seems to be aware of that (or at least it's not sending any further reports with the escaped URI):
And LSP is not escaping the colon because pathname2url on Windows never has (originally it replaced the colon with a pipe, which would not be any better in this situation). (https://github.com/python/cpython/blob/51ed2c56a1852cd6b09c85ba81312dc9782772ce/Lib/nturl2path.py#L77). |
It looks like Pyright uses URIs unchanged if they were received from the client before and creates new URIs percent-encoded itself. If that is desirable or not could be debated but is beyond the scope of this PR, I would say. (I brougt it up myself, I know.) As I read the RFC, the unescaped colon in an absolute path preceded by a scheme is valid (https://www.rfc-editor.org/rfc/rfc3986#section-3.3). Percent-encoding safe characters is allowed too. So, what to say, both Pyright and LSP are probably right. Parsing the URI and normalising the path before using it to key the diagnostics is the thing to do. Could you please check if this PR works properly for you after my last commit based on your workaround? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sure you'll stick around if any bugs appear @htmue
Yes, works for me with the latest commit. Thanks! |
Thanks for your contribution! |
As before, in-view diagnostics are handled by the SessionBuffers. Panel contributions are now managed directly and only by the Sessions, with help of the new DiagnosticsManager. (I bypassed the compressor!)
See more in the commit message.
It turned out that this was all that's needed. There is no need for any knowledge of session buffers in the diagnostics manager (#1868 (comment)).
For now I did only cursory testing with 'haskell-language-server'. It seems to work and I wanted to upload the fix as soon as possible (and get it out of my head). During the next work week there will be some heavy testing on a big multi-folder project with different language servers.