diff options
Diffstat (limited to 'crates/assists/src/utils')
-rw-r--r-- | crates/assists/src/utils/insert_use.rs | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/crates/assists/src/utils/insert_use.rs b/crates/assists/src/utils/insert_use.rs index 8a4c8520d..1cb52318a 100644 --- a/crates/assists/src/utils/insert_use.rs +++ b/crates/assists/src/utils/insert_use.rs | |||
@@ -138,7 +138,7 @@ pub(crate) fn insert_use( | |||
138 | algo::insert_children(scope.as_syntax_node(), insert_position, to_insert) | 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 | old: &ast::Use, | 142 | old: &ast::Use, |
143 | new: &ast::Use, | 143 | new: &ast::Use, |
144 | merge_behaviour: MergeBehaviour, | 144 | merge_behaviour: MergeBehaviour, |
@@ -161,7 +161,7 @@ fn use_tree_list_is_nested(tl: &ast::UseTreeList) -> bool { | |||
161 | } | 161 | } |
162 | 162 | ||
163 | // FIXME: currently this merely prepends the new tree into old, ideally it would insert the items in a sorted fashion | 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 | old: &ast::UseTree, | 165 | old: &ast::UseTree, |
166 | new: &ast::UseTree, | 166 | new: &ast::UseTree, |
167 | merge_behaviour: MergeBehaviour, | 167 | merge_behaviour: MergeBehaviour, |
@@ -278,7 +278,8 @@ fn first_path(path: &ast::Path) -> ast::Path { | |||
278 | } | 278 | } |
279 | 279 | ||
280 | fn segment_iter(path: &ast::Path) -> impl Iterator<Item = ast::PathSegment> + Clone { | 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 | #[derive(PartialEq, Eq)] | 285 | #[derive(PartialEq, Eq)] |
@@ -684,8 +685,18 @@ use std::io;", | |||
684 | check_last( | 685 | check_last( |
685 | "foo::bar", | 686 | "foo::bar", |
686 | r"use foo::bar::baz::Qux;", | 687 | r"use foo::bar::baz::Qux;", |
687 | r"use foo::bar::baz::Qux; | 688 | r"use foo::bar; |
688 | 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 | ||