From 9c9a0bd24fea2ff9b3f3f4619912bb3d15d5de3d Mon Sep 17 00:00:00 2001 From: Vitaly Slobodin Date: Wed, 24 Jul 2024 22:28:23 +0200 Subject: [PATCH] lsp: Check if "Goto Definition" supported before request (#15111) This is related to #15023 where we have the running Rubocop LSP that provides diagnostics and formatting capabilities. Rubocop LSP sends its capabilities back to Zed without support for "textDocument/definition" request, Zed actually does not check that and sends a request to Rubocop that results in the server error "Unsupported method: textDocument/definition". The fix here is related to https://github.com/zed-industries/zed/pull/14666 Release Notes: - N/A --- crates/editor/src/hover_links.rs | 1 + crates/project/src/lsp_command.rs | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/crates/editor/src/hover_links.rs b/crates/editor/src/hover_links.rs index b5c53831ce..910415f313 100644 --- a/crates/editor/src/hover_links.rs +++ b/crates/editor/src/hover_links.rs @@ -786,6 +786,7 @@ mod tests { let mut cx = EditorLspTestContext::new_rust( lsp::ServerCapabilities { hover_provider: Some(lsp::HoverProviderCapability::Simple(true)), + definition_provider: Some(lsp::OneOf::Left(true)), ..Default::default() }, cx, diff --git a/crates/project/src/lsp_command.rs b/crates/project/src/lsp_command.rs index 6d6f787507..593298f5d4 100644 --- a/crates/project/src/lsp_command.rs +++ b/crates/project/src/lsp_command.rs @@ -427,6 +427,13 @@ impl LspCommand for GetDefinition { type LspRequest = lsp::request::GotoDefinition; type ProtoRequest = proto::GetDefinition; + fn check_capabilities(&self, capabilities: AdapterServerCapabilities) -> bool { + capabilities + .server_capabilities + .definition_provider + .is_some() + } + fn to_lsp( &self, path: &Path,