Skip to content

Commit 1433910

Browse files
Merge pull request #21526 from A4-Tacks/comp-not-in-cond
fix: Fix not complete `.not` in condition
2 parents a84d92f + 48ab21e commit 1433910

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

crates/ide-completion/src/completions/postfix.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ pub(crate) fn complete_postfix(
257257
&format!("while {receiver_text} {{\n $0\n}}"),
258258
)
259259
.add_to(acc, ctx.db);
260-
postfix_snippet("not", "!expr", &format!("!{receiver_text}")).add_to(acc, ctx.db);
261260
} else if let Some(trait_) = ctx.famous_defs().core_iter_IntoIterator()
262261
&& receiver_ty.impls_trait(ctx.db, trait_, &[])
263262
{
@@ -270,6 +269,10 @@ pub(crate) fn complete_postfix(
270269
}
271270
}
272271

272+
if receiver_ty.is_bool() || receiver_ty.is_unknown() {
273+
postfix_snippet("not", "!expr", &format!("!{receiver_text}")).add_to(acc, ctx.db);
274+
}
275+
273276
let block_should_be_wrapped = if let ast::Expr::BlockExpr(block) = dot_receiver {
274277
block.modifier().is_some() || !block.is_standalone()
275278
} else {
@@ -589,6 +592,31 @@ fn main() {
589592
);
590593
}
591594

595+
#[test]
596+
fn postfix_completion_works_in_if_condition() {
597+
check(
598+
r#"
599+
fn foo(cond: bool) {
600+
if cond.$0
601+
}
602+
"#,
603+
expect![[r#"
604+
sn box Box::new(expr)
605+
sn call function(expr)
606+
sn const const {}
607+
sn dbg dbg!(expr)
608+
sn dbgr dbg!(&expr)
609+
sn deref *expr
610+
sn let let
611+
sn not !expr
612+
sn ref &expr
613+
sn refm &mut expr
614+
sn return return expr
615+
sn unsafe unsafe {}
616+
"#]],
617+
);
618+
}
619+
592620
#[test]
593621
fn postfix_type_filtering() {
594622
check(

0 commit comments

Comments
 (0)