aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_db/src
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2021-03-03 21:59:56 +0000
committerKirill Bulatov <[email protected]>2021-03-08 21:59:20 +0000
commit5b7d928075f3bedf71f754444c1532976d52eae4 (patch)
treed348d675ba5efbbe50e27b22971b3e14664cdc53 /crates/ide_db/src
parent24a5d3b19dfa3e076df8b7413d0cc4a547aeb7d7 (diff)
Enforce the located imports' order
Diffstat (limited to 'crates/ide_db/src')
-rw-r--r--crates/ide_db/src/helpers/import_assets.rs11
1 files changed, 5 insertions, 6 deletions
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::{
3 AsAssocItem, AssocItem, AssocItemContainer, Crate, ItemInNs, MacroDef, ModPath, Module, 3 AsAssocItem, AssocItem, AssocItemContainer, Crate, ItemInNs, MacroDef, ModPath, Module,
4 ModuleDef, Name, PathResolution, PrefixKind, ScopeDef, Semantics, SemanticsScope, Type, 4 ModuleDef, Name, PathResolution, PrefixKind, ScopeDef, Semantics, SemanticsScope, Type,
5}; 5};
6use itertools::Itertools;
6use rustc_hash::FxHashSet; 7use rustc_hash::FxHashSet;
7use syntax::{ast, AstNode}; 8use syntax::{ast, AstNode};
8 9
@@ -164,16 +165,13 @@ impl<'a> ImportAssets<'a> {
164 &self, 165 &self,
165 sema: &Semantics<RootDatabase>, 166 sema: &Semantics<RootDatabase>,
166 prefix_kind: PrefixKind, 167 prefix_kind: PrefixKind,
167 ) -> FxHashSet<LocatedImport> { 168 ) -> Vec<LocatedImport> {
168 let _p = profile::span("import_assets::search_for_imports"); 169 let _p = profile::span("import_assets::search_for_imports");
169 self.search_for(sema, Some(prefix_kind)) 170 self.search_for(sema, Some(prefix_kind))
170 } 171 }
171 172
172 /// This may return non-absolute paths if a part of the returned path is already imported into scope. 173 /// This may return non-absolute paths if a part of the returned path is already imported into scope.
173 pub fn search_for_relative_paths( 174 pub fn search_for_relative_paths(&self, sema: &Semantics<RootDatabase>) -> Vec<LocatedImport> {
174 &self,
175 sema: &Semantics<RootDatabase>,
176 ) -> FxHashSet<LocatedImport> {
177 let _p = profile::span("import_assets::search_for_relative_paths"); 175 let _p = profile::span("import_assets::search_for_relative_paths");
178 self.search_for(sema, None) 176 self.search_for(sema, None)
179 } 177 }
@@ -182,7 +180,7 @@ impl<'a> ImportAssets<'a> {
182 &self, 180 &self,
183 sema: &Semantics<RootDatabase>, 181 sema: &Semantics<RootDatabase>,
184 prefixed: Option<PrefixKind>, 182 prefixed: Option<PrefixKind>,
185 ) -> FxHashSet<LocatedImport> { 183 ) -> Vec<LocatedImport> {
186 let items_with_candidate_name = match self.name_to_import() { 184 let items_with_candidate_name = match self.name_to_import() {
187 NameToImport::Exact(exact_name) => items_locator::with_for_exact_name( 185 NameToImport::Exact(exact_name) => items_locator::with_for_exact_name(
188 sema, 186 sema,
@@ -216,6 +214,7 @@ impl<'a> ImportAssets<'a> {
216 .into_iter() 214 .into_iter()
217 .filter(|import| import.import_path.len() > 1) 215 .filter(|import| import.import_path.len() > 1)
218 .filter(|import| !scope_definitions.contains(&ScopeDef::from(import.item_to_import))) 216 .filter(|import| !scope_definitions.contains(&ScopeDef::from(import.item_to_import)))
217 .sorted_by_key(|import| import.import_path.clone())
219 .collect() 218 .collect()
220 } 219 }
221 220