mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-18 17:40:29 +00:00
very rough but comments get extracted
This commit is contained in:
parent
f662d8bf38
commit
4f3dd5bc08
2 changed files with 230 additions and 28 deletions
|
@ -329,6 +329,29 @@ pub fn block_expr(
|
|||
ast_from_text(&format!("fn f() {}", buf))
|
||||
}
|
||||
|
||||
pub fn block_expr_full(
|
||||
stmts: impl IntoIterator<Item = crate::SyntaxElement>,
|
||||
tail_expr: Option<ast::Expr>,
|
||||
) -> ast::BlockExpr {
|
||||
let mut buf = "{\n".to_string();
|
||||
for stmt in stmts.into_iter() {
|
||||
|
||||
match stmt {
|
||||
rowan::NodeOrToken::Node(n) => {
|
||||
println!("Node: {:?}", n.text());
|
||||
format_to!(buf, " {}\n", n)
|
||||
},
|
||||
rowan::NodeOrToken::Token(t) if t.kind() == SyntaxKind::COMMENT => format_to!(buf, " {}\n", t),
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
if let Some(tail_expr) = tail_expr {
|
||||
format_to!(buf, " {}\n", tail_expr);
|
||||
}
|
||||
buf += "}";
|
||||
ast_from_text(&format!("fn f() {}", buf))
|
||||
}
|
||||
|
||||
pub fn expr_unit() -> ast::Expr {
|
||||
expr_from_text("()")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue