aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-01-15 18:43:23 +0000
committerGitHub <[email protected]>2020-01-15 18:43:23 +0000
commitaa2e13b37f4508168fb064a79d0190fa705d8a47 (patch)
tree15d4b618885813c2c9efadd2ea0d25a7173807c8 /crates/ra_lsp_server/src
parent01422cc31d1917aaef4b1f402eda05abfff1e75f (diff)
parent79b77403b65877e4d20bbbac6dd853a3beead445 (diff)
Merge #2716
2716: Allow assists with multiple selectable actions r=SomeoneToIgnore a=SomeoneToIgnore This PR prepares an infra for https://github.com/rust-analyzer/rust-analyzer/issues/2180 task by adding a possibility to specify multiple actions in one assist as multiple edit parameters to the `applySourceChange` command. When this is done, the command opens a selection dialog, allowing the user to pick the edit to be applied. I have no working example to test in this PR, but here's a demo of an auto import feature (a separate PR coming later for that one) using this functionality: ![out](https://user-images.githubusercontent.com/2690773/71633614-f8ea4d80-2c1d-11ea-9b15-0e13611a7aa4.gif) The PR is not that massive as it may seem: all the assist files' changes are very generic and similar. Co-authored-by: Kirill Bulatov <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server/src')
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs28
1 files changed, 20 insertions, 8 deletions
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index f2db575ea..9e9964880 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 @@
3 3
4use std::{fmt::Write as _, io::Write as _}; 4use std::{fmt::Write as _, io::Write as _};
5 5
6use either::Either;
6use lsp_server::ErrorCode; 7use lsp_server::ErrorCode;
7use lsp_types::{ 8use lsp_types::{
8 CallHierarchyIncomingCall, CallHierarchyIncomingCallsParams, CallHierarchyItem, 9 CallHierarchyIncomingCall, CallHierarchyIncomingCallsParams, CallHierarchyItem,
@@ -644,7 +645,6 @@ pub fn handle_code_action(
644 let line_index = world.analysis().file_line_index(file_id)?; 645 let line_index = world.analysis().file_line_index(file_id)?;
645 let range = params.range.conv_with(&line_index); 646 let range = params.range.conv_with(&line_index);
646 647
647 let assists = world.analysis().assists(FileRange { file_id, range })?.into_iter();
648 let diagnostics = world.analysis().diagnostics(file_id)?; 648 let diagnostics = world.analysis().diagnostics(file_id)?;
649 let mut res = CodeActionResponse::default(); 649 let mut res = CodeActionResponse::default();
650 650
@@ -697,15 +697,27 @@ pub fn handle_code_action(
697 res.push(action.into()); 697 res.push(action.into());
698 } 698 }
699 699
700 for assist in assists { 700 for assist in world.analysis().assists(FileRange { file_id, range })?.into_iter() {
701 let title = assist.change.label.clone(); 701 let title = assist.label.clone();
702 let edit = assist.change.try_conv_with(&world)?;
703 702
704 let command = Command { 703 let command = match assist.change_data {
705 title, 704 Either::Left(change) => Command {
706 command: "rust-analyzer.applySourceChange".to_string(), 705 title,
707 arguments: Some(vec![to_value(edit).unwrap()]), 706 command: "rust-analyzer.applySourceChange".to_string(),
707 arguments: Some(vec![to_value(change.try_conv_with(&world)?)?]),
708 },
709 Either::Right(changes) => Command {
710 title,
711 command: "rust-analyzer.selectAndApplySourceChange".to_string(),
712 arguments: Some(vec![to_value(
713 changes
714 .into_iter()
715 .map(|change| change.try_conv_with(&world))
716 .collect::<Result<Vec<_>>>()?,
717 )?]),
718 },
708 }; 719 };
720
709 let action = CodeAction { 721 let action = CodeAction {
710 title: command.title.clone(), 722 title: command.title.clone(),
711 kind: match assist.id { 723 kind: match assist.id {