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

feat(lsp): support textDocument/diagnostic specification #7900

Closed
wants to merge 1 commit into from

Conversation

woojiq
Copy link
Contributor

@woojiq woojiq commented Aug 10, 2023

Closes #7757

Explanation for easier review, see #7900 (comment).

Tested manually with ruby-lsp.

@woojiq woojiq changed the title feat(lsp): basic support textDocument/diagnostic specification feat(lsp): support textDocument/diagnostic specification Aug 10, 2023
@woojiq woojiq force-pushed the lsp-pull-diagnostic branch 2 times, most recently from 507a24e to c56b8b8 Compare August 10, 2023 17:33
@woojiq woojiq marked this pull request as draft August 10, 2023 18:23
@woojiq woojiq marked this pull request as ready for review August 11, 2023 16:21
@woojiq woojiq marked this pull request as draft August 11, 2023 20:20
@woojiq
Copy link
Contributor Author

woojiq commented Aug 12, 2023

Few notes for easier review.

I took a large piece of code from PublishDiaagnostic notification and splited in two methods:

Added text_document_diagnostic method to send actuall json-rpc request, it looks like any other text_document_* method (hover, definition etc). And the actual thing you want to review is pull_diagnostic_for_current_doc which is called later in handle_idle_timeout . There is nothing hard tbh. Just send a server request, then create callback for extracting info from response (aforementioned method lsp_diagnostic_to_diagnostic and add_diagnostics are reused).
And the last thing to mention is I added field supports_publish_diagnostic for Client, during first "PublishDiagnostic` notification from a server set this field to true. And then, if it is true, we do not run PullDiagnostic. I think we should prefere Publish.

@woojiq woojiq marked this pull request as ready for review August 12, 2023 13:18
@archseer archseer requested review from pascalkuthe and the-mikedavis and removed request for pascalkuthe September 23, 2023 01:51
@the-mikedavis the-mikedavis added A-language-server Area: Language server client S-waiting-on-review Status: Awaiting review from a maintainer. labels Sep 24, 2023
Implementation of pull diagnostics introduced in LSP 3.17.
@pascalkuthe
Copy link
Member

pascalkuthe commented Sep 26, 2023

I think it makes sense to delay this until the event system (#8021) lands. We really only want to pull diagnostics of all visible documents (only when the contents of any document actually changed, likely with a debounce, if interFileDependencies is false in the capabilities we actually only need to pull if a visible file has changed). This kind of use case is precisely what I intended the event system for.

Additionally, the support implemented here is still lacking some features that are needed to make pull diagnostics really work:

I think the last two points are pretty optional but the first two capabilities seem pretty essential to me.

Comment on lines +284 to +294
pub fn set_publish_diagnostic(&self, val: bool) {
self.supports_publish_diagnostic
.fetch_or(val, atomic::Ordering::Relaxed);
}

/// Whether the server supports Publish Diagnostic
pub fn publish_diagnostic(&self) -> bool {
self.supports_publish_diagnostic
.load(atomic::Ordering::Relaxed)
}

Copy link
Member

Choose a reason for hiding this comment

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

Instead of figuring out of the server has sent a publish diagnostic notification we can simply assume the server will not send them if it has the pull diagnostic capability set (the server will then look at our capabilities and make a decision based on that)

@woojiq
Copy link
Contributor Author

woojiq commented Sep 26, 2023

@pascalkuthe thanks for the extensive answer. I agree with you. I'm going to rework this PR after the event system is deployed. If for some reason I miss this part, feel free to ping.✌️

@4ndv
Copy link

4ndv commented Feb 5, 2024

@woojiq looks like the event system was merged recently

@woojiq
Copy link
Contributor Author

woojiq commented Feb 5, 2024

@woojiq looks like the event system was merged recently

I will have a look. What language server do you use that you need pullDiagnostic, ruby-lsp?

@4ndv
Copy link

4ndv commented Feb 6, 2024

@woojiq looks like the event system was merged recently

I will have a look. What language server do you use that you need pullDiagnostic, ruby-lsp?

Planning to, yes. Right now I'm using lsp mode in rubocop, but it lacks some stuff

@the-mikedavis the-mikedavis added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from a maintainer. labels Feb 10, 2024
@woojiq
Copy link
Contributor Author

woojiq commented Apr 10, 2024

Unfortunately, I am no longer interested in it for two reasons:

  1. none of language servers I use (clangd, rust-analyzer) support this;
  2. much more work need to be done than I thought

Although implementing this probably shouldn't be that difficult since almost all the building blocks for working with LSP are already in the codebase.

I might come back to it in the summer, but point 1 is crucial. Sorry for the false expectations.

@woojiq woojiq closed this Apr 10, 2024
@David-Else
Copy link
Contributor

Seems from version 3.0.1 vscode-eslint uses textDocument/diagnostic: hrsh7th/vscode-langservers-extracted@859ca87#commitcomment-142170236

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-language-server Area: Language server client S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add pullDiagnostics lsp feature
5 participants