diff options
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r-- | crates/ra_ide/src/assists.rs | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/crates/ra_ide/src/assists.rs b/crates/ra_ide/src/assists.rs index e00589733..db6e4e8b7 100644 --- a/crates/ra_ide/src/assists.rs +++ b/crates/ra_ide/src/assists.rs | |||
@@ -2,27 +2,46 @@ | |||
2 | 2 | ||
3 | use ra_db::{FilePosition, FileRange}; | 3 | use ra_db::{FilePosition, FileRange}; |
4 | 4 | ||
5 | use crate::{db::RootDatabase, SourceChange, SourceFileEdit}; | 5 | use crate::{db::RootDatabase, FileId, SourceChange, SourceFileEdit}; |
6 | 6 | ||
7 | pub use ra_assists::AssistId; | 7 | pub use ra_assists::AssistId; |
8 | use ra_assists::{AssistAction, AssistLabel}; | ||
8 | 9 | ||
9 | #[derive(Debug)] | 10 | #[derive(Debug)] |
10 | pub struct Assist { | 11 | pub struct Assist { |
11 | pub id: AssistId, | 12 | pub id: AssistId, |
12 | pub change: SourceChange, | 13 | pub change: SourceChange, |
14 | pub label: String, | ||
15 | pub alternative_changes: Vec<SourceChange>, | ||
13 | } | 16 | } |
14 | 17 | ||
15 | pub(crate) fn assists(db: &RootDatabase, frange: FileRange) -> Vec<Assist> { | 18 | pub(crate) fn assists(db: &RootDatabase, frange: FileRange) -> Vec<Assist> { |
16 | ra_assists::assists(db, frange) | 19 | ra_assists::assists(db, frange) |
17 | .into_iter() | 20 | .into_iter() |
18 | .map(|(label, action)| { | 21 | .map(|(assist_label, action, alternative_actions)| { |
19 | let file_id = frange.file_id; | 22 | let file_id = frange.file_id; |
20 | let file_edit = SourceFileEdit { file_id, edit: action.edit }; | 23 | Assist { |
21 | let id = label.id; | 24 | id: assist_label.id, |
22 | let change = SourceChange::source_file_edit(label.label, file_edit).with_cursor_opt( | 25 | label: assist_label.label.clone(), |
23 | action.cursor_position.map(|offset| FilePosition { offset, file_id }), | 26 | change: action_to_edit(action, file_id, &assist_label), |
24 | ); | 27 | alternative_changes: alternative_actions |
25 | Assist { id, change } | 28 | .into_iter() |
29 | .map(|action| action_to_edit(action, file_id, &assist_label)) | ||
30 | .collect(), | ||
31 | } | ||
26 | }) | 32 | }) |
27 | .collect() | 33 | .collect() |
28 | } | 34 | } |
35 | |||
36 | fn action_to_edit( | ||
37 | action: AssistAction, | ||
38 | file_id: FileId, | ||
39 | assist_label: &AssistLabel, | ||
40 | ) -> SourceChange { | ||
41 | let file_edit = SourceFileEdit { file_id, edit: action.edit }; | ||
42 | SourceChange::source_file_edit( | ||
43 | action.label.unwrap_or_else(|| assist_label.label.clone()), | ||
44 | file_edit, | ||
45 | ) | ||
46 | .with_cursor_opt(action.cursor_position.map(|offset| FilePosition { offset, file_id })) | ||
47 | } | ||