Skip to content

Commit 5341a6f

Browse files
committed
Auto merge of rust-lang#14103 - Veykril:typing-semi, r=Veykril
fix: Don't insert a semicolon when typing = if parse errors are encountered Fixes rust-lang/rust-analyzer#11005
2 parents 885c1ad + 5e6208b commit 5341a6f

File tree

1 file changed

+31
-20
lines changed

1 file changed

+31
-20
lines changed

crates/ide/src/typing.rs

+31-20
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,10 @@ fn on_eq_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdit> {
253253
if file.syntax().text().slice(offset..expr_range.start()).contains_char('\n') {
254254
return None;
255255
}
256+
// Good indicator that we will insert into a bad spot, so bail out.
257+
if expr.syntax().descendants().any(|it| it.kind() == SyntaxKind::ERROR) {
258+
return None;
259+
}
256260
let offset = let_stmt.syntax().text_range().end();
257261
Some(TextEdit::insert(offset, ";".to_string()))
258262
}
@@ -407,15 +411,14 @@ mod tests {
407411

408412
#[test]
409413
fn test_semi_after_let() {
410-
// do_check(r"
411-
// fn foo() {
412-
// let foo =$0
413-
// }
414-
// ", r"
415-
// fn foo() {
416-
// let foo =;
417-
// }
418-
// ");
414+
type_char_noop(
415+
'=',
416+
r"
417+
fn foo() {
418+
let foo =$0
419+
}
420+
",
421+
);
419422
type_char(
420423
'=',
421424
r#"
@@ -429,17 +432,25 @@ fn foo() {
429432
}
430433
"#,
431434
);
432-
// do_check(r"
433-
// fn foo() {
434-
// let foo =$0
435-
// let bar = 1;
436-
// }
437-
// ", r"
438-
// fn foo() {
439-
// let foo =;
440-
// let bar = 1;
441-
// }
442-
// ");
435+
type_char_noop(
436+
'=',
437+
r#"
438+
fn foo() {
439+
let difference $0(counts: &HashMap<(char, char), u64>, last: char) -> u64 {
440+
// ...
441+
}
442+
}
443+
"#,
444+
);
445+
type_char_noop(
446+
'=',
447+
r"
448+
fn foo() {
449+
let foo =$0
450+
let bar = 1;
451+
}
452+
",
453+
);
443454
}
444455

445456
#[test]

0 commit comments

Comments
 (0)