From 56c0345cf30737d4d6db8adad9373c93fce338a0 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Mon, 8 Apr 2024 13:38:32 -0400 Subject: [PATCH] Respect language server's capabilities when calling `GetReferences` (#10285) This PR makes Zed respect the language server's capabilities when calling the `GetReferences` command (used in "Find All References", etc.). This fixes a crash that could occur when using Zed with Gleam v1.0. Release Notes: - Made "Find All References" respect the language server's capabilities. This fixes some instances where certain language servers would stop working after receiving a "Find All References" request. --------- Co-authored-by: Max --- crates/collab/src/tests/integration_tests.rs | 13 ++++++++++--- crates/project/src/lsp_command.rs | 8 ++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/crates/collab/src/tests/integration_tests.rs b/crates/collab/src/tests/integration_tests.rs index dbda880b1c64e911f84174c28d106613fd778656..3ae7e5fc58df17d837db7181d44221790b13ecdf 100644 --- a/crates/collab/src/tests/integration_tests.rs +++ b/crates/collab/src/tests/integration_tests.rs @@ -4659,9 +4659,16 @@ async fn test_references( let active_call_a = cx_a.read(ActiveCall::global); client_a.language_registry().add(rust_lang()); - let mut fake_language_servers = client_a - .language_registry() - .register_fake_lsp_adapter("Rust", Default::default()); + let mut fake_language_servers = client_a.language_registry().register_fake_lsp_adapter( + "Rust", + FakeLspAdapter { + capabilities: lsp::ServerCapabilities { + references_provider: Some(lsp::OneOf::Left(true)), + ..Default::default() + }, + ..Default::default() + }, + ); client_a .fs() diff --git a/crates/project/src/lsp_command.rs b/crates/project/src/lsp_command.rs index 38df25378a0d5d82039b6c733e26cc2d75d7aada..c1b1b20ebd919d318c3d243459c7f8fe2a197a3c 100644 --- a/crates/project/src/lsp_command.rs +++ b/crates/project/src/lsp_command.rs @@ -903,6 +903,14 @@ impl LspCommand for GetReferences { return Some("Finding references...".to_owned()); } + fn check_capabilities(&self, capabilities: &ServerCapabilities) -> bool { + match &capabilities.references_provider { + Some(OneOf::Left(has_support)) => *has_support, + Some(OneOf::Right(_)) => true, + None => false, + } + } + fn to_lsp( &self, path: &Path,