mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
parent
4e50efcfc5
commit
3f6dc20d3c
8 changed files with 225 additions and 25 deletions
|
@ -273,6 +273,26 @@ impl ast::UseTree {
|
|||
}
|
||||
self.clone()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn split_prefix(&self, prefix: &ast::Path) -> ast::UseTree {
|
||||
let suffix = match split_path_prefix(&prefix) {
|
||||
Some(it) => it,
|
||||
None => return self.clone(),
|
||||
};
|
||||
let use_tree = make::use_tree(suffix.clone(), self.use_tree_list(), self.alias());
|
||||
let nested = make::use_tree_list(iter::once(use_tree));
|
||||
return make::use_tree(prefix.clone(), Some(nested), None);
|
||||
|
||||
fn split_path_prefix(prefix: &ast::Path) -> Option<ast::Path> {
|
||||
let parent = prefix.parent_path()?;
|
||||
let mut res = make::path_unqualified(parent.segment()?);
|
||||
for p in iter::successors(parent.parent_path(), |it| it.parent_path()) {
|
||||
res = make::path_qualified(res, p.segment()?);
|
||||
}
|
||||
Some(res)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
|
|
|
@ -167,6 +167,20 @@ impl ast::UseTreeList {
|
|||
.and_then(ast::UseTree::cast)
|
||||
.expect("UseTreeLists are always nested in UseTrees")
|
||||
}
|
||||
pub fn l_curly(&self) -> Option<SyntaxToken> {
|
||||
self.token(T!['{'])
|
||||
}
|
||||
|
||||
pub fn r_curly(&self) -> Option<SyntaxToken> {
|
||||
self.token(T!['}'])
|
||||
}
|
||||
|
||||
fn token(&self, kind: SyntaxKind) -> Option<SyntaxToken> {
|
||||
self.syntax()
|
||||
.children_with_tokens()
|
||||
.filter_map(|it| it.into_token())
|
||||
.find(|it| it.kind() == kind)
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::ImplDef {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue