diff --git a/crates/ide/src/typing.rs b/crates/ide/src/typing.rs index c1bdc51b03..391a8e867f 100644 --- a/crates/ide/src/typing.rs +++ b/crates/ide/src/typing.rs @@ -85,15 +85,13 @@ fn on_opening_brace_typed(file: &SourceFile, offset: TextSize) -> Option { - // Use the expression span to place `}` before the `;` - it.expr()?.syntax().text_range().end() - } - None => block.tail_expr()?.syntax().text_range().end(), - _ => return None, + let offset = match block.statements().next() { + Some(ast::Stmt::ExprStmt(it)) => { + // Use the expression span to place `}` before the `;` + it.expr()?.syntax().text_range().end() } + None => block.tail_expr()?.syntax().text_range().end(), + _ => return None, }; Some(TextEdit::insert(offset, "}".to_string()))