-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
lsp: Implement support for the textDocument/diagnostic
command
#19230
base: main
Are you sure you want to change the base?
lsp: Implement support for the textDocument/diagnostic
command
#19230
Conversation
crates/language/src/language.rs
Outdated
@@ -201,6 +201,7 @@ pub struct CachedLspAdapter { | |||
pub name: LanguageServerName, | |||
pub disk_based_diagnostic_sources: Vec<String>, | |||
pub disk_based_diagnostics_progress_token: Option<String>, | |||
pub previous_document_diagnostic_result_id: Option<String>, |
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.
Still not sure about the place to store this token that Zed should store and use between sending/receiving textDocument/diagnostic
commands.
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.
Moved the previous_document_diagnostic_result_id
to LanguageServerState
enum. Let me know if that's ok.
Whoops, conflicts. I will resolve them in a bit. |
2180cc7
to
04e102e
Compare
Done. |
5f35960
to
2e2e437
Compare
0e98542
to
3ab5b2c
Compare
Ok, this is ready for the first round of review. Thanks! |
5c1e305
to
2d3d38c
Compare
Hi. While working on #19230 I noticed that some servers send a request to unregistered the `textDocument/rename` capability. I thought it would be good to handle that message in Zed: ```plaintext [2024-10-18T21:25:07+02:00 WARN project::lsp_store] unhandled capability unregistration: Unregistration { id: "biome_rename", method: "textDocument/rename" } ``` So this pull request implements that. Thanks. Release Notes: - N/A
…ndustries#19427) Hi. While working on zed-industries#19230 I noticed that some servers send a request to unregistered the `textDocument/rename` capability. I thought it would be good to handle that message in Zed: ```plaintext [2024-10-18T21:25:07+02:00 WARN project::lsp_store] unhandled capability unregistration: Unregistration { id: "biome_rename", method: "textDocument/rename" } ``` So this pull request implements that. Thanks. Release Notes: - N/A
2d3d38c
to
4e6c9fd
Compare
Resolved merge conflicts. |
4e6c9fd
to
b7b3be1
Compare
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.
One thing I do not understand is how both diagnostics pull and diagnostics push models are supposed to live together.
-
For instance, rust-analyzer has its own diagnostics, fast to update, and the cargo check-based ones, which may take seconds to update on large projects.
If we start to wait for all diagnostics or nothing, it might get slower — right now it's ok, as r-a pushes slow and fast ones separately.
How does this feature work on Zed? -
How should the LSP server and the client agree what to use?
It seems, that the push method is the default, and pull is an opt-in one, that will be used right after we declare this new capability? -
Is it ok to handle both push and pull at the same time, as we do now?
We have to include potential refresh requests that we either have to support (as declared currently in the capabilities) or declare incapable.
@SomeoneToIgnore Thanks for this amazing review! This is what I've been waiting for. I will start working on your comments and answering your questions about handling both push and pull models for diagnostics. Do you want me to convert this PR to draft to mark it as non-ready? |
Small update: I am still working on it. I was OOO last week. |
5b9ee27
to
9de1d98
Compare
9de1d98
to
9ddc70c
Compare
There have been a lot of changes recently in the related crates. I will double-check all the changes here. Also, I may need to review the implementation approach in this commit The reason why I went this way is that the |
e7fe69e
to
fa673d1
Compare
93c99eb
to
7bfaf2d
Compare
} else if let project::Event::LanguageServerAdded(_, _, _) = event { | ||
editor.tasks_pull_diagnostics_task = Some(editor.refresh_diagnostics(cx)); | ||
} else if let project::Event::LanguageServerRemoved(_) = event { | ||
editor.tasks_pull_diagnostics_task = Some(editor.refresh_diagnostics(cx)); |
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.
Question: Not sure if triggering the task for pulling diagnostics here is the correct approach. My thinking is with the MultiLspQuery
we want to pull new diagnostics sostics every time new LSP is added or removed.
@SomeoneToIgnore Hi! Can you please do a smoke check of this PR? Just to guide me if I am moving towards the right direction with the task-based approach and additional protobuf messages. The latter is the major question to me since I have had to do it to properly pass LSP diagnostics between Zed and LSPs. The main difference is the structure of push-based and pull-based diagnostics is different. Thanks for the suggestion about using
AFAIU, it depends on the LSP. I wonder if it makes sense to provide a configuration option in Zed to switch between push and pull-based models?
I think it is, but I am not sure. In my tests, I used Ruby LSP with pull-based diagnostics and Thanks again! |
7bfaf2d
to
26f6751
Compare
Thank you for working on this. |
lsp: use task-based approach for pulling diagnostics
Requesting diagnostics for a document can return an empty result meaning there are no new diagnostics for the current document. Returning an empty vector could indicate that. It would be good to avoid that and return `None` if diagnostics haven't changed.
26f6751
to
9e79ecd
Compare
Closes #13107
Release Notes:
textDocument/diagnostic
command.Brief
This is draft PR that implements the LSP
textDocument/diagnostic
command. The goal is to receive your feedback and establish further steps towards fully implementing this command. I tried to re-use existing method and structures to ensure:The current implementation is done via a new LSP command
GetDocumentDiagnostics
that is sent when a buffer is saved and when a buffer is edited. There is a new method calledpull_diagnostic
that is called for such events. It has debounce to ensure we don't spam a server with commands every time the buffer is edited. Probably, we don't need the debounce when the buffer is saved.All in all, the goal is basically to get your feedback and ensure I am on the right track. Thanks!
TODO
References
In action
You can clone any Ruby repo since the
ruby-lsp
supports the pull diagnostics only.Steps to reproduce:
asdf
or `mise).bundle install
gem install ruby-lsp
CleanShot.2024-10-13.at.13.27.22.mp4