diff options
author | Aleksey Kladov <[email protected]> | 2019-02-03 18:26:35 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-02-06 14:00:00 +0000 |
commit | 0c5fd8f7cbf04eda763e55bc9a38dad5f7ec917d (patch) | |
tree | 4af15c8906b85de01a15c717bc1fac388952cd3d /crates/ra_ide_api_light/src/formatting.rs | |
parent | 736a55c97e69f95e6ff4a0c3dafb2018e8ea05f9 (diff) |
move assists to a separate crate
Diffstat (limited to 'crates/ra_ide_api_light/src/formatting.rs')
-rw-r--r-- | crates/ra_ide_api_light/src/formatting.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/crates/ra_ide_api_light/src/formatting.rs b/crates/ra_ide_api_light/src/formatting.rs index 1f34b85d6..46ffa7d96 100644 --- a/crates/ra_ide_api_light/src/formatting.rs +++ b/crates/ra_ide_api_light/src/formatting.rs | |||
@@ -1,3 +1,4 @@ | |||
1 | use itertools::Itertools; | ||
1 | use ra_syntax::{ | 2 | use ra_syntax::{ |
2 | AstNode, | 3 | AstNode, |
3 | SyntaxNode, SyntaxKind::*, | 4 | SyntaxNode, SyntaxKind::*, |
@@ -5,8 +6,13 @@ use ra_syntax::{ | |||
5 | algo::generate, | 6 | algo::generate, |
6 | }; | 7 | }; |
7 | 8 | ||
9 | pub fn reindent(text: &str, indent: &str) -> String { | ||
10 | let indent = format!("\n{}", indent); | ||
11 | text.lines().intersperse(&indent).collect() | ||
12 | } | ||
13 | |||
8 | /// If the node is on the beginning of the line, calculate indent. | 14 | /// If the node is on the beginning of the line, calculate indent. |
9 | pub(crate) fn leading_indent(node: &SyntaxNode) -> Option<&str> { | 15 | pub fn leading_indent(node: &SyntaxNode) -> Option<&str> { |
10 | for leaf in prev_leaves(node) { | 16 | for leaf in prev_leaves(node) { |
11 | if let Some(ws) = ast::Whitespace::cast(leaf) { | 17 | if let Some(ws) = ast::Whitespace::cast(leaf) { |
12 | let ws_text = ws.text(); | 18 | let ws_text = ws.text(); |
@@ -32,7 +38,7 @@ fn prev_leaf(node: &SyntaxNode) -> Option<&SyntaxNode> { | |||
32 | .last() | 38 | .last() |
33 | } | 39 | } |
34 | 40 | ||
35 | pub(crate) fn extract_trivial_expression(block: &ast::Block) -> Option<&ast::Expr> { | 41 | pub fn extract_trivial_expression(block: &ast::Block) -> Option<&ast::Expr> { |
36 | let expr = block.expr()?; | 42 | let expr = block.expr()?; |
37 | if expr.syntax().text().contains('\n') { | 43 | if expr.syntax().text().contains('\n') { |
38 | return None; | 44 | return None; |