From 4aa632761f1db5f18338c9bd568156c0259b9252 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 11 Jan 2019 14:57:19 +0300 Subject: make on dot typed actually work --- crates/ra_ide_api_light/src/formatting.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide_api_light/src/formatting.rs') diff --git a/crates/ra_ide_api_light/src/formatting.rs b/crates/ra_ide_api_light/src/formatting.rs index 1f3769209..4635fbd60 100644 --- a/crates/ra_ide_api_light/src/formatting.rs +++ b/crates/ra_ide_api_light/src/formatting.rs @@ -1,8 +1,16 @@ use ra_syntax::{ - ast, AstNode, + AstNode, SyntaxNode, SyntaxKind::*, + ast::{self, AstToken}, }; +/// If the node is on the begining of the line, calculate indent. +pub(crate) fn leading_indent(node: &SyntaxNode) -> Option<&str> { + let prev = node.prev_sibling()?; + let ws_text = ast::Whitespace::cast(prev)?.text(); + ws_text.rfind('\n').map(|pos| &ws_text[pos + 1..]) +} + pub(crate) fn extract_trivial_expression(block: &ast::Block) -> Option<&ast::Expr> { let expr = block.expr()?; if expr.syntax().text().contains('\n') { -- cgit v1.2.3