10114: fix: Deduplicate imports for qualify_path r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
bors[bot] 2021-09-01 19:53:10 +00:00 committed by GitHub
commit 48f84a7b60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View file

@ -89,12 +89,13 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()>
if proposed_imports.is_empty() { if proposed_imports.is_empty() {
return None; 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 range = ctx.sema.original_range(&syntax_under_caret).range;
let group_label = group_label(import_assets.import_candidate()); let group_label = group_label(import_assets.import_candidate());
let scope = ImportScope::find_insert_use_container_with_macros(&syntax_under_caret, &ctx.sema)?; 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 { for import in proposed_imports {
acc.add_group( acc.add_group(
&group_label, &group_label,

View file

@ -37,7 +37,7 @@ use crate::{
// ``` // ```
pub(crate) fn qualify_path(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { pub(crate) fn qualify_path(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
let (import_assets, syntax_under_caret) = find_importable_node(ctx)?; 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() { if proposed_imports.is_empty() {
return None; 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); let group_label = group_label(candidate);
for import in proposed_imports { for import in proposed_imports {
acc.add_group( acc.add_group(