mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 06:03:58 +00:00
hacky_block_expr_with_comments
This commit is contained in:
parent
5d35e5882c
commit
96ab4c6e6c
2 changed files with 10 additions and 11 deletions
|
@ -1524,9 +1524,7 @@ fn make_body(
|
||||||
println!("element: {:?}", element);
|
println!("element: {:?}", element);
|
||||||
}
|
}
|
||||||
|
|
||||||
make::block_expr_full(elements, tail_expr)
|
make::hacky_block_expr_with_comments(elements, tail_expr)
|
||||||
|
|
||||||
// make::block_expr(parent.statements().into_iter(), tail_expr)
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -329,17 +329,18 @@ pub fn block_expr(
|
||||||
ast_from_text(&format!("fn f() {}", buf))
|
ast_from_text(&format!("fn f() {}", buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn block_expr_full(
|
/// Ideally this function wouldn't exist since it involves manual indenting.
|
||||||
stmts: impl IntoIterator<Item = crate::SyntaxElement>,
|
/// It differs from `make::block_expr` by also supporting comments.
|
||||||
|
///
|
||||||
|
/// FIXME: replace usages of this with the mutable syntax tree API
|
||||||
|
pub fn hacky_block_expr_with_comments(
|
||||||
|
elements: impl IntoIterator<Item = crate::SyntaxElement>,
|
||||||
tail_expr: Option<ast::Expr>,
|
tail_expr: Option<ast::Expr>,
|
||||||
) -> ast::BlockExpr {
|
) -> ast::BlockExpr {
|
||||||
let mut buf = "{\n".to_string();
|
let mut buf = "{\n".to_string();
|
||||||
for stmt in stmts.into_iter() {
|
for node_or_token in elements.into_iter() {
|
||||||
match stmt {
|
match node_or_token {
|
||||||
rowan::NodeOrToken::Node(n) => {
|
rowan::NodeOrToken::Node(n) => format_to!(buf, " {}\n", n),
|
||||||
println!("Node: {:?}", n.text());
|
|
||||||
format_to!(buf, " {}\n", n)
|
|
||||||
}
|
|
||||||
rowan::NodeOrToken::Token(t) if t.kind() == SyntaxKind::COMMENT => {
|
rowan::NodeOrToken::Token(t) if t.kind() == SyntaxKind::COMMENT => {
|
||||||
format_to!(buf, " {}\n", t)
|
format_to!(buf, " {}\n", t)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue