aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-03-22 17:56:23 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-03-22 17:56:23 +0000
commit3604f23e98d01fe9d89e5cdcf76a51cb9c1d6768 (patch)
treede867640036faf167ff07a62d22db02c37f48088 /crates
parent6e324d38d6ef3e250ff32a397f4777699e006f7f (diff)
parent01bca7114c0567961c875a1df5a60748cd872073 (diff)
Merge #1012
1012: Move join_lines and test_utils to ra_ide_api r=matklad a=detrumi Part of #1009 Co-authored-by: Wilco Kusee <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide_api/Cargo.toml1
-rw-r--r--crates/ra_ide_api/src/join_lines.rs (renamed from crates/ra_ide_api_light/src/join_lines.rs)18
-rw-r--r--crates/ra_ide_api/src/lib.rs17
-rw-r--r--crates/ra_ide_api/src/test_utils.rs (renamed from crates/ra_ide_api_light/src/test_utils.rs)15
-rw-r--r--crates/ra_ide_api_light/src/lib.rs6
-rw-r--r--crates/ra_ide_api_light/src/typing.rs2
6 files changed, 26 insertions, 33 deletions
diff --git a/crates/ra_ide_api/Cargo.toml b/crates/ra_ide_api/Cargo.toml
index ac8c8057b..8bd5eec2b 100644
--- a/crates/ra_ide_api/Cargo.toml
+++ b/crates/ra_ide_api/Cargo.toml
@@ -23,6 +23,7 @@ ra_syntax = { path = "../ra_syntax" }
23ra_ide_api_light = { path = "../ra_ide_api_light" } 23ra_ide_api_light = { path = "../ra_ide_api_light" }
24ra_text_edit = { path = "../ra_text_edit" } 24ra_text_edit = { path = "../ra_text_edit" }
25ra_db = { path = "../ra_db" } 25ra_db = { path = "../ra_db" }
26ra_fmt = { path = "../ra_fmt" }
26hir = { path = "../ra_hir", package = "ra_hir" } 27hir = { path = "../ra_hir", package = "ra_hir" }
27test_utils = { path = "../test_utils" } 28test_utils = { path = "../test_utils" }
28ra_assists = { path = "../ra_assists" } 29ra_assists = { path = "../ra_assists" }
diff --git a/crates/ra_ide_api_light/src/join_lines.rs b/crates/ra_ide_api/src/join_lines.rs
index b5bcd62fb..8fb3eaa06 100644
--- a/crates/ra_ide_api_light/src/join_lines.rs
+++ b/crates/ra_ide_api/src/join_lines.rs
@@ -9,22 +9,14 @@ use ra_syntax::{
9use ra_fmt::{ 9use ra_fmt::{
10 compute_ws, extract_trivial_expression 10 compute_ws, extract_trivial_expression
11}; 11};
12use crate::{ 12use ra_text_edit::{TextEdit, TextEditBuilder};
13 LocalEdit, TextEditBuilder,
14};
15 13
16pub fn join_lines(file: &SourceFile, range: TextRange) -> LocalEdit { 14pub fn join_lines(file: &SourceFile, range: TextRange) -> TextEdit {
17 let range = if range.is_empty() { 15 let range = if range.is_empty() {
18 let syntax = file.syntax(); 16 let syntax = file.syntax();
19 let text = syntax.text().slice(range.start()..); 17 let text = syntax.text().slice(range.start()..);
20 let pos = match text.find('\n') { 18 let pos = match text.find('\n') {
21 None => { 19 None => return TextEditBuilder::default().finish(),
22 return LocalEdit {
23 label: "join lines".to_string(),
24 edit: TextEditBuilder::default().finish(),
25 cursor_position: None,
26 };
27 }
28 Some(pos) => pos, 20 Some(pos) => pos,
29 }; 21 };
30 TextRange::offset_len(range.start() + pos, TextUnit::of_char('\n')) 22 TextRange::offset_len(range.start() + pos, TextUnit::of_char('\n'))
@@ -52,7 +44,7 @@ pub fn join_lines(file: &SourceFile, range: TextRange) -> LocalEdit {
52 } 44 }
53 } 45 }
54 46
55 LocalEdit { label: "join lines".to_string(), edit: edit.finish(), cursor_position: None } 47 edit.finish()
56} 48}
57 49
58fn remove_newline( 50fn remove_newline(
@@ -514,7 +506,7 @@ fn foo() {
514 let (sel, before) = extract_range(before); 506 let (sel, before) = extract_range(before);
515 let file = SourceFile::parse(&before); 507 let file = SourceFile::parse(&before);
516 let result = join_lines(&file, sel); 508 let result = join_lines(&file, sel);
517 let actual = result.edit.apply(&before); 509 let actual = result.apply(&before);
518 assert_eq_text!(after, &actual); 510 assert_eq_text!(after, &actual);
519 } 511 }
520 512
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index d6f63490d..a838c30da 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -36,9 +36,12 @@ mod syntax_tree;
36mod line_index; 36mod line_index;
37mod folding_ranges; 37mod folding_ranges;
38mod line_index_utils; 38mod line_index_utils;
39mod join_lines;
39 40
40#[cfg(test)] 41#[cfg(test)]
41mod marks; 42mod marks;
43#[cfg(test)]
44mod test_utils;
42 45
43use std::sync::Arc; 46use std::sync::Arc;
44 47
@@ -276,10 +279,16 @@ impl Analysis {
276 /// stuff like trailing commas. 279 /// stuff like trailing commas.
277 pub fn join_lines(&self, frange: FileRange) -> SourceChange { 280 pub fn join_lines(&self, frange: FileRange) -> SourceChange {
278 let file = self.db.parse(frange.file_id); 281 let file = self.db.parse(frange.file_id);
279 SourceChange::from_local_edit( 282 let file_edit = SourceFileEdit {
280 frange.file_id, 283 file_id: frange.file_id,
281 ra_ide_api_light::join_lines(&file, frange.range), 284 edit: join_lines::join_lines(&file, frange.range),
282 ) 285 };
286 SourceChange {
287 label: "join lines".to_string(),
288 source_file_edits: vec![file_edit],
289 file_system_edits: vec![],
290 cursor_position: None,
291 }
283 } 292 }
284 293
285 /// Returns an edit which should be applied when opening a new line, fixing 294 /// Returns an edit which should be applied when opening a new line, fixing
diff --git a/crates/ra_ide_api_light/src/test_utils.rs b/crates/ra_ide_api/src/test_utils.rs
index bfac0fce3..d0bd3a1e4 100644
--- a/crates/ra_ide_api_light/src/test_utils.rs
+++ b/crates/ra_ide_api/src/test_utils.rs
@@ -1,9 +1,9 @@
1use ra_syntax::{SourceFile, TextUnit}; 1use ra_syntax::{SourceFile, TextUnit};
2use ra_text_edit::TextEdit;
2 3
3use crate::LocalEdit;
4pub use test_utils::*; 4pub use test_utils::*;
5 5
6pub fn check_action<F: Fn(&SourceFile, TextUnit) -> Option<LocalEdit>>( 6pub fn check_action<F: Fn(&SourceFile, TextUnit) -> Option<TextEdit>>(
7 before: &str, 7 before: &str,
8 after: &str, 8 after: &str,
9 f: F, 9 f: F,
@@ -11,14 +11,9 @@ pub fn check_action<F: Fn(&SourceFile, TextUnit) -> Option<LocalEdit>>(
11 let (before_cursor_pos, before) = extract_offset(before); 11 let (before_cursor_pos, before) = extract_offset(before);
12 let file = SourceFile::parse(&before); 12 let file = SourceFile::parse(&before);
13 let result = f(&file, before_cursor_pos).expect("code action is not applicable"); 13 let result = f(&file, before_cursor_pos).expect("code action is not applicable");
14 let actual = result.edit.apply(&before); 14 let actual = result.apply(&before);
15 let actual_cursor_pos = match result.cursor_position { 15 let actual_cursor_pos =
16 None => result 16 result.apply_to_offset(before_cursor_pos).expect("cursor position is affected by the edit");
17 .edit
18 .apply_to_offset(before_cursor_pos)
19 .expect("cursor position is affected by the edit"),
20 Some(off) => off,
21 };
22 let actual = add_cursor(&actual, actual_cursor_pos); 17 let actual = add_cursor(&actual, actual_cursor_pos);
23 assert_eq_text!(after, &actual); 18 assert_eq_text!(after, &actual);
24} 19}
diff --git a/crates/ra_ide_api_light/src/lib.rs b/crates/ra_ide_api_light/src/lib.rs
index 4036a598e..f21a91e18 100644
--- a/crates/ra_ide_api_light/src/lib.rs
+++ b/crates/ra_ide_api_light/src/lib.rs
@@ -4,9 +4,6 @@
4//! an edit or some auxiliary info. 4//! an edit or some auxiliary info.
5 5
6mod structure; 6mod structure;
7#[cfg(test)]
8mod test_utils;
9mod join_lines;
10mod typing; 7mod typing;
11 8
12use rustc_hash::FxHashSet; 9use rustc_hash::FxHashSet;
@@ -20,7 +17,6 @@ use ra_syntax::{
20 17
21pub use crate::{ 18pub use crate::{
22 structure::{file_structure, StructureNode}, 19 structure::{file_structure, StructureNode},
23 join_lines::join_lines,
24 typing::{on_enter, on_dot_typed, on_eq_typed}, 20 typing::{on_enter, on_dot_typed, on_eq_typed},
25}; 21};
26 22
@@ -118,7 +114,7 @@ mod tests {
118 use ra_syntax::AstNode; 114 use ra_syntax::AstNode;
119 use insta::assert_debug_snapshot_matches; 115 use insta::assert_debug_snapshot_matches;
120 116
121 use crate::test_utils::{add_cursor, assert_eq_text, extract_offset}; 117 use test_utils::{add_cursor, assert_eq_text, extract_offset};
122 118
123 use super::*; 119 use super::*;
124 120
diff --git a/crates/ra_ide_api_light/src/typing.rs b/crates/ra_ide_api_light/src/typing.rs
index 9dd9f1c1d..c69270333 100644
--- a/crates/ra_ide_api_light/src/typing.rs
+++ b/crates/ra_ide_api_light/src/typing.rs
@@ -118,7 +118,7 @@ pub fn on_dot_typed(file: &SourceFile, dot_offset: TextUnit) -> Option<LocalEdit
118 118
119#[cfg(test)] 119#[cfg(test)]
120mod tests { 120mod tests {
121 use crate::test_utils::{add_cursor, assert_eq_text, extract_offset}; 121 use test_utils::{add_cursor, assert_eq_text, extract_offset};
122 122
123 use super::*; 123 use super::*;
124 124