Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 83 additions & 2 deletions crates/ide-completion/src/completions/postfix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use itertools::Itertools;
use stdx::never;
use syntax::{
SmolStr,
SyntaxKind::{EXPR_STMT, STMT_LIST},
SyntaxKind::{BLOCK_EXPR, EXPR_STMT, STMT_LIST},
T, TextRange, TextSize, ToSmolStr,
ast::{self, AstNode, AstToken},
format_smolstr, match_ast,
Expand Down Expand Up @@ -155,7 +155,7 @@ pub(crate) fn complete_postfix(
postfix_snippet("let", "let", &format!("let $1 = {receiver_text}"))
.add_to(acc, ctx.db);
}
_ if matches!(second_ancestor.kind(), STMT_LIST | EXPR_STMT) => {
_ if matches!(second_ancestor.kind(), STMT_LIST | EXPR_STMT | BLOCK_EXPR) => {
postfix_snippet("let", "let", &format!("let $0 = {receiver_text};"))
.add_to(acc, ctx.db);
postfix_snippet("letm", "let mut", &format!("let mut $0 = {receiver_text};"))
Expand Down Expand Up @@ -652,6 +652,87 @@ fn main() {
baz.l$0
res
}
"#,
expect![[r#"
sn box Box::new(expr)
sn call function(expr)
sn const const {}
sn dbg dbg!(expr)
sn dbgr dbg!(&expr)
sn deref *expr
sn if if expr {}
sn let let
sn letm let mut
sn match match expr {}
sn not !expr
sn ref &expr
sn refm &mut expr
sn return return expr
sn unsafe unsafe {}
sn while while expr {}
"#]],
);
check(
r#"
fn main() {
&baz.l$0
res
}
"#,
expect![[r#"
sn box Box::new(expr)
sn call function(expr)
sn const const {}
sn dbg dbg!(expr)
sn dbgr dbg!(&expr)
sn deref *expr
sn if if expr {}
sn let let
sn letm let mut
sn match match expr {}
sn not !expr
sn ref &expr
sn refm &mut expr
sn return return expr
sn unsafe unsafe {}
sn while while expr {}
"#]],
);
}

#[test]
fn let_tail_block() {
check(
r#"
fn main() {
baz.l$0
}
"#,
expect![[r#"
sn box Box::new(expr)
sn call function(expr)
sn const const {}
sn dbg dbg!(expr)
sn dbgr dbg!(&expr)
sn deref *expr
sn if if expr {}
sn let let
sn letm let mut
sn match match expr {}
sn not !expr
sn ref &expr
sn refm &mut expr
sn return return expr
sn unsafe unsafe {}
sn while while expr {}
"#]],
);

check(
r#"
fn main() {
&baz.l$0
}
"#,
expect![[r#"
sn box Box::new(expr)
Expand Down
2 changes: 2 additions & 0 deletions crates/ide-completion/src/tests/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3268,6 +3268,8 @@ fn foo() {
sn dbg dbg!(expr)
sn dbgr dbg!(&expr)
sn deref *expr
sn let let
sn letm let mut
sn match match expr {}
sn ref &expr
sn refm &mut expr
Expand Down