Enforce the located imports' order
This commit is contained in:
parent
24a5d3b19d
commit
5b7d928075
@ -245,7 +245,7 @@ pub mod PubMod3 {
|
||||
}
|
||||
",
|
||||
r"
|
||||
use PubMod1::PubStruct;
|
||||
use PubMod3::PubStruct;
|
||||
|
||||
PubStruct
|
||||
|
||||
|
@ -317,7 +317,7 @@ pub mod PubMod3 {
|
||||
}
|
||||
",
|
||||
r"
|
||||
PubMod1::PubStruct
|
||||
PubMod3::PubStruct
|
||||
|
||||
pub mod PubMod1 {
|
||||
pub struct PubStruct;
|
||||
|
@ -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<RootDatabase>,
|
||||
prefix_kind: PrefixKind,
|
||||
) -> FxHashSet<LocatedImport> {
|
||||
) -> Vec<LocatedImport> {
|
||||
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<RootDatabase>,
|
||||
) -> FxHashSet<LocatedImport> {
|
||||
pub fn search_for_relative_paths(&self, sema: &Semantics<RootDatabase>) -> Vec<LocatedImport> {
|
||||
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<RootDatabase>,
|
||||
prefixed: Option<PrefixKind>,
|
||||
) -> FxHashSet<LocatedImport> {
|
||||
) -> Vec<LocatedImport> {
|
||||
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()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user