mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-31 07:37:30 +00:00
Merge f948726b7d
into 67a58fdfeb
This commit is contained in:
commit
afef9f8beb
36 changed files with 143 additions and 100 deletions
|
@ -12,7 +12,7 @@ use intern::sym;
|
|||
use rustc_hash::FxHashSet;
|
||||
|
||||
use crate::{
|
||||
ImportPathConfig, ModuleDefId, ModuleId,
|
||||
FindPathConfig, ModuleDefId, ModuleId,
|
||||
db::DefDatabase,
|
||||
item_scope::ItemInNs,
|
||||
nameres::DefMap,
|
||||
|
@ -27,7 +27,7 @@ pub fn find_path(
|
|||
from: ModuleId,
|
||||
mut prefix_kind: PrefixKind,
|
||||
ignore_local_imports: bool,
|
||||
mut cfg: ImportPathConfig,
|
||||
mut cfg: FindPathConfig,
|
||||
) -> Option<ModPath> {
|
||||
let _p = tracing::info_span!("find_path").entered();
|
||||
|
||||
|
@ -96,7 +96,7 @@ impl PrefixKind {
|
|||
struct FindPathCtx<'db> {
|
||||
db: &'db dyn DefDatabase,
|
||||
prefix: PrefixKind,
|
||||
cfg: ImportPathConfig,
|
||||
cfg: FindPathConfig,
|
||||
ignore_local_imports: bool,
|
||||
is_std_item: bool,
|
||||
from: ModuleId,
|
||||
|
@ -718,7 +718,7 @@ mod tests {
|
|||
module,
|
||||
prefix,
|
||||
ignore_local_imports,
|
||||
ImportPathConfig { prefer_no_std, prefer_prelude, prefer_absolute, allow_unstable },
|
||||
FindPathConfig { prefer_no_std, prefer_prelude, prefer_absolute, allow_unstable },
|
||||
);
|
||||
format_to!(
|
||||
res,
|
||||
|
|
|
@ -101,7 +101,7 @@ use crate::{
|
|||
type FxIndexMap<K, V> = indexmap::IndexMap<K, V, rustc_hash::FxBuildHasher>;
|
||||
/// A wrapper around three booleans
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Copy)]
|
||||
pub struct ImportPathConfig {
|
||||
pub struct FindPathConfig {
|
||||
/// If true, prefer to unconditionally use imports of the `core` and `alloc` crate
|
||||
/// over the std.
|
||||
pub prefer_no_std: bool,
|
||||
|
|
|
@ -11,7 +11,7 @@ use base_db::Crate;
|
|||
use chalk_ir::{BoundVar, Safety, TyKind};
|
||||
use either::Either;
|
||||
use hir_def::{
|
||||
GeneralConstId, GenericDefId, HasModule, ImportPathConfig, LocalFieldId, Lookup, ModuleDefId,
|
||||
GeneralConstId, GenericDefId, HasModule, FindPathConfig, LocalFieldId, Lookup, ModuleDefId,
|
||||
ModuleId, TraitId,
|
||||
db::DefDatabase,
|
||||
expr_store::{ExpressionStore, path::Path},
|
||||
|
@ -1433,7 +1433,7 @@ impl<'db> HirDisplay for crate::next_solver::Ty<'db> {
|
|||
PrefixKind::Plain,
|
||||
false,
|
||||
// FIXME: no_std Cfg?
|
||||
ImportPathConfig {
|
||||
FindPathConfig {
|
||||
prefer_no_std: false,
|
||||
prefer_prelude: true,
|
||||
prefer_absolute: false,
|
||||
|
|
|
@ -130,7 +130,7 @@ pub use {
|
|||
cfg::{CfgAtom, CfgExpr, CfgOptions},
|
||||
hir_def::{
|
||||
Complete,
|
||||
ImportPathConfig,
|
||||
FindPathConfig,
|
||||
attr::{AttrSourceMap, Attrs, AttrsWithOwner},
|
||||
find_path::PrefixKind,
|
||||
import_map,
|
||||
|
@ -957,7 +957,7 @@ impl Module {
|
|||
self,
|
||||
db: &dyn DefDatabase,
|
||||
item: impl Into<ItemInNs>,
|
||||
cfg: ImportPathConfig,
|
||||
cfg: FindPathConfig,
|
||||
) -> Option<ModPath> {
|
||||
hir_def::find_path::find_path(
|
||||
db,
|
||||
|
@ -976,7 +976,7 @@ impl Module {
|
|||
db: &dyn DefDatabase,
|
||||
item: impl Into<ItemInNs>,
|
||||
prefix_kind: PrefixKind,
|
||||
cfg: ImportPathConfig,
|
||||
cfg: FindPathConfig,
|
||||
) -> Option<ModPath> {
|
||||
hir_def::find_path::find_path(db, item.into().into(), self.into(), prefix_kind, true, cfg)
|
||||
}
|
||||
|
|
|
@ -302,6 +302,13 @@ impl<DB: HirDatabase + ?Sized> Semantics<'_, DB> {
|
|||
self.imp.hir_file_to_module_defs(file.into())
|
||||
}
|
||||
|
||||
pub fn is_nightly(&self, krate: Crate) -> bool {
|
||||
let toolchain = self.db.toolchain_channel(krate.into());
|
||||
// `toolchain == None` means we're in some detached files. Since we have no information on
|
||||
// the toolchain being used, let's just allow unstable items to be listed.
|
||||
matches!(toolchain, Some(base_db::ReleaseChannel::Nightly) | None)
|
||||
}
|
||||
|
||||
pub fn to_adt_def(&self, a: &ast::Adt) -> Option<Adt> {
|
||||
self.imp.to_def(a)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//! Type tree for term search
|
||||
|
||||
use hir_def::ImportPathConfig;
|
||||
use hir_def::FindPathConfig;
|
||||
use hir_expand::mod_path::ModPath;
|
||||
use hir_ty::{
|
||||
db::HirDatabase,
|
||||
|
@ -18,7 +18,7 @@ use crate::{
|
|||
fn mod_item_path(
|
||||
sema_scope: &SemanticsScope<'_>,
|
||||
def: &ModuleDef,
|
||||
cfg: ImportPathConfig,
|
||||
cfg: FindPathConfig,
|
||||
) -> Option<ModPath> {
|
||||
let db = sema_scope.db;
|
||||
let m = sema_scope.module();
|
||||
|
@ -29,7 +29,7 @@ fn mod_item_path(
|
|||
fn mod_item_path_str(
|
||||
sema_scope: &SemanticsScope<'_>,
|
||||
def: &ModuleDef,
|
||||
cfg: ImportPathConfig,
|
||||
cfg: FindPathConfig,
|
||||
edition: Edition,
|
||||
) -> Result<String, DisplaySourceCodeError> {
|
||||
let path = mod_item_path(sema_scope, def, cfg);
|
||||
|
@ -103,7 +103,7 @@ impl<'db> Expr<'db> {
|
|||
&self,
|
||||
sema_scope: &SemanticsScope<'db>,
|
||||
many_formatter: &mut dyn FnMut(&Type<'db>) -> String,
|
||||
cfg: ImportPathConfig,
|
||||
cfg: FindPathConfig,
|
||||
display_target: DisplayTarget,
|
||||
) -> Result<String, DisplaySourceCodeError> {
|
||||
let db = sema_scope.db;
|
||||
|
@ -380,7 +380,7 @@ impl<'db> Expr<'db> {
|
|||
fn container_name(
|
||||
container: AssocItemContainer,
|
||||
sema_scope: &SemanticsScope<'_>,
|
||||
cfg: ImportPathConfig,
|
||||
cfg: FindPathConfig,
|
||||
edition: Edition,
|
||||
display_target: DisplayTarget,
|
||||
) -> Result<String, DisplaySourceCodeError> {
|
||||
|
|
|
@ -4,8 +4,12 @@
|
|||
//! module, and we use to statically check that we only produce snippet
|
||||
//! assists if we are allowed to.
|
||||
|
||||
use hir::ImportPathConfig;
|
||||
use ide_db::{SnippetCap, assists::ExprFillDefaultMode, imports::insert_use::InsertUseConfig};
|
||||
use hir::FindPathConfig;
|
||||
use ide_db::{
|
||||
SnippetCap,
|
||||
assists::ExprFillDefaultMode,
|
||||
imports::{import_assets::ImportPathConfig, insert_use::InsertUseConfig},
|
||||
};
|
||||
|
||||
use crate::AssistKind;
|
||||
|
||||
|
@ -31,7 +35,15 @@ impl AssistConfig {
|
|||
prefer_no_std: self.prefer_no_std,
|
||||
prefer_prelude: self.prefer_prelude,
|
||||
prefer_absolute: self.prefer_absolute,
|
||||
allow_unstable: true,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn find_path_confg(&self, allow_unstable: bool) -> FindPathConfig {
|
||||
FindPathConfig {
|
||||
prefer_no_std: self.prefer_no_std,
|
||||
prefer_prelude: self.prefer_prelude,
|
||||
prefer_absolute: self.prefer_absolute,
|
||||
allow_unstable,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::iter::{self, Peekable};
|
||||
|
||||
use either::Either;
|
||||
use hir::{Adt, AsAssocItem, Crate, HasAttrs, ImportPathConfig, ModuleDef, Semantics, sym};
|
||||
use hir::{Adt, AsAssocItem, Crate, FindPathConfig, HasAttrs, ModuleDef, Semantics, sym};
|
||||
use ide_db::RootDatabase;
|
||||
use ide_db::assists::ExprFillDefaultMode;
|
||||
use ide_db::syntax_helpers::suggest_name;
|
||||
|
@ -76,12 +76,11 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
|
|||
.filter(|pat| !matches!(pat, Pat::WildcardPat(_)))
|
||||
.collect();
|
||||
|
||||
let cfg = ctx.config.import_path_config();
|
||||
|
||||
let make = SyntaxFactory::with_mappings();
|
||||
|
||||
let scope = ctx.sema.scope(expr.syntax())?;
|
||||
let module = scope.module();
|
||||
let cfg = ctx.config.find_path_confg(ctx.sema.is_nightly(scope.krate()));
|
||||
let self_ty = if ctx.config.prefer_self_ty {
|
||||
scope
|
||||
.containing_function()
|
||||
|
@ -498,7 +497,7 @@ fn build_pat(
|
|||
make: &SyntaxFactory,
|
||||
module: hir::Module,
|
||||
var: ExtendedVariant,
|
||||
cfg: ImportPathConfig,
|
||||
cfg: FindPathConfig,
|
||||
) -> Option<ast::Pat> {
|
||||
let db = ctx.db();
|
||||
match var {
|
||||
|
|
|
@ -329,8 +329,6 @@ fn augment_references_with_imports(
|
|||
) -> Vec<FileReferenceWithImport> {
|
||||
let mut visited_modules = FxHashSet::default();
|
||||
|
||||
let cfg = ctx.config.import_path_config();
|
||||
|
||||
let edition = target_module.krate().edition(ctx.db());
|
||||
references
|
||||
.into_iter()
|
||||
|
@ -345,22 +343,27 @@ fn augment_references_with_imports(
|
|||
{
|
||||
visited_modules.insert(ref_module);
|
||||
|
||||
let import_scope = ImportScope::find_insert_use_container(name.syntax(), &ctx.sema);
|
||||
let path = ref_module
|
||||
.find_use_path(
|
||||
ctx.sema.db,
|
||||
ModuleDef::Module(*target_module),
|
||||
ctx.config.insert_use.prefix_kind,
|
||||
cfg,
|
||||
)
|
||||
.map(|mod_path| {
|
||||
make::path_concat(
|
||||
mod_path_to_ast(&mod_path, edition),
|
||||
make::path_from_text("Bool"),
|
||||
)
|
||||
});
|
||||
ImportScope::find_insert_use_container(name.syntax(), &ctx.sema).and_then(
|
||||
|import_scope| {
|
||||
let cfg =
|
||||
ctx.config.find_path_confg(ctx.sema.is_nightly(target_module.krate()));
|
||||
let path = ref_module
|
||||
.find_use_path(
|
||||
ctx.sema.db,
|
||||
ModuleDef::Module(*target_module),
|
||||
ctx.config.insert_use.prefix_kind,
|
||||
cfg,
|
||||
)
|
||||
.map(|mod_path| {
|
||||
make::path_concat(
|
||||
mod_path_to_ast(&mod_path, edition),
|
||||
make::path_from_text("Bool"),
|
||||
)
|
||||
})?;
|
||||
|
||||
import_scope.zip(path)
|
||||
Some((import_scope, path))
|
||||
},
|
||||
)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
|
|
@ -43,7 +43,7 @@ pub(crate) fn convert_into_to_from(acc: &mut Assists, ctx: &AssistContext<'_>) -
|
|||
return None;
|
||||
}
|
||||
|
||||
let cfg = ctx.config.import_path_config();
|
||||
let cfg = ctx.config.find_path_confg(ctx.sema.is_nightly(module.krate()));
|
||||
|
||||
let src_type_path = {
|
||||
let src_type_path = src_type.syntax().descendants().find_map(ast::Path::cast)?;
|
||||
|
|
|
@ -184,8 +184,6 @@ fn augment_references_with_imports(
|
|||
) -> Vec<(ast::NameLike, Option<(ImportScope, ast::Path)>)> {
|
||||
let mut visited_modules = FxHashSet::default();
|
||||
|
||||
let cfg = ctx.config.import_path_config();
|
||||
|
||||
references
|
||||
.iter()
|
||||
.filter_map(|FileReference { name, .. }| {
|
||||
|
@ -201,6 +199,7 @@ fn augment_references_with_imports(
|
|||
{
|
||||
visited_modules.insert(ref_module);
|
||||
|
||||
let cfg = ctx.config.find_path_confg(ctx.sema.is_nightly(ref_module.krate()));
|
||||
let import_scope =
|
||||
ImportScope::find_insert_use_container(new_name.syntax(), &ctx.sema);
|
||||
let path = ref_module
|
||||
|
|
|
@ -86,9 +86,8 @@ fn collect_data(ident_pat: ast::IdentPat, ctx: &AssistContext<'_>) -> Option<Str
|
|||
let ty = ctx.sema.type_of_binding_in_pat(&ident_pat)?;
|
||||
let hir::Adt::Struct(struct_type) = ty.strip_references().as_adt()? else { return None };
|
||||
|
||||
let cfg = ctx.config.import_path_config();
|
||||
|
||||
let module = ctx.sema.scope(ident_pat.syntax())?.module();
|
||||
let cfg = ctx.config.find_path_confg(ctx.sema.is_nightly(module.krate()));
|
||||
let struct_def = hir::ModuleDef::from(struct_type);
|
||||
let kind = struct_type.kind(ctx.db());
|
||||
let struct_def_path = module.find_path(ctx.db(), struct_def, cfg)?;
|
||||
|
|
|
@ -209,11 +209,12 @@ pub(crate) fn extract_function(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
|
|||
FamousDefs(&ctx.sema, module.krate()).core_ops_ControlFlow();
|
||||
|
||||
if let Some(control_flow_enum) = control_flow_enum {
|
||||
let cfg = ctx.config.find_path_confg(ctx.sema.is_nightly(module.krate()));
|
||||
let mod_path = module.find_use_path(
|
||||
ctx.sema.db,
|
||||
ModuleDef::from(control_flow_enum),
|
||||
ctx.config.insert_use.prefix_kind,
|
||||
ctx.config.import_path_config(),
|
||||
cfg,
|
||||
);
|
||||
|
||||
if let Some(mod_path) = mod_path {
|
||||
|
|
|
@ -400,11 +400,12 @@ fn process_references(
|
|||
let segment = builder.make_mut(segment);
|
||||
let scope_node = builder.make_syntax_mut(scope_node);
|
||||
if !visited_modules.contains(&module) {
|
||||
let cfg = ctx.config.find_path_confg(ctx.sema.is_nightly(module.krate()));
|
||||
let mod_path = module.find_use_path(
|
||||
ctx.sema.db,
|
||||
*enum_module_def,
|
||||
ctx.config.insert_use.prefix_kind,
|
||||
ctx.config.import_path_config(),
|
||||
cfg,
|
||||
);
|
||||
if let Some(mut mod_path) = mod_path {
|
||||
mod_path.pop_segment();
|
||||
|
|
|
@ -57,9 +57,9 @@ fn generate_record_deref(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<(
|
|||
};
|
||||
|
||||
let module = ctx.sema.to_def(&strukt)?.module(ctx.db());
|
||||
let cfg = ctx.config.find_path_confg(ctx.sema.is_nightly(module.krate()));
|
||||
let trait_ = deref_type_to_generate.to_trait(&ctx.sema, module.krate())?;
|
||||
let trait_path =
|
||||
module.find_path(ctx.db(), ModuleDef::Trait(trait_), ctx.config.import_path_config())?;
|
||||
let trait_path = module.find_path(ctx.db(), ModuleDef::Trait(trait_), cfg)?;
|
||||
|
||||
let field_type = field.ty()?;
|
||||
let field_name = field.name()?;
|
||||
|
@ -99,9 +99,9 @@ fn generate_tuple_deref(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<()
|
|||
};
|
||||
|
||||
let module = ctx.sema.to_def(&strukt)?.module(ctx.db());
|
||||
let cfg = ctx.config.find_path_confg(ctx.sema.is_nightly(module.krate()));
|
||||
let trait_ = deref_type_to_generate.to_trait(&ctx.sema, module.krate())?;
|
||||
let trait_path =
|
||||
module.find_path(ctx.db(), ModuleDef::Trait(trait_), ctx.config.import_path_config())?;
|
||||
let trait_path = module.find_path(ctx.db(), ModuleDef::Trait(trait_), cfg)?;
|
||||
|
||||
let field_type = field.ty()?;
|
||||
let target = field.syntax().text_range();
|
||||
|
|
|
@ -77,10 +77,11 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
|
|||
|
||||
let item_in_ns = hir::ItemInNs::from(hir::ModuleDef::from(ty.as_adt()?));
|
||||
|
||||
let cfg = ctx.config.find_path_confg(ctx.sema.is_nightly(current_module.krate()));
|
||||
let type_path = current_module.find_path(
|
||||
ctx.sema.db,
|
||||
item_for_path_search(ctx.sema.db, item_in_ns)?,
|
||||
ctx.config.import_path_config(),
|
||||
cfg,
|
||||
)?;
|
||||
|
||||
let edition = current_module.krate().edition(ctx.db());
|
||||
|
|
|
@ -169,6 +169,7 @@ fn make_constructors(
|
|||
types: &[ast::Type],
|
||||
) -> Vec<Option<ast::Expr>> {
|
||||
let (db, sema) = (ctx.db(), &ctx.sema);
|
||||
let cfg = ctx.config.find_path_confg(ctx.sema.is_nightly(module.krate()));
|
||||
types
|
||||
.iter()
|
||||
.map(|ty| {
|
||||
|
@ -179,11 +180,7 @@ fn make_constructors(
|
|||
let item_in_ns = ModuleDef::Adt(ty.as_adt()?).into();
|
||||
let edition = module.krate().edition(db);
|
||||
|
||||
let ty_path = module.find_path(
|
||||
db,
|
||||
item_for_path_search(db, item_in_ns)?,
|
||||
ctx.config.import_path_config(),
|
||||
)?;
|
||||
let ty_path = module.find_path(db, item_for_path_search(db, item_in_ns)?, cfg)?;
|
||||
|
||||
use_trivial_constructor(db, mod_path_to_ast(&ty_path, edition), &ty, edition)
|
||||
})
|
||||
|
|
|
@ -45,10 +45,11 @@ pub(crate) fn qualify_method_call(acc: &mut Assists, ctx: &AssistContext<'_>) ->
|
|||
let current_edition = current_module.krate().edition(ctx.db());
|
||||
let target_module_def = ModuleDef::from(resolved_call);
|
||||
let item_in_ns = ItemInNs::from(target_module_def);
|
||||
let cfg = ctx.config.find_path_confg(ctx.sema.is_nightly(current_module.krate()));
|
||||
let receiver_path = current_module.find_path(
|
||||
ctx.sema.db,
|
||||
item_for_path_search(ctx.sema.db, item_in_ns)?,
|
||||
ctx.config.import_path_config(),
|
||||
cfg,
|
||||
)?;
|
||||
|
||||
let qualify_candidate = QualifyCandidate::ImplMethod(ctx.sema.db, call, resolved_call);
|
||||
|
|
|
@ -71,6 +71,7 @@ pub(crate) fn replace_derive_with_manual_impl(
|
|||
let current_module = ctx.sema.scope(adt.syntax())?.module();
|
||||
let current_crate = current_module.krate();
|
||||
let current_edition = current_crate.edition(ctx.db());
|
||||
let cfg = ctx.config.find_path_confg(ctx.sema.is_nightly(current_crate));
|
||||
|
||||
let found_traits = items_locator::items_with_name(
|
||||
ctx.db(),
|
||||
|
@ -84,7 +85,7 @@ pub(crate) fn replace_derive_with_manual_impl(
|
|||
})
|
||||
.flat_map(|trait_| {
|
||||
current_module
|
||||
.find_path(ctx.sema.db, hir::ModuleDef::Trait(trait_), ctx.config.import_path_config())
|
||||
.find_path(ctx.sema.db, hir::ModuleDef::Trait(trait_), cfg)
|
||||
.as_ref()
|
||||
.map(|path| mod_path_to_ast(path, current_edition))
|
||||
.zip(Some(trait_))
|
||||
|
|
|
@ -63,12 +63,9 @@ pub(crate) fn replace_qualified_name_with_use(
|
|||
);
|
||||
let path_to_qualifier = starts_with_name_ref
|
||||
.then(|| {
|
||||
ctx.sema.scope(original_path.syntax())?.module().find_use_path(
|
||||
ctx.sema.db,
|
||||
module,
|
||||
ctx.config.insert_use.prefix_kind,
|
||||
ctx.config.import_path_config(),
|
||||
)
|
||||
let mod_ = ctx.sema.scope(original_path.syntax())?.module();
|
||||
let cfg = ctx.config.find_path_confg(ctx.sema.is_nightly(mod_.krate()));
|
||||
mod_.find_use_path(ctx.sema.db, module, ctx.config.insert_use.prefix_kind, cfg)
|
||||
})
|
||||
.flatten();
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ pub(crate) fn term_search(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<
|
|||
path.gen_source_code(
|
||||
&scope,
|
||||
&mut formatter,
|
||||
ctx.config.import_path_config(),
|
||||
ctx.config.find_path_confg(ctx.sema.is_nightly(scope.module().krate())),
|
||||
scope.krate().to_display_target(ctx.db()),
|
||||
)
|
||||
.ok()
|
||||
|
|
|
@ -132,12 +132,9 @@ pub(crate) fn desugar_async_into_impl_future(
|
|||
|
||||
let scope = ctx.sema.scope(function.syntax())?;
|
||||
let module = scope.module();
|
||||
let cfg = ctx.config.find_path_confg(ctx.sema.is_nightly(module.krate()));
|
||||
let future_trait = FamousDefs(&ctx.sema, scope.krate()).core_future_Future()?;
|
||||
let trait_path = module.find_path(
|
||||
ctx.db(),
|
||||
ModuleDef::Trait(future_trait),
|
||||
ctx.config.import_path_config(),
|
||||
)?;
|
||||
let trait_path = module.find_path(ctx.db(), ModuleDef::Trait(future_trait), cfg)?;
|
||||
let edition = scope.krate().edition(ctx.db());
|
||||
let trait_path = trait_path.display(ctx.db(), edition);
|
||||
|
||||
|
|
|
@ -654,7 +654,7 @@ fn enum_variants_with_paths(
|
|||
if let Some(path) = ctx.module.find_path(
|
||||
ctx.db,
|
||||
hir::ModuleDef::from(variant),
|
||||
ctx.config.import_path_config(ctx.is_nightly),
|
||||
ctx.config.find_path_config(ctx.is_nightly),
|
||||
) {
|
||||
// Variants with trivial paths are already added by the existing completion logic,
|
||||
// so we should avoid adding these twice
|
||||
|
|
|
@ -254,7 +254,7 @@ pub(crate) fn complete_expr_path(
|
|||
.find_path(
|
||||
ctx.db,
|
||||
hir::ModuleDef::from(strukt),
|
||||
ctx.config.import_path_config(ctx.is_nightly),
|
||||
ctx.config.find_path_config(ctx.is_nightly),
|
||||
)
|
||||
.filter(|it| it.len() > 1);
|
||||
|
||||
|
@ -276,7 +276,7 @@ pub(crate) fn complete_expr_path(
|
|||
.find_path(
|
||||
ctx.db,
|
||||
hir::ModuleDef::from(un),
|
||||
ctx.config.import_path_config(ctx.is_nightly),
|
||||
ctx.config.find_path_config(ctx.is_nightly),
|
||||
)
|
||||
.filter(|it| it.len() > 1);
|
||||
|
||||
|
|
|
@ -257,7 +257,7 @@ fn import_on_the_fly(
|
|||
};
|
||||
let user_input_lowercased = potential_import_name.to_lowercase();
|
||||
|
||||
let import_cfg = ctx.config.import_path_config(ctx.is_nightly);
|
||||
let import_cfg = ctx.config.import_path_config();
|
||||
|
||||
import_assets
|
||||
.search_for_imports(&ctx.sema, import_cfg, ctx.config.insert_use.prefix_kind)
|
||||
|
@ -304,7 +304,7 @@ fn import_on_the_fly_pat_(
|
|||
ItemInNs::Values(def) => matches!(def, hir::ModuleDef::Const(_)),
|
||||
};
|
||||
let user_input_lowercased = potential_import_name.to_lowercase();
|
||||
let cfg = ctx.config.import_path_config(ctx.is_nightly);
|
||||
let cfg = ctx.config.import_path_config();
|
||||
|
||||
import_assets
|
||||
.search_for_imports(&ctx.sema, cfg, ctx.config.insert_use.prefix_kind)
|
||||
|
@ -346,7 +346,7 @@ fn import_on_the_fly_method(
|
|||
|
||||
let user_input_lowercased = potential_import_name.to_lowercase();
|
||||
|
||||
let cfg = ctx.config.import_path_config(ctx.is_nightly);
|
||||
let cfg = ctx.config.import_path_config();
|
||||
|
||||
import_assets
|
||||
.search_for_imports(&ctx.sema, cfg, ctx.config.insert_use.prefix_kind)
|
||||
|
|
|
@ -63,7 +63,7 @@ pub(crate) fn complete_postfix(
|
|||
None => return,
|
||||
};
|
||||
|
||||
let cfg = ctx.config.import_path_config(ctx.is_nightly);
|
||||
let cfg = ctx.config.find_path_config(ctx.is_nightly);
|
||||
|
||||
if let Some(drop_trait) = ctx.famous_defs().core_ops_Drop()
|
||||
&& receiver_ty.impls_trait(ctx.db, drop_trait, &[])
|
||||
|
|
|
@ -4,8 +4,11 @@
|
|||
//! module, and we use to statically check that we only produce snippet
|
||||
//! completions if we are allowed to.
|
||||
|
||||
use hir::ImportPathConfig;
|
||||
use ide_db::{SnippetCap, imports::insert_use::InsertUseConfig};
|
||||
use hir::FindPathConfig;
|
||||
use ide_db::{
|
||||
SnippetCap,
|
||||
imports::{import_assets::ImportPathConfig, insert_use::InsertUseConfig},
|
||||
};
|
||||
|
||||
use crate::{CompletionFieldsToResolve, snippet::Snippet};
|
||||
|
||||
|
@ -59,12 +62,20 @@ impl CompletionConfig<'_> {
|
|||
.flat_map(|snip| snip.prefix_triggers.iter().map(move |trigger| (&**trigger, snip)))
|
||||
}
|
||||
|
||||
pub fn import_path_config(&self, allow_unstable: bool) -> ImportPathConfig {
|
||||
ImportPathConfig {
|
||||
pub fn find_path_config(&self, allow_unstable: bool) -> FindPathConfig {
|
||||
FindPathConfig {
|
||||
prefer_no_std: self.prefer_no_std,
|
||||
prefer_prelude: self.prefer_prelude,
|
||||
prefer_absolute: self.prefer_absolute,
|
||||
allow_unstable,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn import_path_config(&self) -> ImportPathConfig {
|
||||
ImportPathConfig {
|
||||
prefer_no_std: self.prefer_no_std,
|
||||
prefer_prelude: self.prefer_prelude,
|
||||
prefer_absolute: self.prefer_absolute,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -299,7 +299,7 @@ pub(crate) fn render_expr(
|
|||
.unwrap_or_else(|| String::from("..."))
|
||||
};
|
||||
|
||||
let cfg = ctx.config.import_path_config(ctx.is_nightly);
|
||||
let cfg = ctx.config.find_path_config(ctx.is_nightly);
|
||||
|
||||
let label =
|
||||
expr.gen_source_code(&ctx.scope, &mut label_formatter, cfg, ctx.display_target).ok()?;
|
||||
|
|
|
@ -164,7 +164,7 @@ impl Snippet {
|
|||
}
|
||||
|
||||
fn import_edits(ctx: &CompletionContext<'_>, requires: &[ModPath]) -> Option<Vec<LocatedImport>> {
|
||||
let import_cfg = ctx.config.import_path_config(ctx.is_nightly);
|
||||
let import_cfg = ctx.config.find_path_config(ctx.is_nightly);
|
||||
|
||||
let resolve = |import| {
|
||||
let item = ctx.scope.resolve_mod_path(import).next()?;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
use std::ops::ControlFlow;
|
||||
|
||||
use hir::{
|
||||
AsAssocItem, AssocItem, AssocItemContainer, Complete, Crate, HasCrate, ImportPathConfig,
|
||||
AsAssocItem, AssocItem, AssocItemContainer, Complete, Crate, FindPathConfig, HasCrate,
|
||||
ItemInNs, ModPath, Module, ModuleDef, Name, PathResolution, PrefixKind, ScopeDef, Semantics,
|
||||
SemanticsScope, Trait, TyFingerprint, Type, db::HirDatabase,
|
||||
};
|
||||
|
@ -19,6 +19,17 @@ use crate::{
|
|||
items_locator::{self, AssocSearchMode, DEFAULT_QUERY_SEARCH_LIMIT},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Copy)]
|
||||
pub struct ImportPathConfig {
|
||||
/// If true, prefer to unconditionally use imports of the `core` and `alloc` crate
|
||||
/// over the std.
|
||||
pub prefer_no_std: bool,
|
||||
/// If true, prefer import paths containing a prelude module.
|
||||
pub prefer_prelude: bool,
|
||||
/// If true, prefer abs path (starting with `::`) where it is available.
|
||||
pub prefer_absolute: bool,
|
||||
}
|
||||
|
||||
/// A candidate for import, derived during various IDE activities:
|
||||
/// * completion with imports on the fly proposals
|
||||
/// * completion edit resolve requests
|
||||
|
@ -296,6 +307,12 @@ impl<'db> ImportAssets<'db> {
|
|||
Some(it) => it,
|
||||
None => return <FxIndexSet<_>>::default().into_iter(),
|
||||
};
|
||||
let cfg = FindPathConfig {
|
||||
prefer_no_std: cfg.prefer_no_std,
|
||||
prefer_prelude: cfg.prefer_prelude,
|
||||
prefer_absolute: cfg.prefer_absolute,
|
||||
allow_unstable: sema.is_nightly(scope.krate()),
|
||||
};
|
||||
let db = sema.db;
|
||||
let krate = self.module_with_candidate.krate();
|
||||
let scope_definitions = self.scope_definitions(sema);
|
||||
|
@ -698,7 +715,7 @@ fn get_mod_path(
|
|||
item_to_search: ItemInNs,
|
||||
module_with_candidate: &Module,
|
||||
prefixed: Option<PrefixKind>,
|
||||
cfg: ImportPathConfig,
|
||||
cfg: FindPathConfig,
|
||||
) -> Option<ModPath> {
|
||||
if let Some(prefix_kind) = prefixed {
|
||||
module_with_candidate.find_use_path(db, item_to_search, prefix_kind, cfg)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
use crate::helpers::mod_path_to_ast;
|
||||
use either::Either;
|
||||
use hir::{
|
||||
AsAssocItem, HirDisplay, HirFileId, ImportPathConfig, ModuleDef, SemanticsScope,
|
||||
AsAssocItem, FindPathConfig, HirDisplay, HirFileId, ModuleDef, SemanticsScope,
|
||||
prettify_macro_expansion,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
|
@ -392,7 +392,7 @@ impl Ctx<'_> {
|
|||
parent.segment()?.name_ref()?,
|
||||
)
|
||||
.and_then(|trait_ref| {
|
||||
let cfg = ImportPathConfig {
|
||||
let cfg = FindPathConfig {
|
||||
prefer_no_std: false,
|
||||
prefer_prelude: true,
|
||||
prefer_absolute: false,
|
||||
|
@ -452,7 +452,7 @@ impl Ctx<'_> {
|
|||
return None;
|
||||
}
|
||||
|
||||
let cfg = ImportPathConfig {
|
||||
let cfg = FindPathConfig {
|
||||
prefer_no_std: false,
|
||||
prefer_prelude: true,
|
||||
prefer_absolute: false,
|
||||
|
@ -501,7 +501,7 @@ impl Ctx<'_> {
|
|||
if let Some(adt) = ty.as_adt()
|
||||
&& let ast::Type::PathType(path_ty) = &ast_ty
|
||||
{
|
||||
let cfg = ImportPathConfig {
|
||||
let cfg = FindPathConfig {
|
||||
prefer_no_std: false,
|
||||
prefer_prelude: true,
|
||||
prefer_absolute: false,
|
||||
|
@ -546,7 +546,7 @@ impl Ctx<'_> {
|
|||
|
||||
match resolution {
|
||||
hir::PathResolution::Def(def) if def.as_assoc_item(self.source_scope.db).is_none() => {
|
||||
let cfg = ImportPathConfig {
|
||||
let cfg = FindPathConfig {
|
||||
prefer_no_std: false,
|
||||
prefer_prelude: true,
|
||||
prefer_absolute: false,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! This diagnostic provides an assist for creating a struct definition from a JSON
|
||||
//! example.
|
||||
|
||||
use hir::{ImportPathConfig, PathResolution, Semantics};
|
||||
use hir::{FindPathConfig, PathResolution, Semantics};
|
||||
use ide_db::text_edit::TextEdit;
|
||||
use ide_db::{
|
||||
EditionedFileId, FileRange, FxHashMap, RootDatabase,
|
||||
|
@ -141,7 +141,7 @@ pub(crate) fn json_in_items(
|
|||
let scope = scb.make_import_scope_mut(import_scope);
|
||||
let current_module = semantics_scope.module();
|
||||
|
||||
let cfg = ImportPathConfig {
|
||||
let cfg = FindPathConfig {
|
||||
prefer_no_std: config.prefer_no_std,
|
||||
prefer_prelude: config.prefer_prelude,
|
||||
prefer_absolute: config.prefer_absolute,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use either::Either;
|
||||
use hir::{
|
||||
AssocItem, HirDisplay, ImportPathConfig, InFile, Type,
|
||||
AssocItem, FindPathConfig, HirDisplay, InFile, Type,
|
||||
db::{ExpandDatabase, HirDatabase},
|
||||
sym,
|
||||
};
|
||||
|
@ -132,7 +132,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::MissingFields) -> Option<Vec<Ass
|
|||
let type_path = current_module?.find_path(
|
||||
ctx.sema.db,
|
||||
item_for_path_search(ctx.sema.db, item_in_ns)?,
|
||||
ImportPathConfig {
|
||||
FindPathConfig {
|
||||
prefer_no_std: ctx.config.prefer_no_std,
|
||||
prefer_prelude: ctx.config.prefer_prelude,
|
||||
prefer_absolute: ctx.config.prefer_absolute,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::ops::Not;
|
||||
|
||||
use hir::{
|
||||
ClosureStyle, HirDisplay, ImportPathConfig,
|
||||
ClosureStyle, HirDisplay, FindPathConfig,
|
||||
db::ExpandDatabase,
|
||||
term_search::{TermSearchConfig, TermSearchCtx, term_search},
|
||||
};
|
||||
|
@ -73,7 +73,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::TypedHole<'_>) -> Option<Vec<Ass
|
|||
path.gen_source_code(
|
||||
&scope,
|
||||
&mut formatter,
|
||||
ImportPathConfig {
|
||||
FindPathConfig {
|
||||
prefer_no_std: ctx.config.prefer_no_std,
|
||||
prefer_prelude: ctx.config.prefer_prelude,
|
||||
prefer_absolute: ctx.config.prefer_absolute,
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::{
|
|||
parsing::{Constraint, NodeKind, Placeholder, Var},
|
||||
resolving::{ResolvedPattern, ResolvedRule, UfcsCallInfo},
|
||||
};
|
||||
use hir::{FileRange, ImportPathConfig, Semantics};
|
||||
use hir::{FileRange, FindPathConfig, Semantics};
|
||||
use ide_db::{FxHashMap, base_db::RootQueryDb};
|
||||
use std::{cell::Cell, iter::Peekable};
|
||||
use syntax::{
|
||||
|
@ -661,7 +661,7 @@ impl Match {
|
|||
.module();
|
||||
for (path, resolved_path) in &template.resolved_paths {
|
||||
if let hir::PathResolution::Def(module_def) = resolved_path.resolution {
|
||||
let cfg = ImportPathConfig {
|
||||
let cfg = FindPathConfig {
|
||||
prefer_no_std: false,
|
||||
prefer_prelude: true,
|
||||
prefer_absolute: false,
|
||||
|
|
|
@ -10,7 +10,7 @@ use std::{
|
|||
|
||||
use cfg::{CfgAtom, CfgDiff};
|
||||
use hir::{
|
||||
Adt, AssocItem, Crate, DefWithBody, HasCrate, HasSource, HirDisplay, ImportPathConfig,
|
||||
Adt, AssocItem, Crate, DefWithBody, HasCrate, HasSource, HirDisplay, FindPathConfig,
|
||||
ModuleDef, Name,
|
||||
db::{DefDatabase, ExpandDatabase, HirDatabase},
|
||||
next_solver::{DbInterner, GenericArgs},
|
||||
|
@ -551,7 +551,7 @@ impl flags::AnalysisStats {
|
|||
.gen_source_code(
|
||||
&scope,
|
||||
&mut formatter,
|
||||
ImportPathConfig {
|
||||
FindPathConfig {
|
||||
prefer_no_std: false,
|
||||
prefer_prelude: true,
|
||||
prefer_absolute: false,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue