aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists/src/lib.rs')
-rw-r--r--crates/ra_assists/src/lib.rs25
1 files changed, 22 insertions, 3 deletions
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs
index a00136da1..ccc95735f 100644
--- a/crates/ra_assists/src/lib.rs
+++ b/crates/ra_assists/src/lib.rs
@@ -17,7 +17,7 @@ mod doc_tests;
17pub mod utils; 17pub mod utils;
18pub mod ast_transform; 18pub mod ast_transform;
19 19
20use ra_db::FileRange; 20use ra_db::{FileId, FileRange};
21use ra_ide_db::RootDatabase; 21use ra_ide_db::RootDatabase;
22use ra_syntax::{TextRange, TextUnit}; 22use ra_syntax::{TextRange, TextUnit};
23use ra_text_edit::TextEdit; 23use ra_text_edit::TextEdit;
@@ -54,6 +54,7 @@ pub struct AssistAction {
54 pub cursor_position: Option<TextUnit>, 54 pub cursor_position: Option<TextUnit>,
55 // FIXME: This belongs to `AssistLabel` 55 // FIXME: This belongs to `AssistLabel`
56 pub target: Option<TextRange>, 56 pub target: Option<TextRange>,
57 pub file: AssistFile,
57} 58}
58 59
59#[derive(Debug, Clone)] 60#[derive(Debug, Clone)]
@@ -63,6 +64,18 @@ pub struct ResolvedAssist {
63 pub action: AssistAction, 64 pub action: AssistAction,
64} 65}
65 66
67#[derive(Debug, Clone, Copy)]
68pub enum AssistFile {
69 CurrentFile,
70 TargetFile(FileId),
71}
72
73impl Default for AssistFile {
74 fn default() -> Self {
75 Self::CurrentFile
76 }
77}
78
66/// Return all the assists applicable at the given position. 79/// Return all the assists applicable at the given position.
67/// 80///
68/// Assists are returned in the "unresolved" state, that is only labels are 81/// Assists are returned in the "unresolved" state, that is only labels are
@@ -184,7 +197,7 @@ mod helpers {
184 use ra_ide_db::{symbol_index::SymbolsDatabase, RootDatabase}; 197 use ra_ide_db::{symbol_index::SymbolsDatabase, RootDatabase};
185 use test_utils::{add_cursor, assert_eq_text, extract_range_or_offset, RangeOrOffset}; 198 use test_utils::{add_cursor, assert_eq_text, extract_range_or_offset, RangeOrOffset};
186 199
187 use crate::{AssistCtx, AssistHandler}; 200 use crate::{AssistCtx, AssistFile, AssistHandler};
188 use hir::Semantics; 201 use hir::Semantics;
189 202
190 pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) { 203 pub(crate) fn with_single_file(text: &str) -> (RootDatabase, FileId) {
@@ -246,7 +259,13 @@ mod helpers {
246 (Some(assist), ExpectedResult::After(after)) => { 259 (Some(assist), ExpectedResult::After(after)) => {
247 let action = assist.0[0].action.clone().unwrap(); 260 let action = assist.0[0].action.clone().unwrap();
248 261
249 let mut actual = action.edit.apply(&text_without_caret); 262 let assisted_file_text = if let AssistFile::TargetFile(file_id) = action.file {
263 db.file_text(file_id).as_ref().to_owned()
264 } else {
265 text_without_caret
266 };
267
268 let mut actual = action.edit.apply(&assisted_file_text);
250 match action.cursor_position { 269 match action.cursor_position {
251 None => { 270 None => {
252 if let RangeOrOffset::Offset(before_cursor_pos) = range_or_offset { 271 if let RangeOrOffset::Offset(before_cursor_pos) = range_or_offset {