aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs19
1 files changed, 6 insertions, 13 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 301ae8497..f2286c9f6 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
@@ -5,7 +5,6 @@ use crate::{
5 utils::{find_insert_use_container, insert_use_statement}, 5 utils::{find_insert_use_container, insert_use_statement},
6 AssistContext, AssistId, Assists, 6 AssistContext, AssistId, Assists,
7}; 7};
8use either::Either;
9 8
10// Assist: replace_qualified_name_with_use 9// Assist: replace_qualified_name_with_use
11// 10//
@@ -56,14 +55,8 @@ pub(crate) fn replace_qualified_name_with_use(
56 None => return, 55 None => return,
57 }; 56 };
58 let mut rewriter = SyntaxRewriter::default(); 57 let mut rewriter = SyntaxRewriter::default();
59 match container { 58 let syntax = container.either(|l| l.syntax().clone(), |r| r.syntax().clone());
60 Either::Left(l) => { 59 shorten_paths(&mut rewriter, syntax, hir_path.mod_path());
61 shorten_paths(&mut rewriter, l.syntax().clone(), hir_path.mod_path());
62 }
63 Either::Right(r) => {
64 shorten_paths(&mut rewriter, r.syntax().clone(), hir_path.mod_path());
65 }
66 }
67 builder.rewrite(rewriter); 60 builder.rewrite(rewriter);
68 }, 61 },
69 ) 62 )
@@ -90,7 +83,7 @@ fn collect_hir_path_segments(path: &hir::Path) -> Option<Vec<SmolStr>> {
90} 83}
91 84
92/// Adds replacements to `re` that shorten `path` in all descendants of `node`. 85/// Adds replacements to `re` that shorten `path` in all descendants of `node`.
93fn shorten_paths(re: &mut SyntaxRewriter<'static>, node: SyntaxNode, path: &ModPath) { 86fn shorten_paths(rewriter: &mut SyntaxRewriter<'static>, node: SyntaxNode, path: &ModPath) {
94 for child in node.children() { 87 for child in node.children() {
95 match_ast! { 88 match_ast! {
96 match child { 89 match child {
@@ -101,12 +94,12 @@ fn shorten_paths(re: &mut SyntaxRewriter<'static>, node: SyntaxNode, path: &ModP
101 ast::Module(_it) => continue, 94 ast::Module(_it) => continue,
102 95
103 ast::Path(p) => { 96 ast::Path(p) => {
104 match maybe_replace_path(re, &p, path) { 97 match maybe_replace_path(rewriter, &p, path) {
105 Some(()) => {}, 98 Some(()) => {},
106 None => shorten_paths(re, p.syntax().clone(), path), 99 None => shorten_paths(rewriter, p.syntax().clone(), path),
107 } 100 }
108 }, 101 },
109 _ => shorten_paths(re, child, path), 102 _ => shorten_paths(rewriter, child, path),
110 } 103 }
111 } 104 }
112 } 105 }