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

LSP: Don't advertise support for Pull Diagnostics #627

Merged
merged 1 commit into from
May 16, 2024

Conversation

ryansch
Copy link
Contributor

@ryansch ryansch commented Apr 29, 2024

Standard doesn't actually support the Pull Diagnostics that were added in LSP 3.17. It supports Push Diagnostics just fine.

Pull Diagnostics: Advertise support via diagnosticProvider in the server capabilities. Respond to textDocument/diagnostic with diagnostics. Note that the textDocument/diagnostic message does not include the text to be diagnosed.

Push Diagnostics: At some point after receiving a textDocument/didOpen or a textDocument/didChange, send a textDocument/publishDiagnostics to the client.

Pull Diagnostics give the client more control over when diagnostics are computed and received and are preferred going forward. Since Standard doesn't actually support them (yet?) we shouldn't advertise that we do.

Context

I figured all of this out while trying to figure out why neovim 0.10 nightly wouldn't update Standard's diagnostics until I forced a buffer reload. It seems that neovim is getting confused when Standard doesn't give a response to textDocument/diagnostic.

Turning off the advertisement for Pull Diagnostics caused neovim to stop sending the textDocument/diagnostic messages entirely and restored support for the existing textDocument/publishDiagnostics messages.

References

https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_pullDiagnostics
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#serverCapabilities
https://atlee.ca/posts/pull-diagnostic-support-for-neovim/

Standard doesn't actually support the Pull Diagnostics that were added
in LSP 3.17. It supports Push Diagnostics just fine.

Pull Diagnostics: Advertise support via diagnosticProvider in the server
capabilities. Respond to textDocument/diagnostic with diagnostics. Note
that the textDocument/diagnostic message does not include the text to be
diagnosed.

Push Diagnostics: At some point after receiving a textDocument/didOpen
or a textDocument/didChange, send a textDocument/publishDiagnostics to
the client.

Pull Diagnostics give the client more control over when diagnostics are
computed and received and are preferred going forward. Since Standard
doesn't actually support them (yet?) we shouldn't advertise that we do.
@ryansch ryansch marked this pull request as ready for review April 29, 2024 14:31
@searls
Copy link
Contributor

searls commented May 1, 2024

I think this should be tested in the VS Code extension before merge. (Just in case VS Code fails to successfully add diagnostics provided by Standard in the Problems view if we don't purport to provide diagnostics)

@ryansch
Copy link
Contributor Author

ryansch commented May 1, 2024

@searls I can fire up VS Code and do said testing. I'll report back.

@ryansch
Copy link
Contributor Author

ryansch commented May 1, 2024

@searls VS Code seems to work just fine with this change. I'm going to have our team run with this change to make sure.

@searls
Copy link
Contributor

searls commented May 1, 2024 via email

@ryansch
Copy link
Contributor Author

ryansch commented May 13, 2024

@searls We haven't had any issues with either vscode or neovim (release or nightly).

Comment on lines -69 to -82
def test_diagnotic_route
msgs, err = run_server_on_requests({
method: "textDocument/diagnostic",
jsonrpc: "2.0",
params: {
textDocument: {
uri: "file:///path/to/file.rb"
}
}
})

assert_equal "", err.string
assert_equal 0, msgs.count
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any intentions to remove rather than update the test case as follows?

  def test_diagnotic_route
    msgs, err = run_server_on_requests({
      method: "textDocument/diagnostic",
      jsonrpc: "2.0",
      params: {
        textDocument: {
          uri: "file:///path/to/file.rb"
        }
      }
    })

-   assert_equal ", err.string
-   assert_equal 0, msgs.count
+   assert_equal "[server] Unsupported Method: textDocument/diagnostic\n", err.string
+   assert_equal 1, msgs.count
  end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure that spec makes sense like that. Since we don't advertise support for it, a client won't ever send us that message.

@searls
Copy link
Contributor

searls commented May 16, 2024

This all seems reasonable and worth merging. If it causes any regression in the VS Code extension, we're sure to hear about it

@searls searls merged commit 44b7061 into standardrb:main May 16, 2024
5 checks passed
koic added a commit to koic/rubocop that referenced this pull request May 16, 2024
bbatsov pushed a commit to rubocop/rubocop that referenced this pull request May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants