pub(crate) fn qualify_path(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
    let import_assets =
        if let Some(path_under_caret) = ctx.find_node_at_offset_with_descend::<ast::Path>() {
            ImportAssets::for_regular_path(path_under_caret, &ctx.sema)
        } else if let Some(method_under_caret) =
            ctx.find_node_at_offset_with_descend::<ast::MethodCallExpr>()
        {
            ImportAssets::for_method_call(method_under_caret, &ctx.sema)
        } else {
            None
        }?;
    let proposed_imports = import_assets.search_for_relative_paths(&ctx.sema);
    if proposed_imports.is_empty() {
        return None;
    }

    let candidate = import_assets.import_candidate();
    let range = ctx.sema.original_range(import_assets.syntax_under_caret()).range;

    let qualify_candidate = match candidate {
        ImportCandidate::QualifierStart(_) => {
            mark::hit!(qualify_path_qualifier_start);
            let path = ast::Path::cast(import_assets.syntax_under_caret().clone())?;
            let segment = path.segment()?;
            QualifyCandidate::QualifierStart(segment)
        }
        ImportCandidate::UnqualifiedName(_) => {
            mark::hit!(qualify_path_unqualified_name);
            QualifyCandidate::UnqualifiedName
        }
        ImportCandidate::TraitAssocItem(_) => {
            mark::hit!(qualify_path_trait_assoc_item);
            let path = ast::Path::cast(import_assets.syntax_under_caret().clone())?;
            let (qualifier, segment) = (path.qualifier()?, path.segment()?);
            QualifyCandidate::TraitAssocItem(qualifier, segment)
        }
        ImportCandidate::TraitMethod(_) => {
            mark::hit!(qualify_path_trait_method);
            let mcall_expr = ast::MethodCallExpr::cast(import_assets.syntax_under_caret().clone())?;
            QualifyCandidate::TraitMethod(ctx.sema.db, mcall_expr)
        }
    };

    let group_label = group_label(candidate);
    for (import, item) in proposed_imports {
        acc.add_group(
            &group_label,
            AssistId("qualify_path", AssistKind::QuickFix),
            label(candidate, &import),
            range,
            |builder| {
                qualify_candidate.qualify(
                    |replace_with: String| builder.replace(range, replace_with),
                    import,
                    item,
                )
            },
        );
    }
    Some(())
}
// Assist: qualify_path
//
// If the name is unresolved, provides all possible qualified paths for it.
//
// ```
// fn main() {
//     let map = HashMap<|>::new();
// }
// # pub mod std { pub mod collections { pub struct HashMap { } } }
// ```
// ->
// ```
// fn main() {
//     let map = std::collections::HashMap::new();
// }
// # pub mod std { pub mod collections { pub struct HashMap { } } }
// ```
qualify_path
If the name is unresolved, provides all possible qualified paths for it.


qualify_path If the name is unresolved provides all possible qualified paths for it .
pub(crate) fn qualify_path(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
    let import_assets =
        if let Some(path_under_caret) = ctx.find_node_at_offset_with_descend::<ast::Path>() {
            ImportAssets::for_regular_path(path_under_caret, &ctx.sema)
        } else if let Some(method_under_caret) =
            ctx.find_node_at_offset_with_descend::<ast::MethodCallExpr>()
        {
            ImportAssets::for_method_call(method_under_caret, &ctx.sema)
        } else {
            None
        }?;
    let proposed_imports = import_assets.search_for_relative_paths(&ctx.sema);
    if proposed_imports.is_empty() {
        return None;
    }
    let candidate = import_assets.import_candidate();
    let range = ctx.sema.original_range(import_assets.syntax_under_caret()).range;
    let qualify_candidate = match candidate {
        ImportCandidate::QualifierStart(_) => {
            mark::hit!(qualify_path_qualifier_start);
            let path = ast::Path::cast(import_assets.syntax_under_caret().clone())?;
            let segment = path.segment()?;
            QualifyCandidate::QualifierStart(segment)
        }
        ImportCandidate::UnqualifiedName(_) => {
            mark::hit!(qualify_path_unqualified_name);
            QualifyCandidate::UnqualifiedName
        }
        ImportCandidate::TraitAssocItem(_) => {
            mark::hit!(qualify_path_trait_assoc_item);
            let path = ast::Path::cast(import_assets.syntax_under_caret().clone())?;
            let (qualifier, segment) = (path.qualifier()?, path.segment()?);
            QualifyCandidate::TraitAssocItem(qualifier, segment)
        }
        ImportCandidate::TraitMethod(_) => {
            mark::hit!(qualify_path_trait_method);
            let mcall_expr = ast::MethodCallExpr::cast(import_assets.syntax_under_caret().clone())?;
            QualifyCandidate::TraitMethod(ctx.sema.db, mcall_expr)
        }
    };
    let group_label = group_label(candidate);
    for (import, item) in proposed_imports {
        acc.add_group(
            &group_label,
            AssistId("qualify_path", AssistKind::QuickFix),
            label(candidate, &import),
            range,
            |builder| {
                qualify_candidate.qualify(
                    |replace_with: String| builder.replace(range, replace_with),
                    import,
                    item,
                )
            },
        );
    }
    Some(())
}
pub ( crate ) fn qualify_path ( acc : & mut Assists , ctx : & AssistContext ) -> Option < ( ) > { let import_assets = if let Some ( path_under_caret ) = ctx . find_node_at_offset_with_descend :: < ast :: Path > ( ) { ImportAssets :: for_regular_path ( path_under_caret , & ctx . sema ) } else if let Some ( method_under_caret ) = ctx . find_node_at_offset_with_descend :: < ast :: MethodCallExpr > ( ) { ImportAssets :: for_method_call ( method_under_caret , & ctx . sema ) } else { None } ? ; let proposed_imports = import_assets . search_for_relative_paths ( & ctx . sema ) ; if proposed_imports . is_empty ( ) { return None ; } let candidate = import_assets . import_candidate ( ) ; let range = ctx . sema . original_range ( import_assets . syntax_under_caret ( ) ) . range ; let qualify_candidate = match candidate { ImportCandidate :: QualifierStart ( _ ) => { mark :: hit ! ( qualify_path_qualifier_start ) ; let path = ast :: Path :: cast ( import_assets . syntax_under_caret ( ) . clone ( ) ) ? ; let segment = path . segment ( ) ? ; QualifyCandidate :: QualifierStart ( segment ) } ImportCandidate :: UnqualifiedName ( _ ) => { mark :: hit ! ( qualify_path_unqualified_name ) ; QualifyCandidate :: UnqualifiedName } ImportCandidate :: TraitAssocItem ( _ ) => { mark :: hit ! ( qualify_path_trait_assoc_item ) ; let path = ast :: Path :: cast ( import_assets . syntax_under_caret ( ) . clone ( ) ) ? ; let ( qualifier , segment ) = ( path . qualifier ( ) ? , path . segment ( ) ? ) ; QualifyCandidate :: TraitAssocItem ( qualifier , segment ) } ImportCandidate :: TraitMethod ( _ ) => { mark :: hit ! ( qualify_path_trait_method ) ; let mcall_expr = ast :: MethodCallExpr :: cast ( import_assets . syntax_under_caret ( ) . clone ( ) ) ? ; QualifyCandidate :: TraitMethod ( ctx . sema . db , mcall_expr ) } } ; let group_label = group_label ( candidate ) ; for ( import , item ) in proposed_imports { acc . add_group ( & group_label , AssistId ( " " , AssistKind :: QuickFix ) , label ( candidate , & import ) , range , | builder | { qualify_candidate . qualify ( | replace_with : String | builder . replace ( range , replace_with ) , import , item , ) } , ) ; } Some ( ( ) ) }
Assist: qualify_path
If the name is unresolved, provides all possible qualified paths for it.
Assist : qualify_path If the name is unresolved provides all possible qualified paths for it .
acc
&mut Assists
ctx
&AssistContext
acc
&mut Assists
ctx
&AssistContext
pub mod std { pub mod collections { pub struct hashmap { } } }
None
pub mod std { pub mod collections { pub struct hashmap { } } }
None