@@ -138,7 +138,7 @@ pub(crate) fn insert_use(
138
138
algo:: insert_children ( scope. as_syntax_node ( ) , insert_position, to_insert)
139
139
}
140
140
141
- fn try_merge_imports (
141
+ pub ( crate ) fn try_merge_imports (
142
142
old : & ast:: Use ,
143
143
new : & ast:: Use ,
144
144
merge_behaviour : MergeBehaviour ,
@@ -161,7 +161,7 @@ fn use_tree_list_is_nested(tl: &ast::UseTreeList) -> bool {
161
161
}
162
162
163
163
// FIXME: currently this merely prepends the new tree into old, ideally it would insert the items in a sorted fashion
164
- pub fn try_merge_trees (
164
+ pub ( crate ) fn try_merge_trees (
165
165
old : & ast:: UseTree ,
166
166
new : & ast:: UseTree ,
167
167
merge_behaviour : MergeBehaviour ,
@@ -278,7 +278,8 @@ fn first_path(path: &ast::Path) -> ast::Path {
278
278
}
279
279
280
280
fn segment_iter ( path : & ast:: Path ) -> impl Iterator < Item = ast:: PathSegment > + Clone {
281
- path. syntax ( ) . children ( ) . flat_map ( ast:: PathSegment :: cast)
281
+ // cant make use of SyntaxNode::siblings, because the returned Iterator is not clone
282
+ successors ( first_segment ( path) , |p| p. parent_path ( ) . parent_path ( ) . and_then ( |p| p. segment ( ) ) )
282
283
}
283
284
284
285
#[ derive( PartialEq , Eq ) ]
@@ -684,8 +685,18 @@ use std::io;",
684
685
check_last (
685
686
"foo::bar" ,
686
687
r"use foo::bar::baz::Qux;" ,
687
- r"use foo::bar::baz::Qux;
688
- use foo::bar;" ,
688
+ r"use foo::bar;
689
+ use foo::bar::baz::Qux;" ,
690
+ ) ;
691
+ }
692
+
693
+ #[ test]
694
+ fn insert_short_before_long ( ) {
695
+ check_none (
696
+ "foo::bar" ,
697
+ r"use foo::bar::baz::Qux;" ,
698
+ r"use foo::bar;
699
+ use foo::bar::baz::Qux;" ,
689
700
) ;
690
701
}
691
702
0 commit comments