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/main_loop') 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