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:
parent
c8a9a74e6a
commit
e1e8c1786e
12 changed files with 430 additions and 140 deletions
|
@ -2,9 +2,13 @@ use std::{fs, path::Path};
|
|||
|
||||
use anyhow::Context as _;
|
||||
use gpui::{App, AppContext as _, Context, Entity, Window};
|
||||
use language::{Capability, Language};
|
||||
use language::{proto::serialize_anchor, Capability, Language};
|
||||
use multi_buffer::MultiBuffer;
|
||||
use project::lsp_store::{lsp_ext_command::ExpandMacro, rust_analyzer_ext::RUST_ANALYZER_NAME};
|
||||
use project::lsp_store::{
|
||||
lsp_ext_command::{DocsUrls, ExpandMacro, ExpandedMacro},
|
||||
rust_analyzer_ext::RUST_ANALYZER_NAME,
|
||||
};
|
||||
use rpc::proto;
|
||||
use text::ToPointUtf16;
|
||||
|
||||
use crate::{
|
||||
|
@ -18,13 +22,16 @@ fn is_rust_language(language: &Language) -> bool {
|
|||
|
||||
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_rust_language, RUST_ANALYZER_NAME)
|
||||
})
|
||||
.is_some()
|
||||
.read(cx)
|
||||
.buffer()
|
||||
.read(cx)
|
||||
.all_buffers()
|
||||
.into_iter()
|
||||
.filter_map(|buffer| buffer.read(cx).language())
|
||||
.any(|language| is_rust_language(language))
|
||||
{
|
||||
register_action(editor, window, expand_macro_recursively);
|
||||
register_action(editor, window, open_docs);
|
||||
register_action(&editor, window, expand_macro_recursively);
|
||||
register_action(&editor, window, open_docs);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,32 +51,57 @@ pub fn expand_macro_recursively(
|
|||
return;
|
||||
};
|
||||
|
||||
let Some((trigger_anchor, rust_language, server_to_query, buffer)) =
|
||||
find_specific_language_server_in_selection(
|
||||
editor,
|
||||
cx,
|
||||
is_rust_language,
|
||||
RUST_ANALYZER_NAME,
|
||||
)
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let server_lookup = find_specific_language_server_in_selection(
|
||||
editor,
|
||||
cx,
|
||||
is_rust_language,
|
||||
RUST_ANALYZER_NAME,
|
||||
);
|
||||
|
||||
let project = project.clone();
|
||||
let buffer_snapshot = buffer.read(cx).snapshot();
|
||||
let position = trigger_anchor.text_anchor.to_point_utf16(&buffer_snapshot);
|
||||
let expand_macro_task = project.update(cx, |project, cx| {
|
||||
project.request_lsp(
|
||||
buffer,
|
||||
project::LanguageServerToQuery::Other(server_to_query),
|
||||
ExpandMacro { position },
|
||||
cx,
|
||||
)
|
||||
});
|
||||
let upstream_client = project.read(cx).lsp_store().read(cx).upstream_client();
|
||||
cx.spawn_in(window, async move |_editor, cx| {
|
||||
let macro_expansion = expand_macro_task.await.context("expand macro")?;
|
||||
let Some((trigger_anchor, rust_language, server_to_query, buffer)) = server_lookup.await
|
||||
else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let macro_expansion = if let Some((client, project_id)) = upstream_client {
|
||||
let buffer_id = buffer.update(cx, |buffer, _| buffer.remote_id())?;
|
||||
let request = proto::LspExtExpandMacro {
|
||||
project_id,
|
||||
buffer_id: buffer_id.to_proto(),
|
||||
position: Some(serialize_anchor(&trigger_anchor.text_anchor)),
|
||||
};
|
||||
let response = client
|
||||
.request(request)
|
||||
.await
|
||||
.context("lsp ext expand macro proto request")?;
|
||||
ExpandedMacro {
|
||||
name: response.name,
|
||||
expansion: response.expansion,
|
||||
}
|
||||
} else {
|
||||
let buffer_snapshot = buffer.update(cx, |buffer, _| buffer.snapshot())?;
|
||||
let position = trigger_anchor.text_anchor.to_point_utf16(&buffer_snapshot);
|
||||
project
|
||||
.update(cx, |project, cx| {
|
||||
project.request_lsp(
|
||||
buffer,
|
||||
project::LanguageServerToQuery::Other(server_to_query),
|
||||
ExpandMacro { position },
|
||||
cx,
|
||||
)
|
||||
})?
|
||||
.await
|
||||
.context("expand macro")?
|
||||
};
|
||||
|
||||
if macro_expansion.is_empty() {
|
||||
log::info!("Empty macro expansion for position {position:?}");
|
||||
log::info!(
|
||||
"Empty macro expansion for position {:?}",
|
||||
trigger_anchor.text_anchor
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
@ -111,36 +143,57 @@ pub fn open_docs(editor: &mut Editor, _: &OpenDocs, window: &mut Window, cx: &mu
|
|||
return;
|
||||
};
|
||||
|
||||
let Some((trigger_anchor, _rust_language, server_to_query, buffer)) =
|
||||
find_specific_language_server_in_selection(
|
||||
editor,
|
||||
cx,
|
||||
is_rust_language,
|
||||
RUST_ANALYZER_NAME,
|
||||
)
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let server_lookup = find_specific_language_server_in_selection(
|
||||
editor,
|
||||
cx,
|
||||
is_rust_language,
|
||||
RUST_ANALYZER_NAME,
|
||||
);
|
||||
|
||||
let project = project.clone();
|
||||
let buffer_snapshot = buffer.read(cx).snapshot();
|
||||
let position = trigger_anchor.text_anchor.to_point_utf16(&buffer_snapshot);
|
||||
let open_docs_task = project.update(cx, |project, cx| {
|
||||
project.request_lsp(
|
||||
buffer,
|
||||
project::LanguageServerToQuery::Other(server_to_query),
|
||||
project::lsp_store::lsp_ext_command::OpenDocs { position },
|
||||
cx,
|
||||
)
|
||||
});
|
||||
|
||||
let upstream_client = project.read(cx).lsp_store().read(cx).upstream_client();
|
||||
cx.spawn_in(window, async move |_editor, cx| {
|
||||
let docs_urls = open_docs_task.await.context("open docs")?;
|
||||
if docs_urls.is_empty() {
|
||||
log::debug!("Empty docs urls for position {position:?}");
|
||||
let Some((trigger_anchor, _, server_to_query, buffer)) = server_lookup.await else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
let docs_urls = if let Some((client, project_id)) = upstream_client {
|
||||
let buffer_id = buffer.update(cx, |buffer, _| buffer.remote_id())?;
|
||||
let request = proto::LspExtOpenDocs {
|
||||
project_id,
|
||||
buffer_id: buffer_id.to_proto(),
|
||||
position: Some(serialize_anchor(&trigger_anchor.text_anchor)),
|
||||
};
|
||||
let response = client
|
||||
.request(request)
|
||||
.await
|
||||
.context("lsp ext open docs proto request")?;
|
||||
DocsUrls {
|
||||
web: response.web,
|
||||
local: response.local,
|
||||
}
|
||||
} else {
|
||||
log::debug!("{:?}", docs_urls);
|
||||
let buffer_snapshot = buffer.update(cx, |buffer, _| buffer.snapshot())?;
|
||||
let position = trigger_anchor.text_anchor.to_point_utf16(&buffer_snapshot);
|
||||
project
|
||||
.update(cx, |project, cx| {
|
||||
project.request_lsp(
|
||||
buffer,
|
||||
project::LanguageServerToQuery::Other(server_to_query),
|
||||
project::lsp_store::lsp_ext_command::OpenDocs { position },
|
||||
cx,
|
||||
)
|
||||
})?
|
||||
.await
|
||||
.context("open docs")?
|
||||
};
|
||||
|
||||
if docs_urls.is_empty() {
|
||||
log::debug!(
|
||||
"Empty docs urls for position {:?}",
|
||||
trigger_anchor.text_anchor
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
workspace.update(cx, |_workspace, cx| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue