diff options
Diffstat (limited to 'crates/ra_ide/src/assists.rs')
-rw-r--r-- | crates/ra_ide/src/assists.rs | 31 |
1 files changed, 10 insertions, 21 deletions
diff --git a/crates/ra_ide/src/assists.rs b/crates/ra_ide/src/assists.rs index a936900da..40d56a4f7 100644 --- a/crates/ra_ide/src/assists.rs +++ b/crates/ra_ide/src/assists.rs | |||
@@ -1,22 +1,23 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use ra_assists::{resolved_assists, AssistAction, AssistLabel}; | ||
3 | use ra_db::{FilePosition, FileRange}; | 4 | use ra_db::{FilePosition, FileRange}; |
5 | use ra_ide_db::RootDatabase; | ||
4 | 6 | ||
5 | use crate::{db::RootDatabase, FileId, SourceChange, SourceFileEdit}; | 7 | use crate::{FileId, SourceChange, SourceFileEdit}; |
6 | 8 | ||
7 | use either::Either; | ||
8 | pub use ra_assists::AssistId; | 9 | pub use ra_assists::AssistId; |
9 | use ra_assists::{AssistAction, AssistLabel}; | ||
10 | 10 | ||
11 | #[derive(Debug)] | 11 | #[derive(Debug)] |
12 | pub struct Assist { | 12 | pub struct Assist { |
13 | pub id: AssistId, | 13 | pub id: AssistId, |
14 | pub label: String, | 14 | pub label: String, |
15 | pub change_data: Either<SourceChange, Vec<SourceChange>>, | 15 | pub group_label: Option<String>, |
16 | pub source_change: SourceChange, | ||
16 | } | 17 | } |
17 | 18 | ||
18 | pub(crate) fn assists(db: &RootDatabase, frange: FileRange) -> Vec<Assist> { | 19 | pub(crate) fn assists(db: &RootDatabase, frange: FileRange) -> Vec<Assist> { |
19 | ra_assists::assists(db, frange) | 20 | resolved_assists(db, frange) |
20 | .into_iter() | 21 | .into_iter() |
21 | .map(|assist| { | 22 | .map(|assist| { |
22 | let file_id = frange.file_id; | 23 | let file_id = frange.file_id; |
@@ -24,17 +25,8 @@ pub(crate) fn assists(db: &RootDatabase, frange: FileRange) -> Vec<Assist> { | |||
24 | Assist { | 25 | Assist { |
25 | id: assist_label.id, | 26 | id: assist_label.id, |
26 | label: assist_label.label.clone(), | 27 | label: assist_label.label.clone(), |
27 | change_data: match assist.action_data { | 28 | group_label: assist.group_label.map(|it| it.0), |
28 | Either::Left(action) => { | 29 | source_change: action_to_edit(assist.action, file_id, assist_label), |
29 | Either::Left(action_to_edit(action, file_id, assist_label)) | ||
30 | } | ||
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 | }, | ||
38 | } | 30 | } |
39 | }) | 31 | }) |
40 | .collect() | 32 | .collect() |
@@ -46,9 +38,6 @@ fn action_to_edit( | |||
46 | assist_label: &AssistLabel, | 38 | assist_label: &AssistLabel, |
47 | ) -> SourceChange { | 39 | ) -> SourceChange { |
48 | let file_edit = SourceFileEdit { file_id, edit: action.edit }; | 40 | let file_edit = SourceFileEdit { file_id, edit: action.edit }; |
49 | SourceChange::source_file_edit( | 41 | SourceChange::source_file_edit(assist_label.label.clone(), file_edit) |
50 | action.label.unwrap_or_else(|| assist_label.label.clone()), | 42 | .with_cursor_opt(action.cursor_position.map(|offset| FilePosition { offset, file_id })) |
51 | file_edit, | ||
52 | ) | ||
53 | .with_cursor_opt(action.cursor_position.map(|offset| FilePosition { offset, file_id })) | ||
54 | } | 43 | } |