Merge #653
653: fix re-indent r=matklad a=matklad Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
03fc615ead
2 changed files with 56 additions and 3 deletions
|
@ -7,9 +7,22 @@ use ra_syntax::{
|
||||||
|
|
||||||
/// If the node is on the beginning of the line, calculate indent.
|
/// If the node is on the beginning of the line, calculate indent.
|
||||||
pub(crate) fn leading_indent(node: &SyntaxNode) -> Option<&str> {
|
pub(crate) fn leading_indent(node: &SyntaxNode) -> Option<&str> {
|
||||||
let prev = prev_leaf(node)?;
|
for leaf in prev_leaves(node) {
|
||||||
let ws_text = ast::Whitespace::cast(prev)?.text();
|
if let Some(ws) = ast::Whitespace::cast(leaf) {
|
||||||
ws_text.rfind('\n').map(|pos| &ws_text[pos + 1..])
|
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> {
|
fn prev_leaf(node: &SyntaxNode) -> Option<&SyntaxNode> {
|
||||||
|
|
|
@ -295,6 +295,46 @@ fn foo() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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]
|
#[test]
|
||||||
fn dont_indent_freestanding_dot() {
|
fn dont_indent_freestanding_dot() {
|
||||||
type_dot(
|
type_dot(
|
||||||
|
|
Loading…
Add table
Reference in a new issue