From 5b7d928075f3bedf71f754444c1532976d52eae4 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Wed, 3 Mar 2021 23:59:56 +0200 Subject: Enforce the located imports' order --- crates/ide_assists/src/handlers/auto_import.rs | 2 +- crates/ide_assists/src/handlers/qualify_path.rs | 2 +- crates/ide_db/src/helpers/import_assets.rs | 11 +++++------ 3 files changed, 7 insertions(+), 8 deletions(-) (limited to 'crates') diff --git a/crates/ide_assists/src/handlers/auto_import.rs b/crates/ide_assists/src/handlers/auto_import.rs index f3c969eee..eb8d35e95 100644 --- a/crates/ide_assists/src/handlers/auto_import.rs +++ b/crates/ide_assists/src/handlers/auto_import.rs @@ -245,7 +245,7 @@ mod tests { } ", 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 407ba47be..b36dd3823 100644 --- a/crates/ide_assists/src/handlers/qualify_path.rs +++ b/crates/ide_assists/src/handlers/qualify_path.rs @@ -317,7 +317,7 @@ mod tests { } ", 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 b3e90717a..b78d1969d 100644 --- a/crates/ide_db/src/helpers/import_assets.rs +++ b/crates/ide_db/src/helpers/import_assets.rs @@ -3,6 +3,7 @@ use hir::{ 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 @@ impl<'a> ImportAssets<'a> { &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 @@ impl<'a> ImportAssets<'a> { &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 @@ impl<'a> ImportAssets<'a> { .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() } -- cgit v1.2.3