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 <max@zed.dev>
This commit is contained in:
Marshall Bowers 2024-04-08 13:38:32 -04:00 committed by GitHub
parent f1428fea4e
commit 56c0345cf3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 3 deletions

View file

@ -4659,9 +4659,16 @@ async fn test_references(
let active_call_a = cx_a.read(ActiveCall::global); let active_call_a = cx_a.read(ActiveCall::global);
client_a.language_registry().add(rust_lang()); client_a.language_registry().add(rust_lang());
let mut fake_language_servers = client_a let mut fake_language_servers = client_a.language_registry().register_fake_lsp_adapter(
.language_registry() "Rust",
.register_fake_lsp_adapter("Rust", Default::default()); FakeLspAdapter {
capabilities: lsp::ServerCapabilities {
references_provider: Some(lsp::OneOf::Left(true)),
..Default::default()
},
..Default::default()
},
);
client_a client_a
.fs() .fs()

View file

@ -903,6 +903,14 @@ impl LspCommand for GetReferences {
return Some("Finding references...".to_owned()); 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( fn to_lsp(
&self, &self,
path: &Path, path: &Path,