diff --git a/crates/ide_assists/src/handlers/auto_import.rs b/crates/ide_assists/src/handlers/auto_import.rs index f3c969eeeca..eb8d35e9576 100644 --- a/crates/ide_assists/src/handlers/auto_import.rs +++ b/crates/ide_assists/src/handlers/auto_import.rs @@ -245,7 +245,7 @@ pub mod PubMod3 { } ", r" - use PubMod1::PubStruct; + use PubMod3::PubStruct; PubStruct diff --git a/crates/ide_assists/src/handlers/qualify_path.rs b/crates/ide_assists/src/handlers/qualify_path.rs index 407ba47beab..b36dd382306 100644 --- a/crates/ide_assists/src/handlers/qualify_path.rs +++ b/crates/ide_assists/src/handlers/qualify_path.rs @@ -317,7 +317,7 @@ pub mod PubMod3 { } ", r" - PubMod1::PubStruct + PubMod3::PubStruct pub mod PubMod1 { pub struct PubStruct; diff --git a/crates/ide_db/src/helpers/import_assets.rs b/crates/ide_db/src/helpers/import_assets.rs index b3e90717a55..b78d1969d2e 100644 --- a/crates/ide_db/src/helpers/import_assets.rs +++ b/crates/ide_db/src/helpers/import_assets.rs @@ -3,6 +3,7 @@ AsAssocItem, AssocItem, AssocItemContainer, Crate, ItemInNs, MacroDef, ModPath, Module, ModuleDef, Name, PathResolution, PrefixKind, ScopeDef, Semantics, SemanticsScope, Type, }; +use itertools::Itertools; use rustc_hash::FxHashSet; use syntax::{ast, AstNode}; @@ -164,16 +165,13 @@ pub fn search_for_imports( &self, sema: &Semantics, prefix_kind: PrefixKind, - ) -> FxHashSet { + ) -> Vec { let _p = profile::span("import_assets::search_for_imports"); self.search_for(sema, Some(prefix_kind)) } /// This may return non-absolute paths if a part of the returned path is already imported into scope. - pub fn search_for_relative_paths( - &self, - sema: &Semantics, - ) -> FxHashSet { + pub fn search_for_relative_paths(&self, sema: &Semantics) -> Vec { let _p = profile::span("import_assets::search_for_relative_paths"); self.search_for(sema, None) } @@ -182,7 +180,7 @@ fn search_for( &self, sema: &Semantics, prefixed: Option, - ) -> FxHashSet { + ) -> Vec { let items_with_candidate_name = match self.name_to_import() { NameToImport::Exact(exact_name) => items_locator::with_for_exact_name( sema, @@ -216,6 +214,7 @@ fn search_for( .into_iter() .filter(|import| import.import_path.len() > 1) .filter(|import| !scope_definitions.contains(&ScopeDef::from(import.item_to_import))) + .sorted_by_key(|import| import.import_path.clone()) .collect() }