From 94bb9cb9ee0e67048c6fdd90250add0cc71b073f Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Wed, 10 Mar 2021 11:30:25 +0200 Subject: [PATCH] Fix labels for single import assists --- crates/ide_assists/src/handlers/auto_import.rs | 14 +++++--------- .../ide_assists/src/handlers/qualify_path.rs | 18 +++++++----------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/crates/ide_assists/src/handlers/auto_import.rs b/crates/ide_assists/src/handlers/auto_import.rs index 7caee8df04..7019039b9e 100644 --- a/crates/ide_assists/src/handlers/auto_import.rs +++ b/crates/ide_assists/src/handlers/auto_import.rs @@ -1,7 +1,7 @@ use ide_db::helpers::{ import_assets::{ImportAssets, ImportCandidate}, insert_use::{insert_use, ImportScope}, - item_name, mod_path_to_ast, + mod_path_to_ast, }; use syntax::{ast, AstNode, SyntaxNode}; @@ -90,17 +90,13 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()> } let range = ctx.sema.original_range(&syntax_under_caret).range; - let group = import_group_message(import_assets.import_candidate()); + let group_label = group_label(import_assets.import_candidate()); let scope = ImportScope::find_insert_use_container(&syntax_under_caret, &ctx.sema)?; for import in proposed_imports { - let name = match item_name(ctx.db(), import.original_item) { - Some(name) => name, - None => continue, - }; acc.add_group( - &group, + &group_label, AssistId("auto_import", AssistKind::QuickFix), - format!("Import `{}`", name), + format!("Import `{}`", import.import_path), range, |builder| { let rewriter = @@ -126,7 +122,7 @@ pub(super) fn find_importable_node(ctx: &AssistContext) -> Option<(ImportAssets, } } -fn import_group_message(import_candidate: &ImportCandidate) -> GroupLabel { +fn group_label(import_candidate: &ImportCandidate) -> GroupLabel { let name = match import_candidate { ImportCandidate::Path(candidate) => format!("Import {}", candidate.name.text()), ImportCandidate::TraitAssocItem(candidate) => { diff --git a/crates/ide_assists/src/handlers/qualify_path.rs b/crates/ide_assists/src/handlers/qualify_path.rs index 272874ae39..30b23da6ca 100644 --- a/crates/ide_assists/src/handlers/qualify_path.rs +++ b/crates/ide_assists/src/handlers/qualify_path.rs @@ -3,7 +3,7 @@ use std::iter; use hir::AsAssocItem; use ide_db::helpers::{ import_assets::{ImportCandidate, LocatedImport}, - item_name, mod_path_to_ast, + mod_path_to_ast, }; use ide_db::RootDatabase; use syntax::{ @@ -78,7 +78,7 @@ pub(crate) fn qualify_path(acc: &mut Assists, ctx: &AssistContext) -> Option<()> acc.add_group( &group_label, AssistId("qualify_path", AssistKind::QuickFix), - label(ctx.db(), candidate, &import), + label(candidate, &import), range, |builder| { qualify_candidate.qualify( @@ -199,21 +199,17 @@ fn group_label(candidate: &ImportCandidate) -> GroupLabel { GroupLabel(format!("Qualify {}", name)) } -fn label(db: &RootDatabase, candidate: &ImportCandidate, import: &LocatedImport) -> String { - let display_path = match item_name(db, import.original_item) { - Some(display_path) => display_path.to_string(), - None => "{unknown}".to_string(), - }; +fn label(candidate: &ImportCandidate, import: &LocatedImport) -> String { match candidate { ImportCandidate::Path(candidate) => { if candidate.qualifier.is_some() { - format!("Qualify with `{}`", display_path) + format!("Qualify with `{}`", import.import_path) } else { - format!("Qualify as `{}`", display_path) + format!("Qualify as `{}`", import.import_path) } } - ImportCandidate::TraitAssocItem(_) => format!("Qualify `{}`", display_path), - ImportCandidate::TraitMethod(_) => format!("Qualify with cast as `{}`", display_path), + ImportCandidate::TraitAssocItem(_) => format!("Qualify `{}`", import.import_path), + ImportCandidate::TraitMethod(_) => format!("Qualify with cast as `{}`", import.import_path), } }