Fix remote clients unable to query custom, lsp_ext, commands (#27775)

Closes https://github.com/zed-industries/zed/issues/20583
Closes https://github.com/zed-industries/zed/issues/27133

A preparation for rust-analyzer's LSP tasks fetching, ensures all remote
clients are able to query custom, lsp_ext, commands.

Release Notes:

- Fixed remote clients unable to query custom, lsp_ext, commands
This commit is contained in:
Kirill Bulatov 2025-03-31 19:13:09 +03:00 committed by GitHub
parent c8a9a74e6a
commit e1e8c1786e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 430 additions and 140 deletions

View file

@ -1,6 +1,8 @@
use anyhow::Context as _;
use gpui::{App, Context, Entity, Window};
use language::Language;
use project::lsp_store::lsp_ext_command::SwitchSourceHeaderResult;
use rpc::proto;
use url::Url;
use workspace::{OpenOptions, OpenVisible};
@ -27,34 +29,42 @@ pub fn switch_source_header(
return;
};
let Some((_, _, server_to_query, buffer)) =
find_specific_language_server_in_selection(editor, cx, is_c_language, CLANGD_SERVER_NAME)
else {
return;
};
let server_lookup =
find_specific_language_server_in_selection(editor, cx, is_c_language, CLANGD_SERVER_NAME);
let project = project.clone();
let buffer_snapshot = buffer.read(cx).snapshot();
let source_file = buffer_snapshot
.file()
.unwrap()
.file_name(cx)
.to_str()
.unwrap()
.to_owned();
let switch_source_header_task = project.update(cx, |project, cx| {
project.request_lsp(
buffer,
project::LanguageServerToQuery::Other(server_to_query),
project::lsp_store::lsp_ext_command::SwitchSourceHeader,
cx,
)
});
let upstream_client = project.read(cx).lsp_store().read(cx).upstream_client();
cx.spawn_in(window, async move |_editor, cx| {
let switch_source_header = switch_source_header_task
.await
.with_context(|| format!("Switch source/header LSP request for path \"{source_file}\" failed"))?;
let Some((_, _, server_to_query, buffer)) =
server_lookup.await
else {
return Ok(());
};
let source_file = buffer.update(cx, |buffer, _| {
buffer.file().map(|file| file.path()).map(|path| path.to_string_lossy().to_string()).unwrap_or_else(|| "Unknown".to_string())
})?;
let switch_source_header = if let Some((client, project_id)) = upstream_client {
let buffer_id = buffer.update(cx, |buffer, _| buffer.remote_id())?;
let request = proto::LspExtSwitchSourceHeader {
project_id,
buffer_id: buffer_id.to_proto(),
};
let response = client
.request(request)
.await
.context("lsp ext switch source header proto request")?;
SwitchSourceHeaderResult(response.target_file)
} else {
project.update(cx, |project, cx| {
project.request_lsp(
buffer,
project::LanguageServerToQuery::Other(server_to_query),
project::lsp_store::lsp_ext_command::SwitchSourceHeader,
cx,
)
})?.await.with_context(|| format!("Switch source/header LSP request for path \"{source_file}\" failed"))?
};
if switch_source_header.0.is_empty() {
log::info!("Clangd returned an empty string when requesting to switch source/header from \"{source_file}\"" );
return Ok(());
@ -87,10 +97,15 @@ pub fn switch_source_header(
}
pub fn apply_related_actions(editor: &Entity<Editor>, window: &mut Window, cx: &mut App) {
if editor.update(cx, |e, cx| {
find_specific_language_server_in_selection(e, cx, is_c_language, CLANGD_SERVER_NAME)
.is_some()
}) {
register_action(editor, window, switch_source_header);
if editor
.read(cx)
.buffer()
.read(cx)
.all_buffers()
.into_iter()
.filter_map(|buffer| buffer.read(cx).language())
.any(|language| is_c_language(language))
{
register_action(&editor, window, switch_source_header);
}
}