Skip to content
Merged
Show file tree
Hide file tree
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
54 changes: 54 additions & 0 deletions crates/ide-completion/src/completions/keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,60 @@ fn main() {
};
bar();
}
"#,
);

check_edit(
"loop",
r#"
fn main() {
let x = &$0
bar();
}
"#,
r#"
fn main() {
let x = &loop {
$0
};
bar();
}
"#,
);

check_edit(
"loop",
r#"
fn main() {
let x = -$0
bar();
}
"#,
r#"
fn main() {
let x = -loop {
$0
};
bar();
}
"#,
);

check_edit(
"loop",
r#"
fn main() {
let x = 2 + $0
bar();
}
"#,
r#"
fn main() {
let x = 2 + loop {
$0
};
bar();
}
"#,
);
}
Expand Down
12 changes: 9 additions & 3 deletions crates/ide-completion/src/context/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1321,9 +1321,8 @@ fn classify_name_ref<'db>(
let incomplete_expr_stmt =
it.parent().and_then(ast::ExprStmt::cast).map(|it| it.semicolon_token().is_none());
let before_else_kw = before_else_kw(it);
let incomplete_let = it
.parent()
.and_then(ast::LetStmt::cast)
let incomplete_let = left_ancestors(it.parent())
.find_map(ast::LetStmt::cast)
.is_some_and(|it| it.semicolon_token().is_none())
|| after_incomplete_let && incomplete_expr_stmt.unwrap_or(true) && !before_else_kw;
let in_value = is_in_value(it);
Expand Down Expand Up @@ -1882,6 +1881,13 @@ fn path_or_use_tree_qualifier(path: &ast::Path) -> Option<(ast::Path, bool)> {
Some((use_tree.path()?, true))
}

fn left_ancestors(node: Option<SyntaxNode>) -> impl Iterator<Item = SyntaxNode> {
node.into_iter().flat_map(|node| {
let end = node.text_range().end();
node.ancestors().take_while(move |it| it.text_range().end() == end)
})
}

fn is_in_token_of_for_loop(path: &ast::Path) -> bool {
// oh my ...
(|| {
Expand Down