From 8e8ea537ab669aaad17a246073eeec65b3e73edb Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 1 Sep 2021 21:51:28 +0200 Subject: [PATCH] Deduplicate imports for qualify_path --- crates/ide_assists/src/handlers/auto_import.rs | 5 +++-- crates/ide_assists/src/handlers/qualify_path.rs | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/ide_assists/src/handlers/auto_import.rs b/crates/ide_assists/src/handlers/auto_import.rs index 7112dd65a1a..1ec3932a2d0 100644 --- a/crates/ide_assists/src/handlers/auto_import.rs +++ b/crates/ide_assists/src/handlers/auto_import.rs @@ -89,12 +89,13 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()> if proposed_imports.is_empty() { return None; } - // we aren't interested in different namespaces - proposed_imports.dedup_by(|a, b| a.import_path == b.import_path); let range = ctx.sema.original_range(&syntax_under_caret).range; let group_label = group_label(import_assets.import_candidate()); let scope = ImportScope::find_insert_use_container_with_macros(&syntax_under_caret, &ctx.sema)?; + + // we aren't interested in different namespaces + proposed_imports.dedup_by(|a, b| a.import_path == b.import_path); for import in proposed_imports { acc.add_group( &group_label, diff --git a/crates/ide_assists/src/handlers/qualify_path.rs b/crates/ide_assists/src/handlers/qualify_path.rs index 28d7f3a346c..2510eae9714 100644 --- a/crates/ide_assists/src/handlers/qualify_path.rs +++ b/crates/ide_assists/src/handlers/qualify_path.rs @@ -37,7 +37,7 @@ // ``` pub(crate) fn qualify_path(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { let (import_assets, syntax_under_caret) = find_importable_node(ctx)?; - let proposed_imports = import_assets.search_for_relative_paths(&ctx.sema); + let mut proposed_imports = import_assets.search_for_relative_paths(&ctx.sema); if proposed_imports.is_empty() { return None; } @@ -70,6 +70,9 @@ pub(crate) fn qualify_path(acc: &mut Assists, ctx: &AssistContext) -> Option<()> } }; + // we aren't interested in different namespaces + proposed_imports.dedup_by(|a, b| a.import_path == b.import_path); + let group_label = group_label(candidate); for import in proposed_imports { acc.add_group(