aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_assists
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_assists')
-rw-r--r--crates/ide_assists/src/handlers/qualify_path.rs44
1 files changed, 17 insertions, 27 deletions
diff --git a/crates/ide_assists/src/handlers/qualify_path.rs b/crates/ide_assists/src/handlers/qualify_path.rs
index 40571e52b..e7444f7db 100644
--- a/crates/ide_assists/src/handlers/qualify_path.rs
+++ b/crates/ide_assists/src/handlers/qualify_path.rs
@@ -14,11 +14,10 @@ use syntax::{
14 14
15use crate::{ 15use crate::{
16 assist_context::{AssistContext, Assists}, 16 assist_context::{AssistContext, Assists},
17 handlers::auto_import::find_importable_node,
17 AssistId, AssistKind, GroupLabel, 18 AssistId, AssistKind, GroupLabel,
18}; 19};
19 20
20use super::auto_import::find_importable_node;
21
22// Assist: qualify_path 21// Assist: qualify_path
23// 22//
24// If the name is unresolved, provides all possible qualified paths for it. 23// If the name is unresolved, provides all possible qualified paths for it.
@@ -43,22 +42,20 @@ pub(crate) fn qualify_path(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
43 return None; 42 return None;
44 } 43 }
45 44
46 let candidate = import_assets.import_candidate();
47 let range = ctx.sema.original_range(&syntax_under_caret).range; 45 let range = ctx.sema.original_range(&syntax_under_caret).range;
48 46 let candidate = import_assets.import_candidate();
49 let qualify_candidate = match candidate { 47 let qualify_candidate = match candidate {
50 ImportCandidate::Path(candidate) => { 48 ImportCandidate::Path(candidate) if candidate.qualifier.is_some() => {
51 if candidate.qualifier.is_some() { 49 cov_mark::hit!(qualify_path_qualifier_start);
52 cov_mark::hit!(qualify_path_qualifier_start); 50 let path = ast::Path::cast(syntax_under_caret)?;
53 let path = ast::Path::cast(syntax_under_caret)?; 51 let (prev_segment, segment) = (path.qualifier()?.segment()?, path.segment()?);
54 let (prev_segment, segment) = (path.qualifier()?.segment()?, path.segment()?); 52 QualifyCandidate::QualifierStart(segment, prev_segment.generic_arg_list())
55 QualifyCandidate::QualifierStart(segment, prev_segment.generic_arg_list()) 53 }
56 } else { 54 ImportCandidate::Path(_) => {
57 cov_mark::hit!(qualify_path_unqualified_name); 55 cov_mark::hit!(qualify_path_unqualified_name);
58 let path = ast::Path::cast(syntax_under_caret)?; 56 let path = ast::Path::cast(syntax_under_caret)?;
59 let generics = path.segment()?.generic_arg_list(); 57 let generics = path.segment()?.generic_arg_list();
60 QualifyCandidate::UnqualifiedName(generics) 58 QualifyCandidate::UnqualifiedName(generics)
61 }
62 } 59 }
63 ImportCandidate::TraitAssocItem(_) => { 60 ImportCandidate::TraitAssocItem(_) => {
64 cov_mark::hit!(qualify_path_trait_assoc_item); 61 cov_mark::hit!(qualify_path_trait_assoc_item);
@@ -119,7 +116,7 @@ impl QualifyCandidate<'_> {
119 QualifyCandidate::TraitAssocItem(qualifier, segment) => { 116 QualifyCandidate::TraitAssocItem(qualifier, segment) => {
120 replacer(format!("<{} as {}>::{}", qualifier, import, segment)); 117 replacer(format!("<{} as {}>::{}", qualifier, import, segment));
121 } 118 }
122 &QualifyCandidate::TraitMethod(db, ref mcall_expr) => { 119 QualifyCandidate::TraitMethod(db, mcall_expr) => {
123 Self::qualify_trait_method(db, mcall_expr, replacer, import, item); 120 Self::qualify_trait_method(db, mcall_expr, replacer, import, item);
124 } 121 }
125 } 122 }
@@ -201,17 +198,10 @@ fn group_label(candidate: &ImportCandidate) -> GroupLabel {
201 198
202fn label(candidate: &ImportCandidate, import: &LocatedImport) -> String { 199fn label(candidate: &ImportCandidate, import: &LocatedImport) -> String {
203 match candidate { 200 match candidate {
204 ImportCandidate::Path(candidate) => { 201 ImportCandidate::Path(candidate) if candidate.qualifier.is_none() => {
205 if candidate.qualifier.is_some() { 202 format!("Qualify as `{}`", import.import_path)
206 format!("Qualify with `{}`", import.import_path)
207 } else {
208 format!("Qualify as `{}`", import.import_path)
209 }
210 }
211 ImportCandidate::TraitAssocItem(_) => {
212 format!("Qualify with `{}`", import.import_path)
213 } 203 }
214 ImportCandidate::TraitMethod(_) => format!("Qualify with `{}`", import.import_path), 204 _ => format!("Qualify with `{}`", import.import_path),
215 } 205 }
216} 206}
217 207