From 73dc8b6f06b49f4728a50e83781c361e9a8b3100 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Thu, 2 Jan 2020 01:39:01 +0200 Subject: Another attempt to add multiple edits --- crates/ra_lsp_server/src/main_loop/handlers.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'crates/ra_lsp_server/src') diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index f2db575ea..ec3c0a557 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -644,7 +644,6 @@ pub fn handle_code_action( let line_index = world.analysis().file_line_index(file_id)?; let range = params.range.conv_with(&line_index); - let assists = world.analysis().assists(FileRange { file_id, range })?.into_iter(); let diagnostics = world.analysis().diagnostics(file_id)?; let mut res = CodeActionResponse::default(); @@ -697,14 +696,19 @@ pub fn handle_code_action( res.push(action.into()); } - for assist in assists { - let title = assist.change.label.clone(); + for assist in world.analysis().assists(FileRange { file_id, range })?.into_iter() { + let title = assist.label.clone(); let edit = assist.change.try_conv_with(&world)?; + let alternative_edits = assist + .alternative_changes + .into_iter() + .map(|change| change.try_conv_with(&world)) + .collect::>>()?; let command = Command { title, command: "rust-analyzer.applySourceChange".to_string(), - arguments: Some(vec![to_value(edit).unwrap()]), + arguments: Some(vec![to_value(edit).unwrap(), to_value(alternative_edits).unwrap()]), }; let action = CodeAction { title: command.title.clone(), -- cgit v1.2.3 From 78a21253b494e573885ac8336bff6e93b401046f Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sun, 12 Jan 2020 00:40:36 +0200 Subject: Apply the api design suggestions --- crates/ra_lsp_server/src/main_loop/handlers.rs | 28 +++++++++++++++++--------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'crates/ra_lsp_server/src') diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index ec3c0a557..d76639474 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -3,6 +3,7 @@ use std::{fmt::Write as _, io::Write as _}; +use itertools::Either; use lsp_server::ErrorCode; use lsp_types::{ CallHierarchyIncomingCall, CallHierarchyIncomingCallsParams, CallHierarchyItem, @@ -698,18 +699,25 @@ pub fn handle_code_action( for assist in world.analysis().assists(FileRange { file_id, range })?.into_iter() { let title = assist.label.clone(); - let edit = assist.change.try_conv_with(&world)?; - let alternative_edits = assist - .alternative_changes - .into_iter() - .map(|change| change.try_conv_with(&world)) - .collect::>>()?; - let command = Command { - title, - command: "rust-analyzer.applySourceChange".to_string(), - arguments: Some(vec![to_value(edit).unwrap(), to_value(alternative_edits).unwrap()]), + let command = match assist.change_data { + Either::Left(change) => Command { + title, + command: "rust-analyzer.applySourceChange".to_string(), + arguments: Some(vec![to_value(change.try_conv_with(&world)?)?]), + }, + Either::Right(changes) => Command { + title, + command: "rust-analyzer.selectAndApplySourceChange".to_string(), + arguments: Some(vec![to_value( + changes + .into_iter() + .map(|change| change.try_conv_with(&world)) + .collect::>>()?, + )?]), + }, }; + let action = CodeAction { title: command.title.clone(), kind: match assist.id { -- cgit v1.2.3 From d51cf7794d110b064fd0e8d53726b4608ec50d1a Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Wed, 15 Jan 2020 20:20:20 +0200 Subject: itertools::Either -> either::Either --- crates/ra_lsp_server/src/main_loop/handlers.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'crates/ra_lsp_server/src') diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index d76639474..9e9964880 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -3,7 +3,7 @@ use std::{fmt::Write as _, io::Write as _}; -use itertools::Either; +use either::Either; use lsp_server::ErrorCode; use lsp_types::{ CallHierarchyIncomingCall, CallHierarchyIncomingCallsParams, CallHierarchyItem, -- cgit v1.2.3