Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-completion/src/context.rs')
-rw-r--r--crates/ide-completion/src/context.rs42
1 files changed, 40 insertions, 2 deletions
diff --git a/crates/ide-completion/src/context.rs b/crates/ide-completion/src/context.rs
index f7fced3f06..f7bb14391b 100644
--- a/crates/ide-completion/src/context.rs
+++ b/crates/ide-completion/src/context.rs
@@ -611,7 +611,7 @@ impl<'db> CompletionContext<'_, 'db> {
let Some(unstable_feature) = attrs.unstable_feature(self.db) else {
return true;
};
- !INTERNAL_FEATURES.contains(&unstable_feature)
+ !is_internal_feature(&unstable_feature)
|| self.krate.is_unstable_feature_enabled(self.db, &unstable_feature)
}
@@ -729,6 +729,13 @@ impl<'db> CompletionContext<'_, 'db> {
vec![]
}
}
+
+ pub(crate) fn rebase_ty(&self, ty: &hir::Type<'db>) -> hir::Type<'db> {
+ self.scope
+ .generic_def()
+ .and_then(|def| ty.try_rebase_into_owner(self.db, def))
+ .unwrap_or_else(|| ty.instantiate_with_errors())
+ }
}
// CompletionContext construction
@@ -848,8 +855,23 @@ impl<'a, 'db> CompletionContext<'a, 'db> {
.map(|it| (it.into_module_def(), *kind))
})
.collect();
+ let exclude_subitems = exclude_flyimport
+ .iter()
+ .flat_map(|it| match it {
+ (ModuleDef::Module(module), AutoImportExclusionType::SubItems) => {
+ module.scope(db, None)
+ }
+ _ => vec![],
+ })
+ .filter_map(|(_, def)| match def {
+ ScopeDef::ModuleDef(module_def) => Some(module_def),
+ _ => None,
+ })
+ .collect::<Vec<_>>();
exclude_flyimport
.extend(exclude_traits.iter().map(|&t| (t.into(), AutoImportExclusionType::Always)));
+ exclude_flyimport
+ .extend(exclude_subitems.into_iter().map(|it| (it, AutoImportExclusionType::Always)));
// FIXME: This should be part of `CompletionAnalysis` / `expand_and_analyze`
let complete_semicolon = if !config.add_semicolon_to_unit {
@@ -858,7 +880,13 @@ impl<'a, 'db> CompletionContext<'a, 'db> {
sema.token_ancestors_with_macros(token.clone()).find(|node| {
matches!(
node.kind(),
- BLOCK_EXPR | MATCH_ARM | CLOSURE_EXPR | ARG_LIST | PAREN_EXPR | ARRAY_EXPR
+ BLOCK_EXPR
+ | MATCH_ARM
+ | CLOSURE_EXPR
+ | ARG_LIST
+ | PAREN_EXPR
+ | ARRAY_EXPR
+ | MATCH_EXPR
)
})
{
@@ -949,6 +977,7 @@ const INTERNAL_FEATURES_LIST: &[Symbol] = &[
sym::eii_internals,
sym::field_representing_type_raw,
sym::intrinsics,
+ sym::core_intrinsics,
sym::lang_items,
sym::link_cfg,
sym::more_maybe_bounds,
@@ -972,3 +1001,12 @@ const INTERNAL_FEATURES_LIST: &[Symbol] = &[
static INTERNAL_FEATURES: LazyLock<FxHashSet<Symbol>> =
LazyLock::new(|| INTERNAL_FEATURES_LIST.iter().cloned().collect());
+
+fn is_internal_feature(feature: &Symbol) -> bool {
+ if INTERNAL_FEATURES.contains(feature) {
+ return true;
+ }
+ // Libs features are internal if they end in `_internal` or `_internals`.
+ let feature = feature.as_str();
+ feature.ends_with("_internal") || feature.ends_with("_internals")
+}