Skip to content

Commit 5b7d928

Browse files
Enforce the located imports' order
1 parent 24a5d3b commit 5b7d928

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

crates/ide_assists/src/handlers/auto_import.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ mod tests {
245245
}
246246
",
247247
r"
248-
use PubMod1::PubStruct;
248+
use PubMod3::PubStruct;
249249
250250
PubStruct
251251

crates/ide_assists/src/handlers/qualify_path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ mod tests {
317317
}
318318
",
319319
r"
320-
PubMod1::PubStruct
320+
PubMod3::PubStruct
321321
322322
pub mod PubMod1 {
323323
pub struct PubStruct;

crates/ide_db/src/helpers/import_assets.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use hir::{
33
AsAssocItem, AssocItem, AssocItemContainer, Crate, ItemInNs, MacroDef, ModPath, Module,
44
ModuleDef, Name, PathResolution, PrefixKind, ScopeDef, Semantics, SemanticsScope, Type,
55
};
6+
use itertools::Itertools;
67
use rustc_hash::FxHashSet;
78
use syntax::{ast, AstNode};
89

@@ -164,16 +165,13 @@ impl<'a> ImportAssets<'a> {
164165
&self,
165166
sema: &Semantics<RootDatabase>,
166167
prefix_kind: PrefixKind,
167-
) -> FxHashSet<LocatedImport> {
168+
) -> Vec<LocatedImport> {
168169
let _p = profile::span("import_assets::search_for_imports");
169170
self.search_for(sema, Some(prefix_kind))
170171
}
171172

172173
/// 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-
&self,
175-
sema: &Semantics<RootDatabase>,
176-
) -> FxHashSet<LocatedImport> {
174+
pub fn search_for_relative_paths(&self, sema: &Semantics<RootDatabase>) -> Vec<LocatedImport> {
177175
let _p = profile::span("import_assets::search_for_relative_paths");
178176
self.search_for(sema, None)
179177
}
@@ -182,7 +180,7 @@ impl<'a> ImportAssets<'a> {
182180
&self,
183181
sema: &Semantics<RootDatabase>,
184182
prefixed: Option<PrefixKind>,
185-
) -> FxHashSet<LocatedImport> {
183+
) -> Vec<LocatedImport> {
186184
let items_with_candidate_name = match self.name_to_import() {
187185
NameToImport::Exact(exact_name) => items_locator::with_for_exact_name(
188186
sema,
@@ -216,6 +214,7 @@ impl<'a> ImportAssets<'a> {
216214
.into_iter()
217215
.filter(|import| import.import_path.len() > 1)
218216
.filter(|import| !scope_definitions.contains(&ScopeDef::from(import.item_to_import)))
217+
.sorted_by_key(|import| import.import_path.clone())
219218
.collect()
220219
}
221220

0 commit comments

Comments
 (0)