diff options
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r-- | crates/ra_lsp_server/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 28 |
2 files changed, 19 insertions, 10 deletions
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml index c08e67b8e..73bce8b08 100644 --- a/crates/ra_lsp_server/Cargo.toml +++ b/crates/ra_lsp_server/Cargo.toml | |||
@@ -28,6 +28,7 @@ ra_prof = { path = "../ra_prof" } | |||
28 | ra_vfs_glob = { path = "../ra_vfs_glob" } | 28 | ra_vfs_glob = { path = "../ra_vfs_glob" } |
29 | env_logger = { version = "0.7.1", default-features = false, features = ["humantime"] } | 29 | env_logger = { version = "0.7.1", default-features = false, features = ["humantime"] } |
30 | ra_cargo_watch = { path = "../ra_cargo_watch" } | 30 | ra_cargo_watch = { path = "../ra_cargo_watch" } |
31 | itertools = "0.8" | ||
31 | 32 | ||
32 | [dev-dependencies] | 33 | [dev-dependencies] |
33 | tempfile = "3" | 34 | tempfile = "3" |
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 @@ | |||
3 | 3 | ||
4 | use std::{fmt::Write as _, io::Write as _}; | 4 | use std::{fmt::Write as _, io::Write as _}; |
5 | 5 | ||
6 | use itertools::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, |
@@ -698,18 +699,25 @@ pub fn handle_code_action( | |||
698 | 699 | ||
699 | for assist in world.analysis().assists(FileRange { file_id, range })?.into_iter() { | 700 | for assist in world.analysis().assists(FileRange { file_id, range })?.into_iter() { |
700 | let title = assist.label.clone(); | 701 | let title = assist.label.clone(); |
701 | let edit = assist.change.try_conv_with(&world)?; | ||
702 | let alternative_edits = assist | ||
703 | .alternative_changes | ||
704 | .into_iter() | ||
705 | .map(|change| change.try_conv_with(&world)) | ||
706 | .collect::<Result<Vec<_>>>()?; | ||
707 | 702 | ||
708 | let command = Command { | 703 | let command = match assist.change_data { |
709 | title, | 704 | Either::Left(change) => Command { |
710 | command: "rust-analyzer.applySourceChange".to_string(), | 705 | title, |
711 | arguments: Some(vec![to_value(edit).unwrap(), to_value(alternative_edits).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 | }, | ||
712 | }; | 719 | }; |
720 | |||
713 | let action = CodeAction { | 721 | let action = CodeAction { |
714 | title: command.title.clone(), | 722 | title: command.title.clone(), |
715 | kind: match assist.id { | 723 | kind: match assist.id { |