about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--crates/rust-analyzer/src/lsp_ext.rs1
-rw-r--r--crates/rust-analyzer/src/main_loop/handlers.rs27
-rw-r--r--crates/rust-analyzer/src/to_proto.rs34
-rw-r--r--editors/code/src/client.ts2
-rw-r--r--editors/code/src/lsp_ext.ts1
5 files changed, 24 insertions, 41 deletions
diff --git a/crates/rust-analyzer/src/lsp_ext.rs b/crates/rust-analyzer/src/lsp_ext.rs
index 4b436c3013f..3b957534ddd 100644
--- a/crates/rust-analyzer/src/lsp_ext.rs
+++ b/crates/rust-analyzer/src/lsp_ext.rs
@@ -111,7 +111,6 @@ impl Request for ResolveCodeActionRequest {
 pub struct ResolveCodeActionParams {
     pub code_action_params: lsp_types::CodeActionParams,
     pub id: String,
-    pub label: String,
 }
 
 pub enum OnEnter {}
diff --git a/crates/rust-analyzer/src/main_loop/handlers.rs b/crates/rust-analyzer/src/main_loop/handlers.rs
index 3c40644414b..fab82ff7ead 100644
--- a/crates/rust-analyzer/src/main_loop/handlers.rs
+++ b/crates/rust-analyzer/src/main_loop/handlers.rs
@@ -756,9 +756,13 @@ pub fn handle_code_action(
     handle_fixes(&world, &params, &mut res)?;
 
     if world.config.client_caps.resolve_code_action {
-        for assist in world.analysis().unresolved_assists(&world.config.assist, frange)?.into_iter()
+        for (index, assist) in world
+            .analysis()
+            .unresolved_assists(&world.config.assist, frange)?
+            .into_iter()
+            .enumerate()
         {
-            res.push(to_proto::unresolved_code_action(&world, assist)?);
+            res.push(to_proto::unresolved_code_action(&world, assist, index)?);
         }
     } else {
         for assist in world.analysis().resolved_assists(&world.config.assist, frange)?.into_iter() {
@@ -773,24 +777,19 @@ pub fn handle_resolve_code_action(
     world: WorldSnapshot,
     params: lsp_ext::ResolveCodeActionParams,
 ) -> Result<Option<lsp_ext::SnippetWorkspaceEdit>> {
-    if !world.config.client_caps.resolve_code_action {
-        return Ok(None);
-    }
-
     let _p = profile("handle_resolve_code_action");
     let file_id = from_proto::file_id(&world, &params.code_action_params.text_document.uri)?;
     let line_index = world.analysis().file_line_index(file_id)?;
     let range = from_proto::text_range(&line_index, params.code_action_params.range);
     let frange = FileRange { file_id, range };
-    let mut res: Vec<lsp_ext::CodeAction> = Vec::new();
 
-    for assist in world.analysis().resolved_assists(&world.config.assist, frange)?.into_iter() {
-        res.push(to_proto::resolved_code_action(&world, assist)?);
-    }
-    Ok(res
-        .into_iter()
-        .find(|action| action.id.clone().unwrap() == params.id && action.title == params.label)
-        .and_then(|action| action.edit))
+    let assists = world.analysis().resolved_assists(&world.config.assist, frange)?;
+    let id_components = params.id.split(":").collect::<Vec<&str>>();
+    let index = id_components.last().unwrap().parse::<usize>().unwrap();
+    let id_string = id_components.first().unwrap();
+    let assist = &assists[index];
+    assert!(assist.assist.id.0 == *id_string);
+    Ok(to_proto::resolved_code_action(&world, assist.clone())?.edit)
 }
 
 pub fn handle_code_lens(
diff --git a/crates/rust-analyzer/src/to_proto.rs b/crates/rust-analyzer/src/to_proto.rs
index 3672b1a2602..fb33bdd5f69 100644
--- a/crates/rust-analyzer/src/to_proto.rs
+++ b/crates/rust-analyzer/src/to_proto.rs
@@ -622,17 +622,12 @@ fn main() <fold>{
 pub(crate) fn unresolved_code_action(
     world: &WorldSnapshot,
     assist: Assist,
+    index: usize,
 ) -> Result<lsp_ext::CodeAction> {
     let res = lsp_ext::CodeAction {
         title: assist.label,
-        id: Some(assist.id.0.to_owned()),
-        group: assist.group.and_then(|it| {
-            if world.config.client_caps.code_action_group {
-                None
-            } else {
-                Some(it.0)
-            }
-        }),
+        id: Some(format!("{}:{}", assist.id.0.to_owned(), index.to_string())),
+        group: assist.group.filter(|_| world.config.client_caps.code_action_group).map(|gr| gr.0),
         kind: Some(String::new()),
         edit: None,
         command: None,
@@ -644,21 +639,14 @@ pub(crate) fn resolved_code_action(
     world: &WorldSnapshot,
     assist: ResolvedAssist,
 ) -> Result<lsp_ext::CodeAction> {
-    let res = lsp_ext::CodeAction {
-        title: assist.assist.label,
-        id: Some(assist.assist.id.0.to_owned()),
-        group: assist.assist.group.and_then(|it| {
-            if world.config.client_caps.code_action_group {
-                None
-            } else {
-                Some(it.0)
-            }
-        }),
-        kind: Some(String::new()),
-        edit: Some(snippet_workspace_edit(world, assist.source_change)?),
-        command: None,
-    };
-    Ok(res)
+    let change = assist.source_change;
+    unresolved_code_action(world, assist.assist, 0).and_then(|it| {
+        Ok(lsp_ext::CodeAction {
+            id: None,
+            edit: Some(snippet_workspace_edit(world, change)?),
+            ..it
+        })
+    })
 }
 
 pub(crate) fn runnable(
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts
index a25091f797c..40ad1e3cd84 100644
--- a/editors/code/src/client.ts
+++ b/editors/code/src/client.ts
@@ -61,8 +61,6 @@ export function createClient(serverPath: string, cwd: string): lc.LanguageClient
                         const id = (item as any).id;
                         const resolveParams: ra.ResolveCodeActionParams = {
                             id: id,
-                            // TODO: delete after discussions if needed
-                            label: item.title,
                             codeActionParams: params
                         };
                         action.command = {
diff --git a/editors/code/src/lsp_ext.ts b/editors/code/src/lsp_ext.ts
index 35d73ce31da..9793b926c26 100644
--- a/editors/code/src/lsp_ext.ts
+++ b/editors/code/src/lsp_ext.ts
@@ -35,7 +35,6 @@ export const parentModule = new lc.RequestType<lc.TextDocumentPositionParams, lc
 
 export interface ResolveCodeActionParams {
     id: string;
-    label: string;
     codeActionParams: lc.CodeActionParams;
 }
 export const resolveCodeAction = new lc.RequestType<ResolveCodeActionParams, lc.WorkspaceEdit, unknown>('experimental/resolveCodeAction');