diff options
Diffstat (limited to 'crates/ra_editor/src/typing.rs')
-rw-r--r-- | crates/ra_editor/src/typing.rs | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/crates/ra_editor/src/typing.rs b/crates/ra_editor/src/typing.rs index 5e412bcfa..dcc8793af 100644 --- a/crates/ra_editor/src/typing.rs +++ b/crates/ra_editor/src/typing.rs | |||
@@ -8,7 +8,9 @@ use ra_syntax::{ | |||
8 | SyntaxKind::*, | 8 | SyntaxKind::*, |
9 | SyntaxNodeRef, TextRange, TextUnit, | 9 | SyntaxNodeRef, TextRange, TextUnit, |
10 | }; | 10 | }; |
11 | use ra_text_edit::text_utils::contains_offset_nonstrict; | 11 | use ra_text_edit::text_utils::{ |
12 | contains_offset_nonstrict | ||
13 | }; | ||
12 | 14 | ||
13 | use crate::{find_node_at_offset, TextEditBuilder, LocalEdit}; | 15 | use crate::{find_node_at_offset, TextEditBuilder, LocalEdit}; |
14 | 16 | ||
@@ -19,6 +21,7 @@ pub fn join_lines(file: &SourceFileNode, range: TextRange) -> LocalEdit { | |||
19 | let pos = match text.find('\n') { | 21 | let pos = match text.find('\n') { |
20 | None => { | 22 | None => { |
21 | return LocalEdit { | 23 | return LocalEdit { |
24 | label: "join lines".to_string(), | ||
22 | edit: TextEditBuilder::new().finish(), | 25 | edit: TextEditBuilder::new().finish(), |
23 | cursor_position: None, | 26 | cursor_position: None, |
24 | }; | 27 | }; |
@@ -51,6 +54,7 @@ pub fn join_lines(file: &SourceFileNode, range: TextRange) -> LocalEdit { | |||
51 | } | 54 | } |
52 | 55 | ||
53 | LocalEdit { | 56 | LocalEdit { |
57 | label: "join lines".to_string(), | ||
54 | edit: edit.finish(), | 58 | edit: edit.finish(), |
55 | cursor_position: None, | 59 | cursor_position: None, |
56 | } | 60 | } |
@@ -76,6 +80,7 @@ pub fn on_enter(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit> { | |||
76 | let mut edit = TextEditBuilder::new(); | 80 | let mut edit = TextEditBuilder::new(); |
77 | edit.insert(offset, inserted); | 81 | edit.insert(offset, inserted); |
78 | Some(LocalEdit { | 82 | Some(LocalEdit { |
83 | label: "on enter".to_string(), | ||
79 | edit: edit.finish(), | 84 | edit: edit.finish(), |
80 | cursor_position: Some(cursor_position), | 85 | cursor_position: Some(cursor_position), |
81 | }) | 86 | }) |
@@ -126,6 +131,7 @@ pub fn on_eq_typed(file: &SourceFileNode, offset: TextUnit) -> Option<LocalEdit> | |||
126 | let mut edit = TextEditBuilder::new(); | 131 | let mut edit = TextEditBuilder::new(); |
127 | edit.insert(offset, ";".to_string()); | 132 | edit.insert(offset, ";".to_string()); |
128 | Some(LocalEdit { | 133 | Some(LocalEdit { |
134 | label: "add semicolon".to_string(), | ||
129 | edit: edit.finish(), | 135 | edit: edit.finish(), |
130 | cursor_position: None, | 136 | cursor_position: None, |
131 | }) | 137 | }) |
@@ -248,24 +254,13 @@ fn join_single_use_tree(edit: &mut TextEditBuilder, node: SyntaxNodeRef) -> Opti | |||
248 | Some(()) | 254 | Some(()) |
249 | } | 255 | } |
250 | 256 | ||
251 | fn single_use_tree(tree_list: ast::UseTreeList) -> Option<ast::UseTree> { | 257 | pub(crate) fn single_use_tree(tree_list: ast::UseTreeList) -> Option<ast::UseTree> { |
252 | let mut res = None; | 258 | let sub_use_trees = tree_list.use_trees().count(); |
253 | for child in tree_list.syntax().children() { | 259 | if sub_use_trees != 1 { |
254 | if let Some(tree) = ast::UseTree::cast(child) { | 260 | return None; |
255 | if tree.syntax().text().contains('\n') { | ||
256 | return None; | ||
257 | } | ||
258 | if mem::replace(&mut res, Some(tree)).is_some() { | ||
259 | return None; | ||
260 | } | ||
261 | } else { | ||
262 | match child.kind() { | ||
263 | WHITESPACE | L_CURLY | R_CURLY | COMMA => (), | ||
264 | _ => return None, | ||
265 | } | ||
266 | } | ||
267 | } | 261 | } |
268 | res | 262 | |
263 | tree_list.use_trees().next() | ||
269 | } | 264 | } |
270 | 265 | ||
271 | fn compute_ws(left: SyntaxNodeRef, right: SyntaxNodeRef) -> &'static str { | 266 | fn compute_ws(left: SyntaxNodeRef, right: SyntaxNodeRef) -> &'static str { |