Always resolve code action if needed (#8904)
Follow-up of https://github.com/zed-industries/zed/pull/8874 and
https://github.com/zed-industries/zed/pull/7635
Closes https://github.com/zed-industries/zed/issues/7609
* mentions all `lsp::CodeActions` properties in the Zed client resolve
capabilities to remove more json out of general actions request
potentially
* removes odd `CodeActions.data` field checks, as that field is opaque
and is intended to store data, needed by the langserver to resolve this
code action
* if any `CodeAction` lacks either `command` or `edits` fields, tries to
resolve the action
This all effectively causes Zed to always fire an action resolve
request, since we update actions list (replacing the resolved actions
with the new, unresolved ones) via `refresh_code_actions`
9e66d48ccd/crates/editor/src/editor.rs (L3650)
that is being called on selections change and the actions menu open.
Yet, we do not query the resolve until the action is either applied
(selected in the list), or called for formatting, so it seems to be fine
to resolve them always, as it's not a frequent operation such as
reacting to every keystroke.
Release Notes:
- Fixed certain code actions not being resolved properly ([7609](https://github.com/zed-industries/zed/issues/7609))
---------
Co-authored-by: Derrick Laird <swampdonk@gmail.com>
This commit is contained in:
parent
addfcdea8d
commit
703c9655a0
4 changed files with 81 additions and 43 deletions
|
@ -40,11 +40,11 @@ use language::{
|
|||
deserialize_anchor, deserialize_fingerprint, deserialize_line_ending, deserialize_version,
|
||||
serialize_anchor, serialize_version, split_operations,
|
||||
},
|
||||
range_from_lsp, range_to_lsp, Bias, Buffer, BufferSnapshot, CachedLspAdapter, Capability,
|
||||
CodeAction, CodeLabel, Completion, Diagnostic, DiagnosticEntry, DiagnosticSet, Diff,
|
||||
Documentation, Event as BufferEvent, File as _, Language, LanguageRegistry, LanguageServerName,
|
||||
LocalFile, LspAdapterDelegate, OffsetRangeExt, Operation, Patch, PendingLanguageServer,
|
||||
PointUtf16, TextBufferSnapshot, ToOffset, ToPointUtf16, Transaction, Unclipped,
|
||||
range_from_lsp, Bias, Buffer, BufferSnapshot, CachedLspAdapter, Capability, CodeAction,
|
||||
CodeLabel, Completion, Diagnostic, DiagnosticEntry, DiagnosticSet, Diff, Documentation,
|
||||
Event as BufferEvent, File as _, Language, LanguageRegistry, LanguageServerName, LocalFile,
|
||||
LspAdapterDelegate, Operation, Patch, PendingLanguageServer, PointUtf16, TextBufferSnapshot,
|
||||
ToOffset, ToPointUtf16, Transaction, Unclipped,
|
||||
};
|
||||
use log::error;
|
||||
use lsp::{
|
||||
|
@ -4360,7 +4360,10 @@ impl Project {
|
|||
})?
|
||||
.await?;
|
||||
|
||||
for action in actions {
|
||||
for mut action in actions {
|
||||
Self::try_resolve_code_action(&language_server, &mut action)
|
||||
.await
|
||||
.context("resolving a formatting code action")?;
|
||||
if let Some(edit) = action.lsp_action.edit {
|
||||
if edit.changes.is_none() && edit.document_changes.is_none() {
|
||||
continue;
|
||||
|
@ -4380,6 +4383,7 @@ impl Project {
|
|||
project_transaction.0.extend(new.0);
|
||||
}
|
||||
|
||||
// TODO kb here too:
|
||||
if let Some(command) = action.lsp_action.command {
|
||||
project.update(&mut cx, |this, _| {
|
||||
this.last_workspace_edits_by_language_server
|
||||
|
@ -5422,33 +5426,10 @@ impl Project {
|
|||
} else {
|
||||
return Task::ready(Ok(Default::default()));
|
||||
};
|
||||
let range = action.range.to_point_utf16(buffer);
|
||||
|
||||
cx.spawn(move |this, mut cx| async move {
|
||||
if let Some(lsp_range) = action
|
||||
.lsp_action
|
||||
.data
|
||||
.as_mut()
|
||||
.and_then(|d| d.get_mut("codeActionParams"))
|
||||
.and_then(|d| d.get_mut("range"))
|
||||
{
|
||||
*lsp_range = serde_json::to_value(&range_to_lsp(range)).unwrap();
|
||||
action.lsp_action = lang_server
|
||||
.request::<lsp::request::CodeActionResolveRequest>(action.lsp_action)
|
||||
.await?;
|
||||
} else {
|
||||
let actions = this
|
||||
.update(&mut cx, |this, cx| {
|
||||
this.code_actions(&buffer_handle, action.range, cx)
|
||||
})?
|
||||
.await?;
|
||||
action.lsp_action = actions
|
||||
.into_iter()
|
||||
.find(|a| a.lsp_action.title == action.lsp_action.title)
|
||||
.ok_or_else(|| anyhow!("code action is outdated"))?
|
||||
.lsp_action;
|
||||
}
|
||||
|
||||
Self::try_resolve_code_action(&lang_server, &mut action)
|
||||
.await
|
||||
.context("resolving a code action")?;
|
||||
if let Some(edit) = action.lsp_action.edit {
|
||||
if edit.changes.is_some() || edit.document_changes.is_some() {
|
||||
return Self::deserialize_workspace_edit(
|
||||
|
@ -8322,6 +8303,23 @@ impl Project {
|
|||
})
|
||||
}
|
||||
|
||||
async fn try_resolve_code_action(
|
||||
lang_server: &LanguageServer,
|
||||
action: &mut CodeAction,
|
||||
) -> anyhow::Result<()> {
|
||||
if GetCodeActions::can_resolve_actions(&lang_server.capabilities()) {
|
||||
if action.lsp_action.data.is_some()
|
||||
&& (action.lsp_action.command.is_none() || action.lsp_action.edit.is_none())
|
||||
{
|
||||
action.lsp_action = lang_server
|
||||
.request::<lsp::request::CodeActionResolveRequest>(action.lsp_action.clone())
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
anyhow::Ok(())
|
||||
}
|
||||
|
||||
async fn handle_refresh_inlay_hints(
|
||||
this: Model<Self>,
|
||||
_: TypedEnvelope<proto::RefreshInlayHints>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue