diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-04-24 12:39:50 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-04-24 12:39:50 +0100 |
commit | 1b4defd2409d6a6120b40a0730e9822a819e971d (patch) | |
tree | 558c6d18d829a5a0b954654df5b232772839c86f /crates/syntax/src | |
parent | 4d110dd118e42a355ca8db41c7fdbf4371c45105 (diff) | |
parent | 050c69c19dd8004c8dfc92dbff86a42fac022e6e (diff) |
Merge #8647
8647: internal: Split out merge_imports module from helpers::insert_use r=Veykril a=Veykril
bors r+
Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/syntax/src')
-rw-r--r-- | crates/syntax/src/ast/node_ext.rs | 22 |
1 files changed, 21 insertions, 1 deletions
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 @@ | |||
1 | //! Various extension methods to ast Nodes, which are hard to code-generate. | 1 | //! Various extension methods to ast Nodes, which are hard to code-generate. |
2 | //! Extensions for various expressions live in a sibling `expr_extensions` module. | 2 | //! Extensions for various expressions live in a sibling `expr_extensions` module. |
3 | 3 | ||
4 | use std::fmt; | 4 | use std::{fmt, iter::successors}; |
5 | 5 | ||
6 | use itertools::Itertools; | 6 | use itertools::Itertools; |
7 | use parser::SyntaxKind; | 7 | use parser::SyntaxKind; |
@@ -237,6 +237,26 @@ impl ast::Path { | |||
237 | None => self.segment(), | 237 | None => self.segment(), |
238 | } | 238 | } |
239 | } | 239 | } |
240 | |||
241 | pub fn first_qualifier_or_self(&self) -> ast::Path { | ||
242 | successors(Some(self.clone()), ast::Path::qualifier).last().unwrap() | ||
243 | } | ||
244 | |||
245 | pub fn first_segment(&self) -> Option<ast::PathSegment> { | ||
246 | self.first_qualifier_or_self().segment() | ||
247 | } | ||
248 | |||
249 | pub fn segments(&self) -> impl Iterator<Item = ast::PathSegment> + Clone { | ||
250 | // cant make use of SyntaxNode::siblings, because the returned Iterator is not clone | ||
251 | successors(self.first_segment(), |p| { | ||
252 | p.parent_path().parent_path().and_then(|p| p.segment()) | ||
253 | }) | ||
254 | } | ||
255 | } | ||
256 | impl ast::UseTree { | ||
257 | pub fn is_simple_path(&self) -> bool { | ||
258 | self.use_tree_list().is_none() && self.star_token().is_none() | ||
259 | } | ||
240 | } | 260 | } |
241 | 261 | ||
242 | impl ast::UseTreeList { | 262 | impl ast::UseTreeList { |