aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_fmt/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_fmt/src/lib.rs')
-rw-r--r--crates/ra_fmt/src/lib.rs28
1 files changed, 0 insertions, 28 deletions
diff --git a/crates/ra_fmt/src/lib.rs b/crates/ra_fmt/src/lib.rs
deleted file mode 100644
index b92477f9e..000000000
--- a/crates/ra_fmt/src/lib.rs
+++ /dev/null
@@ -1,28 +0,0 @@
1//! This crate provides some utilities for indenting rust code.
2
3use std::iter::successors;
4
5use syntax::{
6 ast::{self, AstToken},
7 SmolStr, SyntaxNode, SyntaxToken,
8};
9
10/// If the node is on the beginning of the line, calculate indent.
11pub fn leading_indent(node: &SyntaxNode) -> Option<SmolStr> {
12 for token in prev_tokens(node.first_token()?) {
13 if let Some(ws) = ast::Whitespace::cast(token.clone()) {
14 let ws_text = ws.text();
15 if let Some(pos) = ws_text.rfind('\n') {
16 return Some(ws_text[pos + 1..].into());
17 }
18 }
19 if token.text().contains('\n') {
20 break;
21 }
22 }
23 None
24}
25
26fn prev_tokens(token: SyntaxToken) -> impl Iterator<Item = SyntaxToken> {
27 successors(token.prev_token(), |token| token.prev_token())
28}