aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-05-06 14:49:34 +0100
committerGitHub <[email protected]>2020-05-06 14:49:34 +0100
commitefd8e34c396f1524623a495e47111f1047cf2879 (patch)
tree44ebb47b92d71a5e30cb469988ff1b490ca856d8 /crates/ra_ide
parent1116c9a0e9992d0dea8dac87de95c8a74c093cff (diff)
parentfdd4df97ba5ce1f59abf9e945052fc6f3e077c3a (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')
-rw-r--r--crates/ra_ide/src/assists.rs42
-rw-r--r--crates/ra_ide/src/lib.rs31
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
3use ra_assists::{resolved_assists, AssistAction};
4use ra_db::{FilePosition, FileRange};
5use ra_ide_db::RootDatabase;
6
7use crate::{FileId, SourceChange, SourceFileEdit};
8
9pub use ra_assists::AssistId;
10
11#[derive(Debug)]
12pub struct Assist {
13 pub id: AssistId,
14 pub label: String,
15 pub group_label: Option<String>,
16 pub source_change: SourceChange,
17}
18
19pub(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
34fn 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;
31mod parent_module; 31mod parent_module;
32mod references; 32mod references;
33mod impls; 33mod impls;
34mod assists;
35mod diagnostics; 34mod diagnostics;
36mod syntax_tree; 35mod syntax_tree;
37mod folding_ranges; 36mod folding_ranges;
@@ -64,7 +63,6 @@ use ra_syntax::{SourceFile, TextRange, TextSize};
64use crate::display::ToNav; 63use crate::display::ToNav;
65 64
66pub use crate::{ 65pub 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
86pub use hir::Documentation; 84pub use hir::Documentation;
85pub use ra_assists::AssistId;
87pub use ra_db::{ 86pub 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
137impl Default for AnalysisHost { 136#[derive(Debug)]
138 fn default() -> AnalysisHost { 137pub 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
143impl AnalysisHost { 144impl AnalysisHost {
@@ -187,6 +188,12 @@ impl AnalysisHost {
187 } 188 }
188} 189}
189 190
191impl 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.