aboutsummaryrefslogtreecommitdiff
path: root/crates/libeditor
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libeditor')
-rw-r--r--crates/libeditor/src/code_actions.rs11
-rw-r--r--crates/libeditor/src/lib.rs2
-rw-r--r--crates/libeditor/tests/test.rs6
3 files changed, 7 insertions, 12 deletions
diff --git a/crates/libeditor/src/code_actions.rs b/crates/libeditor/src/code_actions.rs
index 80c396337..500d52c2a 100644
--- a/crates/libeditor/src/code_actions.rs
+++ b/crates/libeditor/src/code_actions.rs
@@ -11,12 +11,7 @@ use libsyntax2::{
11 11
12pub struct ActionResult { 12pub struct ActionResult {
13 pub edit: Edit, 13 pub edit: Edit,
14 pub cursor_position: CursorPosition, 14 pub cursor_position: Option<TextUnit>,
15}
16
17pub enum CursorPosition {
18 Same,
19 Offset(TextUnit),
20} 15}
21 16
22pub fn flip_comma<'a>(file: &'a ParsedFile, offset: TextUnit) -> Option<impl FnOnce() -> ActionResult + 'a> { 17pub fn flip_comma<'a>(file: &'a ParsedFile, offset: TextUnit) -> Option<impl FnOnce() -> ActionResult + 'a> {
@@ -31,7 +26,7 @@ pub fn flip_comma<'a>(file: &'a ParsedFile, offset: TextUnit) -> Option<impl FnO
31 edit.replace(right.range(), left.text()); 26 edit.replace(right.range(), left.text());
32 ActionResult { 27 ActionResult {
33 edit: edit.finish(), 28 edit: edit.finish(),
34 cursor_position: CursorPosition::Same, 29 cursor_position: None,
35 } 30 }
36 }) 31 })
37} 32}
@@ -58,7 +53,7 @@ pub fn add_derive<'a>(file: &'a ParsedFile, offset: TextUnit) -> Option<impl FnO
58 }; 53 };
59 ActionResult { 54 ActionResult {
60 edit: edit.finish(), 55 edit: edit.finish(),
61 cursor_position: CursorPosition::Offset(offset), 56 cursor_position: Some(offset),
62 } 57 }
63 }) 58 })
64} 59}
diff --git a/crates/libeditor/src/lib.rs b/crates/libeditor/src/lib.rs
index abd104af2..12d0a30dd 100644
--- a/crates/libeditor/src/lib.rs
+++ b/crates/libeditor/src/lib.rs
@@ -21,7 +21,7 @@ pub use self::{
21 symbols::{StructureNode, file_structure, FileSymbol, file_symbols}, 21 symbols::{StructureNode, file_structure, FileSymbol, file_symbols},
22 edit::{EditBuilder, Edit, AtomEdit}, 22 edit::{EditBuilder, Edit, AtomEdit},
23 code_actions::{ 23 code_actions::{
24 ActionResult, CursorPosition, find_node, 24 ActionResult, find_node,
25 flip_comma, add_derive, 25 flip_comma, add_derive,
26 }, 26 },
27}; 27};
diff --git a/crates/libeditor/tests/test.rs b/crates/libeditor/tests/test.rs
index f8365949e..4f4b4b773 100644
--- a/crates/libeditor/tests/test.rs
+++ b/crates/libeditor/tests/test.rs
@@ -5,7 +5,7 @@ extern crate assert_eq_text;
5 5
6use assert_eq_text::{assert_eq_dbg}; 6use assert_eq_text::{assert_eq_dbg};
7use libeditor::{ 7use libeditor::{
8 ParsedFile, TextUnit, TextRange, ActionResult, CursorPosition, 8 ParsedFile, TextUnit, TextRange, ActionResult,
9 highlight, runnables, extend_selection, file_structure, 9 highlight, runnables, extend_selection, file_structure,
10 flip_comma, add_derive, matching_brace, 10 flip_comma, add_derive, matching_brace,
11}; 11};
@@ -177,8 +177,8 @@ fn check_action<F: Fn(&ParsedFile, TextUnit) -> Option<ActionResult>>(
177 let result = f(&file, before_cursor_pos).expect("code action is not applicable"); 177 let result = f(&file, before_cursor_pos).expect("code action is not applicable");
178 let actual = result.edit.apply(&before); 178 let actual = result.edit.apply(&before);
179 let actual_cursor_pos = match result.cursor_position { 179 let actual_cursor_pos = match result.cursor_position {
180 CursorPosition::Same => result.edit.apply_to_offset(before_cursor_pos).unwrap(), 180 None => result.edit.apply_to_offset(before_cursor_pos).unwrap(),
181 CursorPosition::Offset(off) => off, 181 Some(off) => off,
182 }; 182 };
183 let actual = add_cursor(&actual, actual_cursor_pos); 183 let actual = add_cursor(&actual, actual_cursor_pos);
184 assert_eq_text!(after, &actual); 184 assert_eq_text!(after, &actual);