@@ -21,7 +21,9 @@ use ra_ide_db::{source_change::SourceFileEdit, RootDatabase};
21
21
use ra_syntax:: {
22
22
algo:: find_node_at_offset,
23
23
ast:: { self , AstToken } ,
24
- AstNode , SourceFile , TextRange , TextSize ,
24
+ AstNode , SourceFile ,
25
+ SyntaxKind :: { FIELD_EXPR , METHOD_CALL_EXPR } ,
26
+ TextRange , TextSize ,
25
27
} ;
26
28
27
29
use ra_text_edit:: TextEdit ;
@@ -98,9 +100,12 @@ fn on_dot_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit> {
98
100
} ;
99
101
let current_indent_len = TextSize :: of ( current_indent) ;
100
102
103
+ let parent = whitespace. syntax ( ) . parent ( ) ;
101
104
// Make sure dot is a part of call chain
102
- let field_expr = ast:: FieldExpr :: cast ( whitespace. syntax ( ) . parent ( ) ) ?;
103
- let prev_indent = leading_indent ( field_expr. syntax ( ) ) ?;
105
+ if !matches ! ( parent. kind( ) , FIELD_EXPR | METHOD_CALL_EXPR ) {
106
+ return None ;
107
+ }
108
+ let prev_indent = leading_indent ( & parent) ?;
104
109
let target_indent = format ! ( " {}" , prev_indent) ;
105
110
let target_indent_len = TextSize :: of ( & target_indent) ;
106
111
if current_indent_len == target_indent_len {
@@ -143,11 +148,11 @@ mod tests {
143
148
} )
144
149
}
145
150
146
- fn type_char ( char_typed : char , before : & str , after : & str ) {
147
- let actual = do_type_char ( char_typed, before )
151
+ fn type_char ( char_typed : char , ra_fixture_before : & str , ra_fixture_after : & str ) {
152
+ let actual = do_type_char ( char_typed, ra_fixture_before )
148
153
. unwrap_or_else ( || panic ! ( "typing `{}` did nothing" , char_typed) ) ;
149
154
150
- assert_eq_text ! ( after , & actual) ;
155
+ assert_eq_text ! ( ra_fixture_after , & actual) ;
151
156
}
152
157
153
158
fn type_char_noop ( char_typed : char , before : & str ) {
@@ -248,6 +253,27 @@ fn foo() {
248
253
)
249
254
}
250
255
256
+ #[ test]
257
+ fn indents_new_chain_call_with_let ( ) {
258
+ type_char (
259
+ '.' ,
260
+ r#"
261
+ fn main() {
262
+ let _ = foo
263
+ <|>
264
+ bar()
265
+ }
266
+ "# ,
267
+ r#"
268
+ fn main() {
269
+ let _ = foo
270
+ .
271
+ bar()
272
+ }
273
+ "# ,
274
+ ) ;
275
+ }
276
+
251
277
#[ test]
252
278
fn indents_continued_chain_call ( ) {
253
279
type_char (
0 commit comments