Skip to content
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

ruff server: Support publish diagnostics as a fallback when pull diagnostics aren't supported #11092

Merged
merged 2 commits into from
Apr 23, 2024

Conversation

snowsignal
Copy link
Contributor

Summary

Fixes #11059

Several major editors don't support pull diagnostics, a method of sending diagnostics to the client that was introduced in version 0.3.17 of the specification. Until now, ruff server has only used pull diagnostics, which resulted in diagnostics not being available on Neovim and Helix, which don't support pull diagnostics yet (though Neovim 10.0 will have support for this).

ruff server will now utilize the older method of sending diagnostics, known as 'publish diagnostics', when pull diagnostics aren't supported by the client. This involves re-linting a document every time it is opened or modified, and then sending the diagnostics generated from that lint to the client via the textDocument/publishDiagnostics notification.

Test Plan

The easiest way to test that this PR works is to check if diagnostics show up on Neovim <=0.9.

@snowsignal snowsignal added the server Related to the LSP server label Apr 22, 2024
@snowsignal snowsignal added this to the Ruff Server: Beta milestone Apr 22, 2024
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@snowsignal snowsignal merged commit 62478c3 into main Apr 23, 2024
17 checks passed
@snowsignal snowsignal deleted the jane/server/diagnostics/publish branch April 23, 2024 04:06
Copy link
Member

@dhruvmanila dhruvmanila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for implementing it so quickly!

Unless it's already done, we'd need to clear the diagnostics for the document for on_close event otherwise the diagnostics will remain in the "Problems" tab even after closing the file. Refer https://github.com/astral-sh/ruff-lsp/blob/187d7790be0783b9ac41ce025a724cf389bf575c/ruff_lsp/server.py#L459-L464

@MichaReiser
Copy link
Member

I think our old extension also had an option to pull diagnostics only on save. But I don't mind pushing this out until we're asked to build this (especially because we can't really support it when using pull diagnostics)

@dhruvmanila
Copy link
Member

@MichaReiser Are you referring to onType / onSave option value? I was about to comment on that.

@snowsignal
Copy link
Contributor Author

@dhruvmanila I've opened an issue (#11114) to solve the problem you mentioned earlier.

@snowsignal
Copy link
Contributor Author

As for the onSave/onType setting - I was going to hold off on implementing that unless there seems to be a need for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
server Related to the LSP server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ruff server should use textDocument/publishDiagnostics when pull diagnostics aren't supported
4 participants