diff options
author | Aleksey Kladov <[email protected]> | 2019-02-08 11:49:43 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-02-08 11:49:43 +0000 |
commit | 12e3b4c70b5ef23b2fdfc197296d483680e125f9 (patch) | |
tree | 71baa0e0a62f9f6b61450501c5f821f67badf9e4 /crates/ra_ide_api_light/src/extend_selection.rs | |
parent | 5cb1d41a30d25cbe136402644bf5434dd667f1e5 (diff) |
reformat the world
Diffstat (limited to 'crates/ra_ide_api_light/src/extend_selection.rs')
-rw-r--r-- | crates/ra_ide_api_light/src/extend_selection.rs | 57 |
1 files changed, 11 insertions, 46 deletions
diff --git a/crates/ra_ide_api_light/src/extend_selection.rs b/crates/ra_ide_api_light/src/extend_selection.rs index f396dfe3f..28d62f290 100644 --- a/crates/ra_ide_api_light/src/extend_selection.rs +++ b/crates/ra_ide_api_light/src/extend_selection.rs | |||
@@ -43,11 +43,7 @@ pub fn extend_selection(root: &SyntaxNode, range: TextRange) -> Option<TextRange | |||
43 | let node = find_covering_node(root, range); | 43 | let node = find_covering_node(root, range); |
44 | 44 | ||
45 | // Using shallowest node with same range allows us to traverse siblings. | 45 | // Using shallowest node with same range allows us to traverse siblings. |
46 | let node = node | 46 | let node = node.ancestors().take_while(|n| n.range() == node.range()).last().unwrap(); |
47 | .ancestors() | ||
48 | .take_while(|n| n.range() == node.range()) | ||
49 | .last() | ||
50 | .unwrap(); | ||
51 | 47 | ||
52 | if range == node.range() { | 48 | if range == node.range() { |
53 | if string_kinds.contains(&node.kind()) { | 49 | if string_kinds.contains(&node.kind()) { |
@@ -145,10 +141,7 @@ fn extend_list_item(node: &SyntaxNode) -> Option<TextRange> { | |||
145 | } | 141 | } |
146 | 142 | ||
147 | if let Some(comma_node) = nearby_comma(node, Direction::Prev) { | 143 | if let Some(comma_node) = nearby_comma(node, Direction::Prev) { |
148 | return Some(TextRange::from_to( | 144 | return Some(TextRange::from_to(comma_node.range().start(), node.range().end())); |
149 | comma_node.range().start(), | ||
150 | node.range().end(), | ||
151 | )); | ||
152 | } | 145 | } |
153 | 146 | ||
154 | if let Some(comma_node) = nearby_comma(node, Direction::Next) { | 147 | if let Some(comma_node) = nearby_comma(node, Direction::Next) { |
@@ -160,10 +153,7 @@ fn extend_list_item(node: &SyntaxNode) -> Option<TextRange> { | |||
160 | .filter(|node| is_single_line_ws(node)) | 153 | .filter(|node| is_single_line_ws(node)) |
161 | .unwrap_or(comma_node); | 154 | .unwrap_or(comma_node); |
162 | 155 | ||
163 | return Some(TextRange::from_to( | 156 | return Some(TextRange::from_to(node.range().start(), final_node.range().end())); |
164 | node.range().start(), | ||
165 | final_node.range().end(), | ||
166 | )); | ||
167 | } | 157 | } |
168 | 158 | ||
169 | return None; | 159 | return None; |
@@ -217,36 +207,15 @@ mod tests { | |||
217 | #[test] | 207 | #[test] |
218 | fn test_extend_selection_list() { | 208 | fn test_extend_selection_list() { |
219 | do_check(r#"fn foo(<|>x: i32) {}"#, &["x", "x: i32"]); | 209 | do_check(r#"fn foo(<|>x: i32) {}"#, &["x", "x: i32"]); |
220 | do_check( | 210 | do_check(r#"fn foo(<|>x: i32, y: i32) {}"#, &["x", "x: i32", "x: i32, "]); |
221 | r#"fn foo(<|>x: i32, y: i32) {}"#, | 211 | do_check(r#"fn foo(<|>x: i32,y: i32) {}"#, &["x", "x: i32", "x: i32,"]); |
222 | &["x", "x: i32", "x: i32, "], | 212 | do_check(r#"fn foo(x: i32, <|>y: i32) {}"#, &["y", "y: i32", ", y: i32"]); |
223 | ); | 213 | do_check(r#"fn foo(x: i32, <|>y: i32, ) {}"#, &["y", "y: i32", ", y: i32"]); |
224 | do_check( | 214 | do_check(r#"fn foo(x: i32,<|>y: i32) {}"#, &["y", "y: i32", ",y: i32"]); |
225 | r#"fn foo(<|>x: i32,y: i32) {}"#, | ||
226 | &["x", "x: i32", "x: i32,"], | ||
227 | ); | ||
228 | do_check( | ||
229 | r#"fn foo(x: i32, <|>y: i32) {}"#, | ||
230 | &["y", "y: i32", ", y: i32"], | ||
231 | ); | ||
232 | do_check( | ||
233 | r#"fn foo(x: i32, <|>y: i32, ) {}"#, | ||
234 | &["y", "y: i32", ", y: i32"], | ||
235 | ); | ||
236 | do_check( | ||
237 | r#"fn foo(x: i32,<|>y: i32) {}"#, | ||
238 | &["y", "y: i32", ",y: i32"], | ||
239 | ); | ||
240 | 215 | ||
241 | do_check( | 216 | do_check(r#"const FOO: [usize; 2] = [ 22<|> , 33];"#, &["22", "22 , "]); |
242 | r#"const FOO: [usize; 2] = [ 22<|> , 33];"#, | ||
243 | &["22", "22 , "], | ||
244 | ); | ||
245 | do_check(r#"const FOO: [usize; 2] = [ 22 , 33<|>];"#, &["33", ", 33"]); | 217 | do_check(r#"const FOO: [usize; 2] = [ 22 , 33<|>];"#, &["33", ", 33"]); |
246 | do_check( | 218 | do_check(r#"const FOO: [usize; 2] = [ 22 , 33<|> ,];"#, &["33", ", 33"]); |
247 | r#"const FOO: [usize; 2] = [ 22 , 33<|> ,];"#, | ||
248 | &["33", ", 33"], | ||
249 | ); | ||
250 | 219 | ||
251 | do_check( | 220 | do_check( |
252 | r#" | 221 | r#" |
@@ -292,11 +261,7 @@ struct B { | |||
292 | <|> | 261 | <|> |
293 | } | 262 | } |
294 | "#, | 263 | "#, |
295 | &[ | 264 | &["\n \n", "{\n \n}", "/// bla\n/// bla\nstruct B {\n \n}"], |
296 | "\n \n", | ||
297 | "{\n \n}", | ||
298 | "/// bla\n/// bla\nstruct B {\n \n}", | ||
299 | ], | ||
300 | ) | 265 | ) |
301 | } | 266 | } |
302 | 267 | ||