Cleanup qualify_path
This commit is contained in:
parent
7200b994c9
commit
c34a9f10b1
@ -14,11 +14,10 @@
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
assist_context::{AssistContext, Assists},
|
assist_context::{AssistContext, Assists},
|
||||||
|
handlers::auto_import::find_importable_node,
|
||||||
AssistId, AssistKind, GroupLabel,
|
AssistId, AssistKind, GroupLabel,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::auto_import::find_importable_node;
|
|
||||||
|
|
||||||
// Assist: qualify_path
|
// Assist: qualify_path
|
||||||
//
|
//
|
||||||
// If the name is unresolved, provides all possible qualified paths for it.
|
// If the name is unresolved, provides all possible qualified paths for it.
|
||||||
@ -43,23 +42,21 @@ pub(crate) fn qualify_path(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let candidate = import_assets.import_candidate();
|
|
||||||
let range = ctx.sema.original_range(&syntax_under_caret).range;
|
let range = ctx.sema.original_range(&syntax_under_caret).range;
|
||||||
|
let candidate = import_assets.import_candidate();
|
||||||
let qualify_candidate = match candidate {
|
let qualify_candidate = match candidate {
|
||||||
ImportCandidate::Path(candidate) => {
|
ImportCandidate::Path(candidate) if candidate.qualifier.is_some() => {
|
||||||
if candidate.qualifier.is_some() {
|
|
||||||
cov_mark::hit!(qualify_path_qualifier_start);
|
cov_mark::hit!(qualify_path_qualifier_start);
|
||||||
let path = ast::Path::cast(syntax_under_caret)?;
|
let path = ast::Path::cast(syntax_under_caret)?;
|
||||||
let (prev_segment, segment) = (path.qualifier()?.segment()?, path.segment()?);
|
let (prev_segment, segment) = (path.qualifier()?.segment()?, path.segment()?);
|
||||||
QualifyCandidate::QualifierStart(segment, prev_segment.generic_arg_list())
|
QualifyCandidate::QualifierStart(segment, prev_segment.generic_arg_list())
|
||||||
} else {
|
}
|
||||||
|
ImportCandidate::Path(_) => {
|
||||||
cov_mark::hit!(qualify_path_unqualified_name);
|
cov_mark::hit!(qualify_path_unqualified_name);
|
||||||
let path = ast::Path::cast(syntax_under_caret)?;
|
let path = ast::Path::cast(syntax_under_caret)?;
|
||||||
let generics = path.segment()?.generic_arg_list();
|
let generics = path.segment()?.generic_arg_list();
|
||||||
QualifyCandidate::UnqualifiedName(generics)
|
QualifyCandidate::UnqualifiedName(generics)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
ImportCandidate::TraitAssocItem(_) => {
|
ImportCandidate::TraitAssocItem(_) => {
|
||||||
cov_mark::hit!(qualify_path_trait_assoc_item);
|
cov_mark::hit!(qualify_path_trait_assoc_item);
|
||||||
let path = ast::Path::cast(syntax_under_caret)?;
|
let path = ast::Path::cast(syntax_under_caret)?;
|
||||||
@ -119,7 +116,7 @@ fn qualify(
|
|||||||
QualifyCandidate::TraitAssocItem(qualifier, segment) => {
|
QualifyCandidate::TraitAssocItem(qualifier, segment) => {
|
||||||
replacer(format!("<{} as {}>::{}", qualifier, import, segment));
|
replacer(format!("<{} as {}>::{}", qualifier, import, segment));
|
||||||
}
|
}
|
||||||
&QualifyCandidate::TraitMethod(db, ref mcall_expr) => {
|
QualifyCandidate::TraitMethod(db, mcall_expr) => {
|
||||||
Self::qualify_trait_method(db, mcall_expr, replacer, import, item);
|
Self::qualify_trait_method(db, mcall_expr, replacer, import, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -201,17 +198,10 @@ fn group_label(candidate: &ImportCandidate) -> GroupLabel {
|
|||||||
|
|
||||||
fn label(candidate: &ImportCandidate, import: &LocatedImport) -> String {
|
fn label(candidate: &ImportCandidate, import: &LocatedImport) -> String {
|
||||||
match candidate {
|
match candidate {
|
||||||
ImportCandidate::Path(candidate) => {
|
ImportCandidate::Path(candidate) if candidate.qualifier.is_none() => {
|
||||||
if candidate.qualifier.is_some() {
|
|
||||||
format!("Qualify with `{}`", import.import_path)
|
|
||||||
} else {
|
|
||||||
format!("Qualify as `{}`", import.import_path)
|
format!("Qualify as `{}`", import.import_path)
|
||||||
}
|
}
|
||||||
}
|
_ => format!("Qualify with `{}`", import.import_path),
|
||||||
ImportCandidate::TraitAssocItem(_) => {
|
|
||||||
format!("Qualify with `{}`", import.import_path)
|
|
||||||
}
|
|
||||||
ImportCandidate::TraitMethod(_) => format!("Qualify with `{}`", import.import_path),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user