mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
refine semi completion
This commit is contained in:
parent
c0d1b17a4e
commit
29a52f8d56
2 changed files with 34 additions and 16 deletions
|
@ -191,6 +191,24 @@ mod tests {
|
|||
return "return $0;"
|
||||
"#,
|
||||
);
|
||||
check_keyword_completion(
|
||||
r"
|
||||
fn quux() -> i32 {
|
||||
if condition {
|
||||
<|>
|
||||
}
|
||||
let x = 92;
|
||||
x
|
||||
}
|
||||
",
|
||||
r#"
|
||||
if "if $0 {}"
|
||||
match "match $0 {}"
|
||||
while "while $0 {}"
|
||||
loop "loop {$0}"
|
||||
return "return $0;"
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -148,24 +148,24 @@ impl<'a> CompletionContext<'a> {
|
|||
if path.qualifier().is_none() {
|
||||
self.is_trivial_path = true;
|
||||
|
||||
self.can_be_stmt = match name_ref
|
||||
// Find either enclosing expr statement (thing with `;`) or a
|
||||
// block. If block, check that we are the last expr.
|
||||
self.can_be_stmt = name_ref
|
||||
.syntax()
|
||||
.ancestors()
|
||||
.filter_map(ast::ExprStmt::cast)
|
||||
.next()
|
||||
{
|
||||
None => {
|
||||
name_ref
|
||||
.syntax()
|
||||
.ancestors()
|
||||
.filter_map(ast::Block::cast)
|
||||
.next()
|
||||
.and_then(|block| block.expr())
|
||||
.map(|e| e.syntax().range())
|
||||
== Some(name_ref.syntax().range())
|
||||
.find_map(|node| {
|
||||
if let Some(stmt) = ast::ExprStmt::cast(node) {
|
||||
return Some(stmt.syntax().range() == name_ref.syntax().range());
|
||||
}
|
||||
Some(expr_stmt) => expr_stmt.syntax().range() == name_ref.syntax().range(),
|
||||
};
|
||||
if let Some(block) = ast::Block::cast(node) {
|
||||
return Some(
|
||||
block.expr().map(|e| e.syntax().range())
|
||||
== Some(name_ref.syntax().range()),
|
||||
);
|
||||
}
|
||||
None
|
||||
})
|
||||
.unwrap_or(false);
|
||||
|
||||
if let Some(off) = name_ref.syntax().range().start().checked_sub(2.into()) {
|
||||
if let Some(if_expr) =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue