diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-05-06 14:49:34 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-05-06 14:49:34 +0100 |
commit | efd8e34c396f1524623a495e47111f1047cf2879 (patch) | |
tree | 44ebb47b92d71a5e30cb469988ff1b490ca856d8 /crates/ra_ide/src | |
parent | 1116c9a0e9992d0dea8dac87de95c8a74c093cff (diff) | |
parent | fdd4df97ba5ce1f59abf9e945052fc6f3e077c3a (diff) |
Merge #4344
4344: Use SourceChange for assists r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide/src')
-rw-r--r-- | crates/ra_ide/src/assists.rs | 42 | ||||
-rw-r--r-- | crates/ra_ide/src/lib.rs | 31 |
2 files changed, 24 insertions, 49 deletions
diff --git a/crates/ra_ide/src/assists.rs b/crates/ra_ide/src/assists.rs deleted file mode 100644 index 389339a03..000000000 --- a/crates/ra_ide/src/assists.rs +++ /dev/null | |||
@@ -1,42 +0,0 @@ | |||
1 | //! FIXME: write short doc here | ||
2 | |||
3 | use ra_assists::{resolved_assists, AssistAction}; | ||
4 | use ra_db::{FilePosition, FileRange}; | ||
5 | use ra_ide_db::RootDatabase; | ||
6 | |||
7 | use crate::{FileId, SourceChange, SourceFileEdit}; | ||
8 | |||
9 | pub use ra_assists::AssistId; | ||
10 | |||
11 | #[derive(Debug)] | ||
12 | pub struct Assist { | ||
13 | pub id: AssistId, | ||
14 | pub label: String, | ||
15 | pub group_label: Option<String>, | ||
16 | pub source_change: SourceChange, | ||
17 | } | ||
18 | |||
19 | pub(crate) fn assists(db: &RootDatabase, frange: FileRange) -> Vec<Assist> { | ||
20 | resolved_assists(db, frange) | ||
21 | .into_iter() | ||
22 | .map(|assist| { | ||
23 | let file_id = frange.file_id; | ||
24 | Assist { | ||
25 | id: assist.label.id, | ||
26 | label: assist.label.label.clone(), | ||
27 | group_label: assist.label.group.map(|it| it.0), | ||
28 | source_change: action_to_edit(assist.action, file_id, assist.label.label.clone()), | ||
29 | } | ||
30 | }) | ||
31 | .collect() | ||
32 | } | ||
33 | |||
34 | fn action_to_edit(action: AssistAction, file_id: FileId, label: String) -> SourceChange { | ||
35 | let file_id = match action.file { | ||
36 | ra_assists::AssistFile::TargetFile(it) => it, | ||
37 | _ => file_id, | ||
38 | }; | ||
39 | let file_edit = SourceFileEdit { file_id, edit: action.edit }; | ||
40 | SourceChange::source_file_edit(label, file_edit) | ||
41 | .with_cursor_opt(action.cursor_position.map(|offset| FilePosition { offset, file_id })) | ||
42 | } | ||
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 4ed02f60e..614029de4 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs | |||
@@ -31,7 +31,6 @@ mod syntax_highlighting; | |||
31 | mod parent_module; | 31 | mod parent_module; |
32 | mod references; | 32 | mod references; |
33 | mod impls; | 33 | mod impls; |
34 | mod assists; | ||
35 | mod diagnostics; | 34 | mod diagnostics; |
36 | mod syntax_tree; | 35 | mod syntax_tree; |
37 | mod folding_ranges; | 36 | mod folding_ranges; |
@@ -64,7 +63,6 @@ use ra_syntax::{SourceFile, TextRange, TextSize}; | |||
64 | use crate::display::ToNav; | 63 | use crate::display::ToNav; |
65 | 64 | ||
66 | pub use crate::{ | 65 | pub use crate::{ |
67 | assists::{Assist, AssistId}, | ||
68 | call_hierarchy::CallItem, | 66 | call_hierarchy::CallItem, |
69 | completion::{ | 67 | completion::{ |
70 | CompletionConfig, CompletionItem, CompletionItemKind, CompletionScore, InsertTextFormat, | 68 | CompletionConfig, CompletionItem, CompletionItemKind, CompletionScore, InsertTextFormat, |
@@ -84,6 +82,7 @@ pub use crate::{ | |||
84 | }; | 82 | }; |
85 | 83 | ||
86 | pub use hir::Documentation; | 84 | pub use hir::Documentation; |
85 | pub use ra_assists::AssistId; | ||
87 | pub use ra_db::{ | 86 | pub use ra_db::{ |
88 | Canceled, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRootId, | 87 | Canceled, CrateGraph, CrateId, Edition, FileId, FilePosition, FileRange, SourceRootId, |
89 | }; | 88 | }; |
@@ -134,10 +133,12 @@ pub struct AnalysisHost { | |||
134 | db: RootDatabase, | 133 | db: RootDatabase, |
135 | } | 134 | } |
136 | 135 | ||
137 | impl Default for AnalysisHost { | 136 | #[derive(Debug)] |
138 | fn default() -> AnalysisHost { | 137 | pub struct Assist { |
139 | AnalysisHost::new(None) | 138 | pub id: AssistId, |
140 | } | 139 | pub label: String, |
140 | pub group_label: Option<String>, | ||
141 | pub source_change: SourceChange, | ||
141 | } | 142 | } |
142 | 143 | ||
143 | impl AnalysisHost { | 144 | impl AnalysisHost { |
@@ -187,6 +188,12 @@ impl AnalysisHost { | |||
187 | } | 188 | } |
188 | } | 189 | } |
189 | 190 | ||
191 | impl Default for AnalysisHost { | ||
192 | fn default() -> AnalysisHost { | ||
193 | AnalysisHost::new(None) | ||
194 | } | ||
195 | } | ||
196 | |||
190 | /// Analysis is a snapshot of a world state at a moment in time. It is the main | 197 | /// Analysis is a snapshot of a world state at a moment in time. It is the main |
191 | /// entry point for asking semantic information about the world. When the world | 198 | /// entry point for asking semantic information about the world. When the world |
192 | /// state is advanced using `AnalysisHost::apply_change` method, all existing | 199 | /// state is advanced using `AnalysisHost::apply_change` method, all existing |
@@ -464,7 +471,17 @@ impl Analysis { | |||
464 | /// Computes assists (aka code actions aka intentions) for the given | 471 | /// Computes assists (aka code actions aka intentions) for the given |
465 | /// position. | 472 | /// position. |
466 | pub fn assists(&self, frange: FileRange) -> Cancelable<Vec<Assist>> { | 473 | pub fn assists(&self, frange: FileRange) -> Cancelable<Vec<Assist>> { |
467 | self.with_db(|db| assists::assists(db, frange)) | 474 | self.with_db(|db| { |
475 | ra_assists::resolved_assists(db, frange) | ||
476 | .into_iter() | ||
477 | .map(|assist| Assist { | ||
478 | id: assist.label.id, | ||
479 | label: assist.label.label, | ||
480 | group_label: assist.label.group.map(|it| it.0), | ||
481 | source_change: assist.action, | ||
482 | }) | ||
483 | .collect() | ||
484 | }) | ||
468 | } | 485 | } |
469 | 486 | ||
470 | /// Computes the set of diagnostics for the given file. | 487 | /// Computes the set of diagnostics for the given file. |