Skip to content

Commit 61e292f

Browse files
Complete braces more aggressively
1 parent 36cd724 commit 61e292f

File tree

1 file changed

+35
-20
lines changed

1 file changed

+35
-20
lines changed

crates/ide/src/typing.rs

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,26 +86,13 @@ fn on_opening_brace_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdi
8686
// We expect a block expression enclosing exactly 1 preexisting expression. It can be parsed as
8787
// either the trailing expr or an ExprStmt.
8888
let offset = {
89-
match block.tail_expr() {
90-
Some(expr) => {
91-
if block.statements().next().is_some() {
92-
return None;
93-
}
94-
expr.syntax().text_range().end()
95-
}
96-
None => {
97-
if block.statements().count() != 1 {
98-
return None;
99-
}
100-
101-
match block.statements().next()? {
102-
ast::Stmt::ExprStmt(it) => {
103-
// Use the expression span to place `}` before the `;`
104-
it.expr()?.syntax().text_range().end()
105-
}
106-
_ => return None,
107-
}
108-
}
89+
match block.statements().next() {
90+
Some(ast::Stmt::ExprStmt(it)) => {
91+
// Use the expression span to place `}` before the `;`
92+
it.expr()?.syntax().text_range().end()
93+
},
94+
None => block.tail_expr()?.syntax().text_range().end(),
95+
_ => return None,
10996
}
11097
};
11198

@@ -417,5 +404,33 @@ fn main() {
417404
type_char('{', r"fn f() { match () { _ => $0() } }", r"fn f() { match () { _ => {()} } }");
418405
type_char('{', r"fn f() { $0(); }", r"fn f() { {()}; }");
419406
type_char('{', r"fn f() { let x = $0(); }", r"fn f() { let x = {()}; }");
407+
type_char(
408+
'{',
409+
r"
410+
const S: () = $0();
411+
fn f() {}
412+
",
413+
r"
414+
const S: () = {()};
415+
fn f() {}
416+
",
417+
);
418+
type_char(
419+
'{',
420+
r"
421+
fn f() {
422+
match x {
423+
0 => $0(),
424+
1 => (),
425+
}
426+
}",
427+
r"
428+
fn f() {
429+
match x {
430+
0 => {()},
431+
1 => (),
432+
}
433+
}",
434+
);
420435
}
421436
}

0 commit comments

Comments
 (0)