mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-30 23:27:24 +00:00
Add config to unconditionally prefer core imports over std
Fixes https://github.com/rust-lang/rust-analyzer/issues/12979
This commit is contained in:
parent
6909556435
commit
7d19971666
33 changed files with 156 additions and 43 deletions
|
@ -212,18 +212,20 @@ impl ImportAssets {
|
|||
&self,
|
||||
sema: &Semantics<'_, RootDatabase>,
|
||||
prefix_kind: PrefixKind,
|
||||
prefer_core: bool,
|
||||
) -> Vec<LocatedImport> {
|
||||
let _p = profile::span("import_assets::search_for_imports");
|
||||
self.search_for(sema, Some(prefix_kind))
|
||||
self.search_for(sema, Some(prefix_kind), prefer_core)
|
||||
}
|
||||
|
||||
/// 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>,
|
||||
prefer_core: bool,
|
||||
) -> Vec<LocatedImport> {
|
||||
let _p = profile::span("import_assets::search_for_relative_paths");
|
||||
self.search_for(sema, None)
|
||||
self.search_for(sema, None, prefer_core)
|
||||
}
|
||||
|
||||
pub fn path_fuzzy_name_to_exact(&mut self, case_sensitive: bool) {
|
||||
|
@ -242,6 +244,7 @@ impl ImportAssets {
|
|||
&self,
|
||||
sema: &Semantics<'_, RootDatabase>,
|
||||
prefixed: Option<PrefixKind>,
|
||||
prefer_core: bool,
|
||||
) -> Vec<LocatedImport> {
|
||||
let _p = profile::span("import_assets::search_for");
|
||||
|
||||
|
@ -252,6 +255,7 @@ impl ImportAssets {
|
|||
item_for_path_search(sema.db, item)?,
|
||||
&self.module_with_candidate,
|
||||
prefixed,
|
||||
prefer_core,
|
||||
)
|
||||
};
|
||||
|
||||
|
@ -564,11 +568,12 @@ fn get_mod_path(
|
|||
item_to_search: ItemInNs,
|
||||
module_with_candidate: &Module,
|
||||
prefixed: Option<PrefixKind>,
|
||||
prefer_core: bool,
|
||||
) -> Option<ModPath> {
|
||||
if let Some(prefix_kind) = prefixed {
|
||||
module_with_candidate.find_use_path_prefixed(db, item_to_search, prefix_kind)
|
||||
module_with_candidate.find_use_path_prefixed(db, item_to_search, prefix_kind, prefer_core)
|
||||
} else {
|
||||
module_with_candidate.find_use_path(db, item_to_search)
|
||||
module_with_candidate.find_use_path(db, item_to_search, prefer_core)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -173,6 +173,7 @@ impl<'a> Ctx<'a> {
|
|||
let found_path = self.target_module.find_use_path(
|
||||
self.source_scope.db.upcast(),
|
||||
hir::ModuleDef::Trait(trait_ref),
|
||||
false,
|
||||
)?;
|
||||
match ast::make::ty_path(mod_path_to_ast(&found_path)) {
|
||||
ast::Type::PathType(path_ty) => Some(path_ty),
|
||||
|
@ -209,7 +210,7 @@ impl<'a> Ctx<'a> {
|
|||
}
|
||||
|
||||
let found_path =
|
||||
self.target_module.find_use_path(self.source_scope.db.upcast(), def)?;
|
||||
self.target_module.find_use_path(self.source_scope.db.upcast(), def, false)?;
|
||||
let res = mod_path_to_ast(&found_path).clone_for_update();
|
||||
if let Some(args) = path.segment().and_then(|it| it.generic_arg_list()) {
|
||||
if let Some(segment) = res.segment() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue