@@ -21,7 +21,9 @@ use ra_ide_db::{source_change::SourceFileEdit, RootDatabase};
2121use ra_syntax:: {
2222 algo:: find_node_at_offset,
2323 ast:: { self , AstToken } ,
24- AstNode , SourceFile , TextRange , TextSize ,
24+ AstNode , SourceFile ,
25+ SyntaxKind :: { FIELD_EXPR , METHOD_CALL_EXPR } ,
26+ TextRange , TextSize ,
2527} ;
2628
2729use ra_text_edit:: TextEdit ;
@@ -98,9 +100,12 @@ fn on_dot_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit> {
98100 } ;
99101 let current_indent_len = TextSize :: of ( current_indent) ;
100102
103+ let parent = whitespace. syntax ( ) . parent ( ) ;
101104 // 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) ?;
104109 let target_indent = format ! ( " {}" , prev_indent) ;
105110 let target_indent_len = TextSize :: of ( & target_indent) ;
106111 if current_indent_len == target_indent_len {
@@ -143,11 +148,11 @@ mod tests {
143148 } )
144149 }
145150
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 )
148153 . unwrap_or_else ( || panic ! ( "typing `{}` did nothing" , char_typed) ) ;
149154
150- assert_eq_text ! ( after , & actual) ;
155+ assert_eq_text ! ( ra_fixture_after , & actual) ;
151156 }
152157
153158 fn type_char_noop ( char_typed : char , before : & str ) {
@@ -248,6 +253,27 @@ fn foo() {
248253 )
249254 }
250255
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+
251277 #[ test]
252278 fn indents_continued_chain_call ( ) {
253279 type_char (
0 commit comments