From a7f32650283bbde792f168a6a40f7da47b8a798e Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sun, 22 Dec 2024 12:08:27 +0100 Subject: [PATCH] fix: Don't trigger paren wrapping typing handler after idents --- crates/ide/src/typing.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/crates/ide/src/typing.rs b/crates/ide/src/typing.rs index 3d9146cc4c7f..d37318ff4570 100644 --- a/crates/ide/src/typing.rs +++ b/crates/ide/src/typing.rs @@ -174,6 +174,9 @@ fn on_delimited_node_typed( kinds: &[fn(SyntaxKind) -> bool], ) -> Option { let t = reparsed.syntax().token_at_offset(offset).right_biased()?; + if t.prev_token().map_or(false, |t| t.kind().is_any_identifier()) { + return None; + } let (filter, node) = t .parent_ancestors() .take_while(|n| n.text_range().start() == offset) @@ -1091,6 +1094,22 @@ fn f() { ); } + #[test] + fn preceding_whitespace_is_significant_for_closing_brackets() { + type_char_noop( + '(', + r#" +fn f() { a.b$0if true {} } +"#, + ); + type_char_noop( + '(', + r#" +fn f() { foo$0{} } +"#, + ); + } + #[test] fn adds_closing_parenthesis_for_pat() { type_char(