From 4f066b1cc628e2d3c69da9bdd0b16f1a8e74ce6f Mon Sep 17 00:00:00 2001
From: Michael Davis <mcarsondavis@gmail.com>
Date: Sun, 12 Mar 2023 19:29:58 -0500
Subject: [PATCH] LSP: No-op client/registerCapability requests (#6258)

---
 helix-lsp/src/lib.rs          |  5 +++++
 helix-term/src/application.rs | 11 +++++++++++
 2 files changed, 16 insertions(+)

diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs
index e31df59f..5609a624 100644
--- a/helix-lsp/src/lib.rs
+++ b/helix-lsp/src/lib.rs
@@ -526,6 +526,7 @@ pub enum MethodCall {
     ApplyWorkspaceEdit(lsp::ApplyWorkspaceEditParams),
     WorkspaceFolders,
     WorkspaceConfiguration(lsp::ConfigurationParams),
+    RegisterCapability(lsp::RegistrationParams),
 }
 
 impl MethodCall {
@@ -545,6 +546,10 @@ impl MethodCall {
                 let params: lsp::ConfigurationParams = params.parse()?;
                 Self::WorkspaceConfiguration(params)
             }
+            lsp::request::RegisterCapability::METHOD => {
+                let params: lsp::RegistrationParams = params.parse()?;
+                Self::RegisterCapability(params)
+            }
             _ => {
                 return Err(Error::Unhandled);
             }
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index c7e93995..781e6fa7 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -1014,6 +1014,17 @@ impl Application {
                             .collect();
                         Ok(json!(result))
                     }
+                    Ok(MethodCall::RegisterCapability(_params)) => {
+                        log::warn!("Ignoring a client/registerCapability request because dynamic capability registration is not enabled. Please report this upstream to the language server");
+                        // Language Servers based on the `vscode-languageserver-node` library often send
+                        // client/registerCapability even though we do not enable dynamic registration
+                        // for any capabilities. We should send a MethodNotFound JSONRPC error in this
+                        // case but that rejects the registration promise in the server which causes an
+                        // exit. So we work around this by ignoring the request and sending back an OK
+                        // response.
+
+                        Ok(serde_json::Value::Null)
+                    }
                 };
 
                 let language_server = match self.editor.language_servers.get_by_id(server_id) {