diff --git a/crates/ra_ide_api_light/src/formatting.rs b/crates/ra_ide_api_light/src/formatting.rs
index 4635fbd605..599e3cdcbe 100644
--- a/crates/ra_ide_api_light/src/formatting.rs
+++ b/crates/ra_ide_api_light/src/formatting.rs
@@ -2,15 +2,23 @@ use ra_syntax::{
AstNode,
SyntaxNode, SyntaxKind::*,
ast::{self, AstToken},
+ algo::generate,
};
/// 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 prev = prev_leaf(node)?;
let ws_text = ast::Whitespace::cast(prev)?.text();
ws_text.rfind('\n').map(|pos| &ws_text[pos + 1..])
}
+fn prev_leaf(node: &SyntaxNode) -> Option<&SyntaxNode> {
+ generate(node.ancestors().find_map(SyntaxNode::prev_sibling), |it| {
+ it.last_child()
+ })
+ .last()
+}
+
pub(crate) fn extract_trivial_expression(block: &ast::Block) -> Option<&ast::Expr> {
let expr = block.expr()?;
if expr.syntax().text().contains('\n') {
diff --git a/crates/ra_ide_api_light/src/typing.rs b/crates/ra_ide_api_light/src/typing.rs
index c8f3dfe448..5ff2b7c1f4 100644
--- a/crates/ra_ide_api_light/src/typing.rs
+++ b/crates/ra_ide_api_light/src/typing.rs
@@ -227,6 +227,38 @@ fn foo() {
)
}
+ #[test]
+ fn indents_new_chain_call_with_semi() {
+ type_dot(
+ r"
+ pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable