diff options
Diffstat (limited to 'crates/ra_ide_api_light')
-rw-r--r-- | crates/ra_ide_api_light/src/extend_selection.rs | 4 | ||||
-rw-r--r-- | crates/ra_ide_api_light/src/formatting.rs | 19 | ||||
-rw-r--r-- | crates/ra_ide_api_light/src/snapshots/tests__file_structure.snap | 26 | ||||
-rw-r--r-- | crates/ra_ide_api_light/src/structure.rs | 1 | ||||
-rw-r--r-- | crates/ra_ide_api_light/src/typing.rs | 40 |
5 files changed, 82 insertions, 8 deletions
diff --git a/crates/ra_ide_api_light/src/extend_selection.rs b/crates/ra_ide_api_light/src/extend_selection.rs index db93db208..f396dfe3f 100644 --- a/crates/ra_ide_api_light/src/extend_selection.rs +++ b/crates/ra_ide_api_light/src/extend_selection.rs | |||
@@ -9,9 +9,9 @@ pub fn extend_selection(root: &SyntaxNode, range: TextRange) -> Option<TextRange | |||
9 | let list_kinds = [ | 9 | let list_kinds = [ |
10 | FIELD_PAT_LIST, | 10 | FIELD_PAT_LIST, |
11 | MATCH_ARM_LIST, | 11 | MATCH_ARM_LIST, |
12 | NAMED_FIELD_LIST, | ||
13 | NAMED_FIELD_DEF_LIST, | 12 | NAMED_FIELD_DEF_LIST, |
14 | POS_FIELD_LIST, | 13 | POS_FIELD_DEF_LIST, |
14 | NAMED_FIELD_LIST, | ||
15 | ENUM_VARIANT_LIST, | 15 | ENUM_VARIANT_LIST, |
16 | USE_TREE_LIST, | 16 | USE_TREE_LIST, |
17 | TYPE_PARAM_LIST, | 17 | TYPE_PARAM_LIST, |
diff --git a/crates/ra_ide_api_light/src/formatting.rs b/crates/ra_ide_api_light/src/formatting.rs index ca0fdb928..1f34b85d6 100644 --- a/crates/ra_ide_api_light/src/formatting.rs +++ b/crates/ra_ide_api_light/src/formatting.rs | |||
@@ -7,9 +7,22 @@ use ra_syntax::{ | |||
7 | 7 | ||
8 | /// If the node is on the beginning of the line, calculate indent. | 8 | /// If the node is on the beginning of the line, calculate indent. |
9 | pub(crate) fn leading_indent(node: &SyntaxNode) -> Option<&str> { | 9 | pub(crate) fn leading_indent(node: &SyntaxNode) -> Option<&str> { |
10 | let prev = prev_leaf(node)?; | 10 | for leaf in prev_leaves(node) { |
11 | let ws_text = ast::Whitespace::cast(prev)?.text(); | 11 | if let Some(ws) = ast::Whitespace::cast(leaf) { |
12 | ws_text.rfind('\n').map(|pos| &ws_text[pos + 1..]) | 12 | let ws_text = ws.text(); |
13 | if let Some(pos) = ws_text.rfind('\n') { | ||
14 | return Some(&ws_text[pos + 1..]); | ||
15 | } | ||
16 | } | ||
17 | if leaf.leaf_text().unwrap().contains('\n') { | ||
18 | break; | ||
19 | } | ||
20 | } | ||
21 | None | ||
22 | } | ||
23 | |||
24 | fn prev_leaves(node: &SyntaxNode) -> impl Iterator<Item = &SyntaxNode> { | ||
25 | generate(prev_leaf(node), |&node| prev_leaf(node)) | ||
13 | } | 26 | } |
14 | 27 | ||
15 | fn prev_leaf(node: &SyntaxNode) -> Option<&SyntaxNode> { | 28 | fn prev_leaf(node: &SyntaxNode) -> Option<&SyntaxNode> { |
diff --git a/crates/ra_ide_api_light/src/snapshots/tests__file_structure.snap b/crates/ra_ide_api_light/src/snapshots/tests__file_structure.snap index b96398950..270f75a56 100644 --- a/crates/ra_ide_api_light/src/snapshots/tests__file_structure.snap +++ b/crates/ra_ide_api_light/src/snapshots/tests__file_structure.snap | |||
@@ -1,8 +1,8 @@ | |||
1 | --- | 1 | --- |
2 | created: "2019-01-24T18:04:00.090162+00:00" | 2 | created: "2019-01-26T07:11:02.463391362+00:00" |
3 | creator: insta@0.4.0 | 3 | creator: insta@0.5.2 |
4 | expression: structure | 4 | expression: structure |
5 | source: "crates\\ra_ide_api_light\\src\\structure.rs" | 5 | source: crates/ra_ide_api_light/src/structure.rs |
6 | --- | 6 | --- |
7 | [ | 7 | [ |
8 | StructureNode { | 8 | StructureNode { |
@@ -78,6 +78,26 @@ source: "crates\\ra_ide_api_light\\src\\structure.rs" | |||
78 | detail: None | 78 | detail: None |
79 | }, | 79 | }, |
80 | StructureNode { | 80 | StructureNode { |
81 | parent: Some( | ||
82 | 6 | ||
83 | ), | ||
84 | label: "X", | ||
85 | navigation_range: [169; 170), | ||
86 | node_range: [169; 170), | ||
87 | kind: ENUM_VARIANT, | ||
88 | detail: None | ||
89 | }, | ||
90 | StructureNode { | ||
91 | parent: Some( | ||
92 | 6 | ||
93 | ), | ||
94 | label: "Y", | ||
95 | navigation_range: [172; 173), | ||
96 | node_range: [172; 178), | ||
97 | kind: ENUM_VARIANT, | ||
98 | detail: None | ||
99 | }, | ||
100 | StructureNode { | ||
81 | parent: None, | 101 | parent: None, |
82 | label: "T", | 102 | label: "T", |
83 | navigation_range: [186; 187), | 103 | navigation_range: [186; 187), |
diff --git a/crates/ra_ide_api_light/src/structure.rs b/crates/ra_ide_api_light/src/structure.rs index e3713c217..4e080ed03 100644 --- a/crates/ra_ide_api_light/src/structure.rs +++ b/crates/ra_ide_api_light/src/structure.rs | |||
@@ -103,6 +103,7 @@ fn structure_node(node: &SyntaxNode) -> Option<StructureNode> { | |||
103 | .visit(decl::<ast::StructDef>) | 103 | .visit(decl::<ast::StructDef>) |
104 | .visit(|nfd: &ast::NamedFieldDef| decl_with_type_ref(nfd, nfd.type_ref())) | 104 | .visit(|nfd: &ast::NamedFieldDef| decl_with_type_ref(nfd, nfd.type_ref())) |
105 | .visit(decl::<ast::EnumDef>) | 105 | .visit(decl::<ast::EnumDef>) |
106 | .visit(decl::<ast::EnumVariant>) | ||
106 | .visit(decl::<ast::TraitDef>) | 107 | .visit(decl::<ast::TraitDef>) |
107 | .visit(decl::<ast::Module>) | 108 | .visit(decl::<ast::Module>) |
108 | .visit(|td: &ast::TypeDef| decl_with_type_ref(td, td.type_ref())) | 109 | .visit(|td: &ast::TypeDef| decl_with_type_ref(td, td.type_ref())) |
diff --git a/crates/ra_ide_api_light/src/typing.rs b/crates/ra_ide_api_light/src/typing.rs index 5ff2b7c1f..861027b9f 100644 --- a/crates/ra_ide_api_light/src/typing.rs +++ b/crates/ra_ide_api_light/src/typing.rs | |||
@@ -296,6 +296,46 @@ fn foo() { | |||
296 | } | 296 | } |
297 | 297 | ||
298 | #[test] | 298 | #[test] |
299 | fn indents_middle_of_chain_call() { | ||
300 | type_dot( | ||
301 | r" | ||
302 | fn source_impl() { | ||
303 | let var = enum_defvariant_list().unwrap() | ||
304 | <|> | ||
305 | .nth(92) | ||
306 | .unwrap(); | ||
307 | } | ||
308 | ", | ||
309 | r" | ||
310 | fn source_impl() { | ||
311 | let var = enum_defvariant_list().unwrap() | ||
312 | . | ||
313 | .nth(92) | ||
314 | .unwrap(); | ||
315 | } | ||
316 | ", | ||
317 | ); | ||
318 | type_dot( | ||
319 | r" | ||
320 | fn source_impl() { | ||
321 | let var = enum_defvariant_list().unwrap() | ||
322 | <|> | ||
323 | .nth(92) | ||
324 | .unwrap(); | ||
325 | } | ||
326 | ", | ||
327 | r" | ||
328 | fn source_impl() { | ||
329 | let var = enum_defvariant_list().unwrap() | ||
330 | . | ||
331 | .nth(92) | ||
332 | .unwrap(); | ||
333 | } | ||
334 | ", | ||
335 | ); | ||
336 | } | ||
337 | |||
338 | #[test] | ||
299 | fn dont_indent_freestanding_dot() { | 339 | fn dont_indent_freestanding_dot() { |
300 | type_dot( | 340 | type_dot( |
301 | r" | 341 | r" |