From 17a1011a12d270dfaf83a404dd7c40c5d9967064 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Wed, 7 Apr 2021 01:39:17 +0200 Subject: simplify --- crates/ide/src/typing.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'crates/ide') diff --git a/crates/ide/src/typing.rs b/crates/ide/src/typing.rs index c1bdc51b0..391a8e867 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())) -- cgit v1.2.3