Discard LSP publishDiagnostic when LS is not initialized (#3403)
This is invalid according to the [LSP spec]:
> In addition the server is not allowed to send any requests
> or notifications to the client until it has responded with an
> InitializeResult, with the exception that during the initialize
> request the server is allowed to send the notifications
> window/showMessage, window/logMessage and telemetry/event as well
> as the window/showMessageRequest request to the client.
So we should discard the message when the language server is not
yet initialized. This can happen if the server sends
textDocument/publishDiagnostics before responding to the initialize
request. clojure-lsp appears to exhibit this behavior in the wild.
[LSP Spec]: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initialize
commit7547a961bb29b7619cf683a241781041aa208c37
authorMichael Davis <mcarsondavis@gmail.com>
dateWed 31 Aug 2022, 03:47 (4 years ago)
parent03f0ef9
helix-term/src/application.rs+6−1
@@ -512,7 +512,12 @@ impl Application {
512512 use helix_core::diagnostic::{Diagnostic, Range, Severity::*};
513513 use lsp::DiagnosticSeverity;
514514
515− let language_server = doc.language_server().unwrap();
515+ let language_server = if let Some(language_server) = doc.language_server() {
516+ language_server
517+ } else {
518+ log::warn!("Discarding diagnostic because language server is not initialized: {:?}", diagnostic);
519+ return None;
520+ };
516521
517522 // TODO: convert inside server
518523 let start = if let Some(start) = lsp_pos_to_pos(