diff options
Diffstat (limited to 'crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs')
-rw-r--r-- | crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs b/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs index 3d51faa54..da0a860c5 100644 --- a/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs +++ b/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs | |||
@@ -25,7 +25,7 @@ pub(crate) fn replace_qualified_name_with_use( | |||
25 | ) -> Option<()> { | 25 | ) -> Option<()> { |
26 | let path: ast::Path = ctx.find_node_at_offset()?; | 26 | let path: ast::Path = ctx.find_node_at_offset()?; |
27 | // We don't want to mess with use statements | 27 | // We don't want to mess with use statements |
28 | if path.syntax().ancestors().find_map(ast::UseItem::cast).is_some() { | 28 | if path.syntax().ancestors().find_map(ast::Use::cast).is_some() { |
29 | return None; | 29 | return None; |
30 | } | 30 | } |
31 | 31 | ||
@@ -85,7 +85,7 @@ fn shorten_paths(rewriter: &mut SyntaxRewriter<'static>, node: SyntaxNode, path: | |||
85 | match child { | 85 | match child { |
86 | // Don't modify `use` items, as this can break the `use` item when injecting a new | 86 | // Don't modify `use` items, as this can break the `use` item when injecting a new |
87 | // import into the use tree. | 87 | // import into the use tree. |
88 | ast::UseItem(_it) => continue, | 88 | ast::Use(_it) => continue, |
89 | // Don't descend into submodules, they don't have the same `use` items in scope. | 89 | // Don't descend into submodules, they don't have the same `use` items in scope. |
90 | ast::Module(_it) => continue, | 90 | ast::Module(_it) => continue, |
91 | 91 | ||
@@ -643,4 +643,46 @@ fn main() { | |||
643 | ", | 643 | ", |
644 | ); | 644 | ); |
645 | } | 645 | } |
646 | |||
647 | #[test] | ||
648 | fn does_not_replace_pub_use() { | ||
649 | check_assist( | ||
650 | replace_qualified_name_with_use, | ||
651 | r" | ||
652 | pub use std::fmt; | ||
653 | |||
654 | impl std::io<|> for Foo { | ||
655 | } | ||
656 | ", | ||
657 | r" | ||
658 | use std::io; | ||
659 | |||
660 | pub use std::fmt; | ||
661 | |||
662 | impl io for Foo { | ||
663 | } | ||
664 | ", | ||
665 | ); | ||
666 | } | ||
667 | |||
668 | #[test] | ||
669 | fn does_not_replace_pub_crate_use() { | ||
670 | check_assist( | ||
671 | replace_qualified_name_with_use, | ||
672 | r" | ||
673 | pub(crate) use std::fmt; | ||
674 | |||
675 | impl std::io<|> for Foo { | ||
676 | } | ||
677 | ", | ||
678 | r" | ||
679 | use std::io; | ||
680 | |||
681 | pub(crate) use std::fmt; | ||
682 | |||
683 | impl io for Foo { | ||
684 | } | ||
685 | ", | ||
686 | ); | ||
687 | } | ||
646 | } | 688 | } |