Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions crates/ide-completion/src/completions/postfix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use ide_db::{
};
use stdx::never;
use syntax::{
SyntaxKind::{BLOCK_EXPR, EXPR_STMT, FOR_EXPR, IF_EXPR, LOOP_EXPR, STMT_LIST, WHILE_EXPR},
SyntaxKind::{EXPR_STMT, STMT_LIST},
T, TextRange, TextSize,
ast::{self, AstNode, AstToken},
match_ast,
Expand Down Expand Up @@ -253,18 +253,15 @@ pub(crate) fn complete_postfix(
}
}

let mut block_should_be_wrapped = true;
if dot_receiver.syntax().kind() == BLOCK_EXPR {
block_should_be_wrapped = false;
if let Some(parent) = dot_receiver.syntax().parent()
&& matches!(parent.kind(), IF_EXPR | WHILE_EXPR | LOOP_EXPR | FOR_EXPR)
{
block_should_be_wrapped = true;
}
let block_should_be_wrapped = if let ast::Expr::BlockExpr(block) = dot_receiver {
block.modifier().is_some() || !block.is_standalone()
} else {
true
};
{
let (open_brace, close_brace) =
if block_should_be_wrapped { ("{ ", " }") } else { ("", "") };
// FIXME: Why add parentheses
let (open_paren, close_paren) = if is_in_cond { ("(", ")") } else { ("", "") };
let unsafe_completion_string =
format!("{open_paren}unsafe {open_brace}{receiver_text}{close_brace}{close_paren}");
Expand Down Expand Up @@ -842,6 +839,20 @@ fn main() {
&format!("fn main() {{ let x = {kind} {{ if true {{1}} else {{2}} }} }}"),
);

if kind == "const" {
check_edit(
kind,
r#"fn main() { unsafe {1}.$0 }"#,
&format!("fn main() {{ {kind} {{ unsafe {{1}} }} }}"),
);
} else {
check_edit(
kind,
r#"fn main() { const {1}.$0 }"#,
&format!("fn main() {{ {kind} {{ const {{1}} }} }}"),
);
}

// completion will not be triggered
check_edit(
kind,
Expand Down