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_db/src/helpers/import_assets.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'crates/ide_db/src') 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