aboutsummaryrefslogtreecommitdiff
path: root/crates/ide
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide')
-rw-r--r--crates/ide/src/typing.rs55
1 files changed, 35 insertions, 20 deletions
diff --git a/crates/ide/src/typing.rs b/crates/ide/src/typing.rs
index de65632e3..b0234d7fd 100644
--- a/crates/ide/src/typing.rs
+++ b/crates/ide/src/typing.rs
@@ -86,26 +86,13 @@ fn on_opening_brace_typed(file: &SourceFile, offset: TextSize) -> Option<TextEdi
86 // We expect a block expression enclosing exactly 1 preexisting expression. It can be parsed as 86 // We expect a block expression enclosing exactly 1 preexisting expression. It can be parsed as
87 // either the trailing expr or an ExprStmt. 87 // either the trailing expr or an ExprStmt.
88 let offset = { 88 let offset = {
89 match block.tail_expr() { 89 match block.statements().next() {
90 Some(expr) => { 90 Some(ast::Stmt::ExprStmt(it)) => {
91 if block.statements().next().is_some() { 91 // Use the expression span to place `}` before the `;`
92 return None; 92 it.expr()?.syntax().text_range().end()
93 } 93 },
94 expr.syntax().text_range().end() 94 None => block.tail_expr()?.syntax().text_range().end(),
95 } 95 _ => return None,
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 }
109 } 96 }
110 }; 97 };
111 98
@@ -417,5 +404,33 @@ fn main() {
417 type_char('{', r"fn f() { match () { _ => $0() } }", r"fn f() { match () { _ => {()} } }"); 404 type_char('{', r"fn f() { match () { _ => $0() } }", r"fn f() { match () { _ => {()} } }");
418 type_char('{', r"fn f() { $0(); }", r"fn f() { {()}; }"); 405 type_char('{', r"fn f() { $0(); }", r"fn f() { {()}; }");
419 type_char('{', r"fn f() { let x = $0(); }", r"fn f() { let x = {()}; }"); 406 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 );
420 } 435 }
421} 436}