mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
Split out merge_imports module from helpers::insert_use
This commit is contained in:
parent
4d110dd118
commit
050c69c19d
8 changed files with 344 additions and 329 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue