From fe0e9a2b9bd96f00669edc77ae33fd696c0f0c2d Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Wed, 28 Jun 2023 15:59:13 -0500 Subject: [PATCH] LSP: Discard publishDiagnostic from uninitialized servers (#7467) The spec explicitly disallows publishDiagnostic to be sent before the initialize response: > ... the server is not allowed to send any requests or notifications to > the client until it has responded with an InitializeResult ... (https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#initialize) But if a non-compliant server sends this we currently panic because we '.expect()' the server capabilities to be known to fetch the position encoding. Instead of panicking we can discard the notification and log the non-compliant behavior. --- helix-term/src/application.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 47744d00b5c7..c9ecb03d00a8 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -750,7 +750,12 @@ impl Application { return; } }; - let offset_encoding = language_server!().offset_encoding(); + let language_server = language_server!(); + if !language_server.is_initialized() { + log::error!("Discarding publishDiagnostic notification sent by an uninitialized server: {}", language_server.name()); + return; + } + let offset_encoding = language_server.offset_encoding(); let doc = self.editor.document_by_path_mut(&path).filter(|doc| { if let Some(version) = params.version { if version != doc.version() {