aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r--crates/ra_ide/src/assists.rs35
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
3use ra_db::{FilePosition, FileRange}; 3use ra_db::{FilePosition, FileRange};
4 4
5use crate::{db::RootDatabase, SourceChange, SourceFileEdit}; 5use crate::{db::RootDatabase, FileId, SourceChange, SourceFileEdit};
6 6
7pub use ra_assists::AssistId; 7pub use ra_assists::AssistId;
8use ra_assists::{AssistAction, AssistLabel};
8 9
9#[derive(Debug)] 10#[derive(Debug)]
10pub struct Assist { 11pub 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
15pub(crate) fn assists(db: &RootDatabase, frange: FileRange) -> Vec<Assist> { 18pub(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
36fn 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}