From 050c69c19dd8004c8dfc92dbff86a42fac022e6e Mon Sep 17 00:00:00 2001
From: Lukas Wirth <lukastw97@gmail.com>
Date: Sat, 24 Apr 2021 13:31:16 +0200
Subject: Split out merge_imports module from helpers::insert_use

---
 crates/syntax/src/ast/node_ext.rs | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

(limited to 'crates/syntax/src')

diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs
index 171099661..492fbc4a0 100644
--- a/crates/syntax/src/ast/node_ext.rs
+++ b/crates/syntax/src/ast/node_ext.rs
@@ -1,7 +1,7 @@
 //! Various extension methods to ast Nodes, which are hard to code-generate.
 //! Extensions for various expressions live in a sibling `expr_extensions` module.
 
-use std::fmt;
+use std::{fmt, iter::successors};
 
 use itertools::Itertools;
 use parser::SyntaxKind;
@@ -237,6 +237,26 @@ impl ast::Path {
             None => self.segment(),
         }
     }
+
+    pub fn first_qualifier_or_self(&self) -> ast::Path {
+        successors(Some(self.clone()), ast::Path::qualifier).last().unwrap()
+    }
+
+    pub fn first_segment(&self) -> Option<ast::PathSegment> {
+        self.first_qualifier_or_self().segment()
+    }
+
+    pub fn segments(&self) -> impl Iterator<Item = ast::PathSegment> + Clone {
+        // cant make use of SyntaxNode::siblings, because the returned Iterator is not clone
+        successors(self.first_segment(), |p| {
+            p.parent_path().parent_path().and_then(|p| p.segment())
+        })
+    }
+}
+impl ast::UseTree {
+    pub fn is_simple_path(&self) -> bool {
+        self.use_tree_list().is_none() && self.star_token().is_none()
+    }
 }
 
 impl ast::UseTreeList {
-- 
cgit v1.2.3