Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/syntax/src/ast/node_ext.rs')
-rw-r--r--crates/syntax/src/ast/node_ext.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs
index 19c2d3be16..0f06690b8c 100644
--- a/crates/syntax/src/ast/node_ext.rs
+++ b/crates/syntax/src/ast/node_ext.rs
@@ -327,6 +327,14 @@ impl ast::UseTree {
pub fn parent_use_tree_list(&self) -> Option<ast::UseTreeList> {
self.syntax().parent().and_then(ast::UseTreeList::cast)
}
+
+ pub fn top_use_tree(&self) -> ast::UseTree {
+ let mut this = self.clone();
+ while let Some(use_tree_list) = this.parent_use_tree_list() {
+ this = use_tree_list.parent_use_tree();
+ }
+ this
+ }
}
impl ast::UseTreeList {