Skip to content

Commit a18392b

Browse files
bors[bot]matklad
andauthored
Merge #6689
6689: Trigger .let postfix snippet in the middle of the block r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents eb7f969 + 21d962f commit a18392b

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

crates/completion/src/completions/postfix.rs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod format_like;
55
use ide_db::ty_filter::TryEnum;
66
use syntax::{
77
ast::{self, AstNode, AstToken},
8-
SyntaxKind::BLOCK_EXPR,
8+
SyntaxKind::{BLOCK_EXPR, EXPR_STMT},
99
TextRange, TextSize,
1010
};
1111
use text_edit::TextEdit;
@@ -221,9 +221,8 @@ pub(crate) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) {
221221
)
222222
.add_to(acc);
223223

224-
let parent_node = dot_receiver.syntax().parent().and_then(|p| p.parent());
225-
if let Some(parent) = parent_node {
226-
if parent.kind() == BLOCK_EXPR {
224+
if let Some(parent) = dot_receiver.syntax().parent().and_then(|p| p.parent()) {
225+
if matches!(parent.kind(), BLOCK_EXPR | EXPR_STMT) {
227226
postfix_snippet(
228227
ctx,
229228
cap,
@@ -389,6 +388,34 @@ fn main() {
389388
)
390389
}
391390

391+
#[test]
392+
fn let_middle_block() {
393+
check(
394+
r#"
395+
fn main() {
396+
baz.l<|>
397+
res
398+
}
399+
"#,
400+
expect![[r#"
401+
sn box Box::new(expr)
402+
sn call function(expr)
403+
sn dbg dbg!(expr)
404+
sn dbgr dbg!(&expr)
405+
sn if if expr {}
406+
sn let let
407+
sn letm let mut
408+
sn match match expr {}
409+
sn not !expr
410+
sn ok Ok(expr)
411+
sn ref &expr
412+
sn refm &mut expr
413+
sn some Some(expr)
414+
sn while while expr {}
415+
"#]],
416+
);
417+
}
418+
392419
#[test]
393420
fn option_iflet() {
394421
check_edit(

0 commit comments

Comments
 (0)