aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-22 10:58:34 +0100
committerAleksey Kladov <[email protected]>2018-08-22 10:58:34 +0100
commite8dfb92641f64b772204d7670c7286cb9b8b398b (patch)
treebb305d3003d01756fc8c282f008108d05da7decf
parent641659d5a8dcca0b8a1c36ff6d1c517a91296116 (diff)
Simplify
-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
-rw-r--r--crates/server/src/main_loop/handlers.rs9
4 files changed, 10 insertions, 18 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);
diff --git a/crates/server/src/main_loop/handlers.rs b/crates/server/src/main_loop/handlers.rs
index 16cc92464..9ff821a8b 100644
--- a/crates/server/src/main_loop/handlers.rs
+++ b/crates/server/src/main_loop/handlers.rs
@@ -6,7 +6,7 @@ use languageserver_types::{
6 SymbolInformation, Position, Location, 6 SymbolInformation, Position, Location,
7}; 7};
8use libanalysis::{Query}; 8use libanalysis::{Query};
9use libeditor::{self, CursorPosition}; 9use libeditor;
10use libsyntax2::TextUnit; 10use libsyntax2::TextUnit;
11use serde_json::{to_value, from_value}; 11use serde_json::{to_value, from_value};
12 12
@@ -230,11 +230,8 @@ pub fn handle_execute_command(
230 document_changes: None, 230 document_changes: None,
231 }; 231 };
232 let edit = req::ApplyWorkspaceEditParams { edit }; 232 let edit = req::ApplyWorkspaceEditParams { edit };
233 let cursor_pos = match action_result.cursor_position { 233 let cursor_pos = action_result.cursor_position
234 CursorPosition::Same => None, 234 .map(|off| off.conv_with(&line_index));
235 CursorPosition::Offset(offset) => Some(offset.conv_with(&line_index)),
236 };
237
238 Ok((edit, cursor_pos)) 235 Ok((edit, cursor_pos))
239} 236}
240 237