aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs')
-rw-r--r--crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs18
1 files changed, 7 insertions, 11 deletions
diff --git a/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs b/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs
index 2f2306fcc..99ba79860 100644
--- a/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs
+++ b/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs
@@ -31,7 +31,7 @@ pub(crate) fn replace_qualified_name_with_use(
31 } 31 }
32 32
33 let target = path.syntax().text_range(); 33 let target = path.syntax().text_range();
34 let scope = ImportScope::find_insert_use_container(path.syntax(), &ctx.sema)?; 34 let scope = ImportScope::find_insert_use_container_with_macros(path.syntax(), &ctx.sema)?;
35 let syntax = scope.as_syntax_node(); 35 let syntax = scope.as_syntax_node();
36 acc.add( 36 acc.add(
37 AssistId("replace_qualified_name_with_use", AssistKind::RefactorRewrite), 37 AssistId("replace_qualified_name_with_use", AssistKind::RefactorRewrite),
@@ -42,15 +42,15 @@ pub(crate) fn replace_qualified_name_with_use(
42 // affected (that is, all paths inside the node we added the `use` to). 42 // affected (that is, all paths inside the node we added the `use` to).
43 let syntax = builder.make_mut(syntax.clone()); 43 let syntax = builder.make_mut(syntax.clone());
44 if let Some(ref import_scope) = ImportScope::from(syntax.clone()) { 44 if let Some(ref import_scope) = ImportScope::from(syntax.clone()) {
45 insert_use(import_scope, path.clone(), ctx.config.insert_use); 45 shorten_paths(&syntax, &path.clone_for_update());
46 insert_use(import_scope, path, ctx.config.insert_use);
46 } 47 }
47 shorten_paths(syntax.clone(), &path.clone_for_update());
48 }, 48 },
49 ) 49 )
50} 50}
51 51
52/// Adds replacements to `re` that shorten `path` in all descendants of `node`. 52/// Adds replacements to `re` that shorten `path` in all descendants of `node`.
53fn shorten_paths(node: SyntaxNode, path: &ast::Path) { 53fn shorten_paths(node: &SyntaxNode, path: &ast::Path) {
54 for child in node.children() { 54 for child in node.children() {
55 match_ast! { 55 match_ast! {
56 match child { 56 match child {
@@ -59,14 +59,10 @@ fn shorten_paths(node: SyntaxNode, path: &ast::Path) {
59 ast::Use(_it) => continue, 59 ast::Use(_it) => continue,
60 // Don't descend into submodules, they don't have the same `use` items in scope. 60 // Don't descend into submodules, they don't have the same `use` items in scope.
61 ast::Module(_it) => continue, 61 ast::Module(_it) => continue,
62 62 ast::Path(p) => if maybe_replace_path(p.clone(), path.clone()).is_none() {
63 ast::Path(p) => { 63 shorten_paths(p.syntax(), path);
64 match maybe_replace_path(p.clone(), path.clone()) {
65 Some(()) => {},
66 None => shorten_paths(p.syntax().clone(), path),
67 }
68 }, 64 },
69 _ => shorten_paths(child, path), 65 _ => shorten_paths(&child, path),
70 } 66 }
71 } 67 }
72 } 68 }