@@ -23,7 +23,7 @@ use syntax::{
23
23
algo:: find_node_at_offset,
24
24
ast:: { self , edit:: IndentLevel , AstToken } ,
25
25
AstNode , Parse , SourceFile ,
26
- SyntaxKind :: { FIELD_EXPR , METHOD_CALL_EXPR } ,
26
+ SyntaxKind :: { self , FIELD_EXPR , METHOD_CALL_EXPR } ,
27
27
TextRange , TextSize ,
28
28
} ;
29
29
@@ -95,9 +95,16 @@ fn on_opening_brace_typed(file: &Parse<SourceFile>, offset: TextSize) -> Option<
95
95
}
96
96
97
97
let brace_token = file. tree ( ) . syntax ( ) . token_at_offset ( offset) . right_biased ( ) ?;
98
+ if brace_token. kind ( ) != SyntaxKind :: L_CURLY {
99
+ return None ;
100
+ }
98
101
99
- // Remove the `{` to get a better parse tree, and reparse
100
- let file = file. reparse ( & Indel :: delete ( brace_token. text_range ( ) ) ) ;
102
+ // Remove the `{` to get a better parse tree, and reparse.
103
+ let range = brace_token. text_range ( ) ;
104
+ if !stdx:: always!( range. len( ) == TextSize :: of( '{' ) ) {
105
+ return None ;
106
+ }
107
+ let file = file. reparse ( & Indel :: delete ( range) ) ;
101
108
102
109
if let Some ( edit) = brace_expr ( & file. tree ( ) , offset) {
103
110
return Some ( edit) ;
@@ -549,6 +556,29 @@ fn f() {
549
556
) ;
550
557
}
551
558
559
+ #[ test]
560
+ fn noop_in_string_literal ( ) {
561
+ // Regression test for #9351
562
+ type_char_noop (
563
+ '{' ,
564
+ r##"
565
+ fn check_with(ra_fixture: &str, expect: Expect) {
566
+ let base = r#"
567
+ enum E { T(), R$0, C }
568
+ use self::E::X;
569
+ const Z: E = E::C;
570
+ mod m {}
571
+ asdasdasdasdasdasda
572
+ sdasdasdasdasdasda
573
+ sdasdasdasdasd
574
+ "#;
575
+ let actual = completion_list(&format!("{}\n{}", base, ra_fixture));
576
+ expect.assert_eq(&actual)
577
+ }
578
+ "## ,
579
+ ) ;
580
+ }
581
+
552
582
#[ test]
553
583
fn adds_closing_brace_for_use_tree ( ) {
554
584
type_char (
0 commit comments