X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Ftools%2Frust-analyzer%2Fcrates%2Fsyntax%2Fsrc%2Fast%2Fnode_ext.rs;h=bb92c51e9a90ed766bce24344f8ddeeb2337ed8c;hb=30a370678603ce8cdc47c91a09f335533119d4dd;hp=b143df1f83f2ae3a2aa26dad048cd1fedc5c0492;hpb=b8aab9781a76f4498cc3819674397dedad37f20b;p=rust.git diff --git a/src/tools/rust-analyzer/crates/syntax/src/ast/node_ext.rs b/src/tools/rust-analyzer/crates/syntax/src/ast/node_ext.rs index b143df1f83f..bb92c51e9a9 100644 --- a/src/tools/rust-analyzer/crates/syntax/src/ast/node_ext.rs +++ b/src/tools/rust-analyzer/crates/syntax/src/ast/node_ext.rs @@ -806,6 +806,19 @@ pub fn type_or_const_params(&self) -> impl Iterator Option { + // If the iterable is a BlockExpr, check if the body is missing. + // If it is assume the iterable is the expression that is missing instead. + let mut exprs = support::children(self.syntax()); + let first = exprs.next(); + match first { + Some(ast::Expr::BlockExpr(_)) => exprs.next().and(first), + first => first, + } + } +} + impl ast::HasLoopBody for ast::ForExpr { fn loop_body(&self) -> Option { let mut exprs = support::children(self.syntax()); @@ -815,6 +828,19 @@ fn loop_body(&self) -> Option { } } +impl ast::WhileExpr { + pub fn condition(&self) -> Option { + // If the condition is a BlockExpr, check if the body is missing. + // If it is assume the condition is the expression that is missing instead. + let mut exprs = support::children(self.syntax()); + let first = exprs.next(); + match first { + Some(ast::Expr::BlockExpr(_)) => exprs.next().and(first), + first => first, + } + } +} + impl ast::HasLoopBody for ast::WhileExpr { fn loop_body(&self) -> Option { let mut exprs = support::children(self.syntax()); @@ -835,3 +861,15 @@ fn from(it: ast::Adt) -> Self { } } } + +impl ast::IfExpr { + pub fn condition(&self) -> Option { + support::child(&self.syntax) + } +} + +impl ast::MatchGuard { + pub fn condition(&self) -> Option { + support::child(&self.syntax) + } +}