diff options
author | Aleksey Kladov <[email protected]> | 2018-08-29 16:03:14 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-29 16:03:14 +0100 |
commit | 8abf5363433e977c5393bb569e2a5d559cb0a602 (patch) | |
tree | 8bb7bc3097cb9e22af9e3be8605cb4745c2fae5f /crates/libeditor/src/code_actions.rs | |
parent | 2007ccfcfe0bf01c934589dd3c87fda83b06b272 (diff) |
Grand refactoring
Diffstat (limited to 'crates/libeditor/src/code_actions.rs')
-rw-r--r-- | crates/libeditor/src/code_actions.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/crates/libeditor/src/code_actions.rs b/crates/libeditor/src/code_actions.rs index 08a85f6e2..dadbd63ab 100644 --- a/crates/libeditor/src/code_actions.rs +++ b/crates/libeditor/src/code_actions.rs | |||
@@ -13,13 +13,14 @@ use libsyntax2::{ | |||
13 | 13 | ||
14 | use {EditBuilder, Edit, find_node_at_offset}; | 14 | use {EditBuilder, Edit, find_node_at_offset}; |
15 | 15 | ||
16 | // TODO: rename to FileEdit | ||
16 | #[derive(Debug)] | 17 | #[derive(Debug)] |
17 | pub struct ActionResult { | 18 | pub struct LocalEdit { |
18 | pub edit: Edit, | 19 | pub edit: Edit, |
19 | pub cursor_position: Option<TextUnit>, | 20 | pub cursor_position: Option<TextUnit>, |
20 | } | 21 | } |
21 | 22 | ||
22 | pub fn flip_comma<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() -> ActionResult + 'a> { | 23 | pub fn flip_comma<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() -> LocalEdit + 'a> { |
23 | let syntax = file.syntax(); | 24 | let syntax = file.syntax(); |
24 | 25 | ||
25 | let comma = find_leaf_at_offset(syntax, offset).find(|leaf| leaf.kind() == COMMA)?; | 26 | let comma = find_leaf_at_offset(syntax, offset).find(|leaf| leaf.kind() == COMMA)?; |
@@ -29,14 +30,14 @@ pub fn flip_comma<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() | |||
29 | let mut edit = EditBuilder::new(); | 30 | let mut edit = EditBuilder::new(); |
30 | edit.replace(left.range(), right.text().to_string()); | 31 | edit.replace(left.range(), right.text().to_string()); |
31 | edit.replace(right.range(), left.text().to_string()); | 32 | edit.replace(right.range(), left.text().to_string()); |
32 | ActionResult { | 33 | LocalEdit { |
33 | edit: edit.finish(), | 34 | edit: edit.finish(), |
34 | cursor_position: None, | 35 | cursor_position: None, |
35 | } | 36 | } |
36 | }) | 37 | }) |
37 | } | 38 | } |
38 | 39 | ||
39 | pub fn add_derive<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() -> ActionResult + 'a> { | 40 | pub fn add_derive<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() -> LocalEdit + 'a> { |
40 | let nominal = find_node_at_offset::<ast::NominalDef>(file.syntax(), offset)?; | 41 | let nominal = find_node_at_offset::<ast::NominalDef>(file.syntax(), offset)?; |
41 | Some(move || { | 42 | Some(move || { |
42 | let derive_attr = nominal | 43 | let derive_attr = nominal |
@@ -56,14 +57,14 @@ pub fn add_derive<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() | |||
56 | tt.syntax().range().end() - TextUnit::of_char(')') | 57 | tt.syntax().range().end() - TextUnit::of_char(')') |
57 | } | 58 | } |
58 | }; | 59 | }; |
59 | ActionResult { | 60 | LocalEdit { |
60 | edit: edit.finish(), | 61 | edit: edit.finish(), |
61 | cursor_position: Some(offset), | 62 | cursor_position: Some(offset), |
62 | } | 63 | } |
63 | }) | 64 | }) |
64 | } | 65 | } |
65 | 66 | ||
66 | pub fn add_impl<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() -> ActionResult + 'a> { | 67 | pub fn add_impl<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() -> LocalEdit + 'a> { |
67 | let nominal = find_node_at_offset::<ast::NominalDef>(file.syntax(), offset)?; | 68 | let nominal = find_node_at_offset::<ast::NominalDef>(file.syntax(), offset)?; |
68 | let name = nominal.name()?; | 69 | let name = nominal.name()?; |
69 | 70 | ||
@@ -90,7 +91,7 @@ pub fn add_impl<'a>(file: &'a File, offset: TextUnit) -> Option<impl FnOnce() -> | |||
90 | let offset = start_offset + TextUnit::of_str(&buf); | 91 | let offset = start_offset + TextUnit::of_str(&buf); |
91 | buf.push_str("\n}"); | 92 | buf.push_str("\n}"); |
92 | edit.insert(start_offset, buf); | 93 | edit.insert(start_offset, buf); |
93 | ActionResult { | 94 | LocalEdit { |
94 | edit: edit.finish(), | 95 | edit: edit.finish(), |
95 | cursor_position: Some(offset), | 96 | cursor_position: Some(offset), |
96 | } | 97 | } |