diff options
author | Kirill Bulatov <[email protected]> | 2020-01-11 22:40:36 +0000 |
---|---|---|
committer | Kirill Bulatov <[email protected]> | 2020-01-15 18:17:17 +0000 |
commit | 78a21253b494e573885ac8336bff6e93b401046f (patch) | |
tree | 3ec31f8481f9a930b0b3afb6cc0ce4c97cf648f2 /crates/ra_ide | |
parent | 73dc8b6f06b49f4728a50e83781c361e9a8b3100 (diff) |
Apply the api design suggestions
Diffstat (limited to 'crates/ra_ide')
-rw-r--r-- | crates/ra_ide/src/assists.rs | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/crates/ra_ide/src/assists.rs b/crates/ra_ide/src/assists.rs index db6e4e8b7..e30eee5f4 100644 --- a/crates/ra_ide/src/assists.rs +++ b/crates/ra_ide/src/assists.rs | |||
@@ -4,30 +4,37 @@ use ra_db::{FilePosition, FileRange}; | |||
4 | 4 | ||
5 | use crate::{db::RootDatabase, FileId, SourceChange, SourceFileEdit}; | 5 | use crate::{db::RootDatabase, FileId, SourceChange, SourceFileEdit}; |
6 | 6 | ||
7 | use itertools::Either; | ||
7 | pub use ra_assists::AssistId; | 8 | pub use ra_assists::AssistId; |
8 | use ra_assists::{AssistAction, AssistLabel}; | 9 | use ra_assists::{AssistAction, AssistLabel}; |
9 | 10 | ||
10 | #[derive(Debug)] | 11 | #[derive(Debug)] |
11 | pub struct Assist { | 12 | pub struct Assist { |
12 | pub id: AssistId, | 13 | pub id: AssistId, |
13 | pub change: SourceChange, | ||
14 | pub label: String, | 14 | pub label: String, |
15 | pub alternative_changes: Vec<SourceChange>, | 15 | pub change_data: Either<SourceChange, Vec<SourceChange>>, |
16 | } | 16 | } |
17 | 17 | ||
18 | pub(crate) fn assists(db: &RootDatabase, frange: FileRange) -> Vec<Assist> { | 18 | pub(crate) fn assists(db: &RootDatabase, frange: FileRange) -> Vec<Assist> { |
19 | ra_assists::assists(db, frange) | 19 | ra_assists::assists(db, frange) |
20 | .into_iter() | 20 | .into_iter() |
21 | .map(|(assist_label, action, alternative_actions)| { | 21 | .map(|assist| { |
22 | let file_id = frange.file_id; | 22 | let file_id = frange.file_id; |
23 | let assist_label = &assist.label; | ||
23 | Assist { | 24 | Assist { |
24 | id: assist_label.id, | 25 | id: assist_label.id, |
25 | label: assist_label.label.clone(), | 26 | label: assist_label.label.clone(), |
26 | change: action_to_edit(action, file_id, &assist_label), | 27 | change_data: match assist.action_data { |
27 | alternative_changes: alternative_actions | 28 | Either::Left(action) => { |
28 | .into_iter() | 29 | Either::Left(action_to_edit(action, file_id, assist_label)) |
29 | .map(|action| action_to_edit(action, file_id, &assist_label)) | 30 | } |
30 | .collect(), | 31 | Either::Right(actions) => Either::Right( |
32 | actions | ||
33 | .into_iter() | ||
34 | .map(|action| action_to_edit(action, file_id, assist_label)) | ||
35 | .collect(), | ||
36 | ), | ||
37 | }, | ||
31 | } | 38 | } |
32 | }) | 39 | }) |
33 | .collect() | 40 | .collect() |