diff options
Diffstat (limited to 'crates/ra_lsp_server/src')
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 28 |
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 | ||
4 | use std::{fmt::Write as _, io::Write as _}; | 4 | use std::{fmt::Write as _, io::Write as _}; |
5 | 5 | ||
6 | use either::Either; | ||
6 | use lsp_server::ErrorCode; | 7 | use lsp_server::ErrorCode; |
7 | use lsp_types::{ | 8 | use 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 { |