Merge #4850
4850: Indent chain `.` even if there's more stuff afterwards r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
7c617000b8
@ -21,7 +21,9 @@
|
||||
use ra_syntax::{
|
||||
algo::find_node_at_offset,
|
||||
ast::{self, AstToken},
|
||||
AstNode, SourceFile, TextRange, TextSize,
|
||||
AstNode, SourceFile,
|
||||
SyntaxKind::{FIELD_EXPR, METHOD_CALL_EXPR},
|
||||
TextRange, TextSize,
|
||||
};
|
||||
|
||||
use ra_text_edit::TextEdit;
|
||||
@ -98,9 +100,12 @@ fn on_dot_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit> {
|
||||
};
|
||||
let current_indent_len = TextSize::of(current_indent);
|
||||
|
||||
let parent = whitespace.syntax().parent();
|
||||
// Make sure dot is a part of call chain
|
||||
let field_expr = ast::FieldExpr::cast(whitespace.syntax().parent())?;
|
||||
let prev_indent = leading_indent(field_expr.syntax())?;
|
||||
if !matches!(parent.kind(), FIELD_EXPR | METHOD_CALL_EXPR) {
|
||||
return None;
|
||||
}
|
||||
let prev_indent = leading_indent(&parent)?;
|
||||
let target_indent = format!(" {}", prev_indent);
|
||||
let target_indent_len = TextSize::of(&target_indent);
|
||||
if current_indent_len == target_indent_len {
|
||||
@ -143,11 +148,11 @@ fn do_type_char(char_typed: char, before: &str) -> Option<String> {
|
||||
})
|
||||
}
|
||||
|
||||
fn type_char(char_typed: char, before: &str, after: &str) {
|
||||
let actual = do_type_char(char_typed, before)
|
||||
fn type_char(char_typed: char, ra_fixture_before: &str, ra_fixture_after: &str) {
|
||||
let actual = do_type_char(char_typed, ra_fixture_before)
|
||||
.unwrap_or_else(|| panic!("typing `{}` did nothing", char_typed));
|
||||
|
||||
assert_eq_text!(after, &actual);
|
||||
assert_eq_text!(ra_fixture_after, &actual);
|
||||
}
|
||||
|
||||
fn type_char_noop(char_typed: char, before: &str) {
|
||||
@ -248,6 +253,27 @@ fn main() {
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn indents_new_chain_call_with_let() {
|
||||
type_char(
|
||||
'.',
|
||||
r#"
|
||||
fn main() {
|
||||
let _ = foo
|
||||
<|>
|
||||
bar()
|
||||
}
|
||||
"#,
|
||||
r#"
|
||||
fn main() {
|
||||
let _ = foo
|
||||
.
|
||||
bar()
|
||||
}
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn indents_continued_chain_call() {
|
||||
type_char(
|
||||
|
Loading…
Reference in New Issue
Block a user