fix re-indent
This commit is contained in:
parent
e53eab3f25
commit
dbd28e4203
@ -7,9 +7,22 @@
|
||||
|
||||
/// If the node is on the beginning of the line, calculate indent.
|
||||
pub(crate) fn leading_indent(node: &SyntaxNode) -> Option<&str> {
|
||||
let prev = prev_leaf(node)?;
|
||||
let ws_text = ast::Whitespace::cast(prev)?.text();
|
||||
ws_text.rfind('\n').map(|pos| &ws_text[pos + 1..])
|
||||
for leaf in prev_leaves(node) {
|
||||
if let Some(ws) = ast::Whitespace::cast(leaf) {
|
||||
let ws_text = ws.text();
|
||||
if let Some(pos) = ws_text.rfind('\n') {
|
||||
return Some(&ws_text[pos + 1..]);
|
||||
}
|
||||
}
|
||||
if leaf.leaf_text().unwrap().contains('\n') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn prev_leaves(node: &SyntaxNode) -> impl Iterator<Item = &SyntaxNode> {
|
||||
generate(prev_leaf(node), |&node| prev_leaf(node))
|
||||
}
|
||||
|
||||
fn prev_leaf(node: &SyntaxNode) -> Option<&SyntaxNode> {
|
||||
|
@ -295,6 +295,46 @@ pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Mod
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn indents_middle_of_chain_call() {
|
||||
type_dot(
|
||||
r"
|
||||
fn source_impl() {
|
||||
let var = enum_defvariant_list().unwrap()
|
||||
<|>
|
||||
.nth(92)
|
||||
.unwrap();
|
||||
}
|
||||
",
|
||||
r"
|
||||
fn source_impl() {
|
||||
let var = enum_defvariant_list().unwrap()
|
||||
.
|
||||
.nth(92)
|
||||
.unwrap();
|
||||
}
|
||||
",
|
||||
);
|
||||
type_dot(
|
||||
r"
|
||||
fn source_impl() {
|
||||
let var = enum_defvariant_list().unwrap()
|
||||
<|>
|
||||
.nth(92)
|
||||
.unwrap();
|
||||
}
|
||||
",
|
||||
r"
|
||||
fn source_impl() {
|
||||
let var = enum_defvariant_list().unwrap()
|
||||
.
|
||||
.nth(92)
|
||||
.unwrap();
|
||||
}
|
||||
",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dont_indent_freestanding_dot() {
|
||||
type_dot(
|
||||
|
Loading…
Reference in New Issue
Block a user