mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
Rerail split_import API onto AST
The code is more verbose and less efficient now, but should be reusable in add_import context as well
This commit is contained in:
parent
d75577fcee
commit
ea0c124219
3 changed files with 72 additions and 19 deletions
|
@ -25,6 +25,27 @@ fn path_from_text(text: &str) -> ast::Path {
|
|||
ast_from_text(text)
|
||||
}
|
||||
|
||||
pub fn use_tree(
|
||||
path: ast::Path,
|
||||
use_tree_list: Option<ast::UseTreeList>,
|
||||
alias: Option<ast::Alias>,
|
||||
) -> ast::UseTree {
|
||||
let mut buf = "use ".to_string();
|
||||
buf += &path.syntax().to_string();
|
||||
if let Some(use_tree_list) = use_tree_list {
|
||||
buf += &format!("::{}", use_tree_list.syntax());
|
||||
}
|
||||
if let Some(alias) = alias {
|
||||
buf += &format!(" {}", alias.syntax());
|
||||
}
|
||||
ast_from_text(&buf)
|
||||
}
|
||||
|
||||
pub fn use_tree_list(use_trees: impl IntoIterator<Item = ast::UseTree>) -> ast::UseTreeList {
|
||||
let use_trees = use_trees.into_iter().map(|it| it.syntax().clone()).join(", ");
|
||||
ast_from_text(&format!("use {{{}}};", use_trees))
|
||||
}
|
||||
|
||||
pub fn record_field(name: ast::NameRef, expr: Option<ast::Expr>) -> ast::RecordField {
|
||||
return match expr {
|
||||
Some(expr) => from_text(&format!("{}: {}", name.syntax(), expr.syntax())),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue