diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-25 20:13:07 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-25 20:13:07 +0000 |
commit | 03fc615ead78ecf126632220104fa4de3414eb7f (patch) | |
tree | 4a392cb8184b2189c59e415666d569129e0d52d7 /crates/ra_ide_api_light/src/formatting.rs | |
parent | d65dca6bb3844d71ca14c396497783cbf9650e4a (diff) | |
parent | dbd28e4203cc268d8c1a80e8fa5dbfe6c042c061 (diff) |
Merge #653
653: fix re-indent r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide_api_light/src/formatting.rs')
-rw-r--r-- | crates/ra_ide_api_light/src/formatting.rs | 19 |
1 files changed, 16 insertions, 3 deletions
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> { |