Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-completion/src/completions.rs')
-rw-r--r--crates/ide-completion/src/completions.rs61
1 files changed, 60 insertions, 1 deletions
diff --git a/crates/ide-completion/src/completions.rs b/crates/ide-completion/src/completions.rs
index b94bbc4065..bc7a94cd33 100644
--- a/crates/ide-completion/src/completions.rs
+++ b/crates/ide-completion/src/completions.rs
@@ -23,7 +23,7 @@ pub(crate) mod env_vars;
use std::iter;
-use hir::{known, ScopeDef, Variant};
+use hir::{known, HasAttrs, ScopeDef, Variant};
use ide_db::{imports::import_assets::LocatedImport, SymbolKind};
use syntax::ast;
@@ -173,6 +173,9 @@ impl Completions {
resolution: hir::ScopeDef,
doc_aliases: Vec<syntax::SmolStr>,
) {
+ if !ctx.check_stability(resolution.attrs(ctx.db).as_deref()) {
+ return;
+ }
let is_private_editable = match ctx.def_is_visible(&resolution) {
Visible::Yes => false,
Visible::Editable => true,
@@ -198,6 +201,9 @@ impl Completions {
local_name: hir::Name,
resolution: hir::ScopeDef,
) {
+ if !ctx.check_stability(resolution.attrs(ctx.db).as_deref()) {
+ return;
+ }
let is_private_editable = match ctx.def_is_visible(&resolution) {
Visible::Yes => false,
Visible::Editable => true,
@@ -220,6 +226,9 @@ impl Completions {
path_ctx: &PathCompletionCtx,
e: hir::Enum,
) {
+ if !ctx.check_stability(Some(&e.attrs(ctx.db))) {
+ return;
+ }
e.variants(ctx.db)
.into_iter()
.for_each(|variant| self.add_enum_variant(ctx, path_ctx, variant, None));
@@ -233,6 +242,9 @@ impl Completions {
local_name: hir::Name,
doc_aliases: Vec<syntax::SmolStr>,
) {
+ if !ctx.check_stability(Some(&module.attrs(ctx.db))) {
+ return;
+ }
self.add_path_resolution(
ctx,
path_ctx,
@@ -249,6 +261,9 @@ impl Completions {
mac: hir::Macro,
local_name: hir::Name,
) {
+ if !ctx.check_stability(Some(&mac.attrs(ctx.db))) {
+ return;
+ }
let is_private_editable = match ctx.is_visible(&mac) {
Visible::Yes => false,
Visible::Editable => true,
@@ -272,6 +287,9 @@ impl Completions {
func: hir::Function,
local_name: Option<hir::Name>,
) {
+ if !ctx.check_stability(Some(&func.attrs(ctx.db))) {
+ return;
+ }
let is_private_editable = match ctx.is_visible(&func) {
Visible::Yes => false,
Visible::Editable => true,
@@ -296,6 +314,9 @@ impl Completions {
receiver: Option<hir::Name>,
local_name: Option<hir::Name>,
) {
+ if !ctx.check_stability(Some(&func.attrs(ctx.db))) {
+ return;
+ }
let is_private_editable = match ctx.is_visible(&func) {
Visible::Yes => false,
Visible::Editable => true,
@@ -320,6 +341,9 @@ impl Completions {
func: hir::Function,
import: LocatedImport,
) {
+ if !ctx.check_stability(Some(&func.attrs(ctx.db))) {
+ return;
+ }
let is_private_editable = match ctx.is_visible(&func) {
Visible::Yes => false,
Visible::Editable => true,
@@ -340,6 +364,9 @@ impl Completions {
}
pub(crate) fn add_const(&mut self, ctx: &CompletionContext<'_>, konst: hir::Const) {
+ if !ctx.check_stability(Some(&konst.attrs(ctx.db))) {
+ return;
+ }
let is_private_editable = match ctx.is_visible(&konst) {
Visible::Yes => false,
Visible::Editable => true,
@@ -356,6 +383,9 @@ impl Completions {
ctx: &CompletionContext<'_>,
type_alias: hir::TypeAlias,
) {
+ if !ctx.check_stability(Some(&type_alias.attrs(ctx.db))) {
+ return;
+ }
let is_private_editable = match ctx.is_visible(&type_alias) {
Visible::Yes => false,
Visible::Editable => true,
@@ -372,6 +402,9 @@ impl Completions {
ctx: &CompletionContext<'_>,
type_alias: hir::TypeAlias,
) {
+ if !ctx.check_stability(Some(&type_alias.attrs(ctx.db))) {
+ return;
+ }
self.add_opt(render_type_alias_with_eq(RenderContext::new(ctx), type_alias));
}
@@ -382,6 +415,9 @@ impl Completions {
variant: hir::Variant,
path: hir::ModPath,
) {
+ if !ctx.check_stability(Some(&variant.attrs(ctx.db))) {
+ return;
+ }
if let Some(builder) =
render_variant_lit(RenderContext::new(ctx), path_ctx, None, variant, Some(path))
{
@@ -396,6 +432,9 @@ impl Completions {
variant: hir::Variant,
local_name: Option<hir::Name>,
) {
+ if !ctx.check_stability(Some(&variant.attrs(ctx.db))) {
+ return;
+ }
if let PathCompletionCtx { kind: PathKind::Pat { pat_ctx }, .. } = path_ctx {
cov_mark::hit!(enum_variant_pattern_path);
self.add_variant_pat(ctx, pat_ctx, Some(path_ctx), variant, local_name);
@@ -417,6 +456,9 @@ impl Completions {
field: hir::Field,
ty: &hir::Type,
) {
+ if !ctx.check_stability(Some(&field.attrs(ctx.db))) {
+ return;
+ }
let is_private_editable = match ctx.is_visible(&field) {
Visible::Yes => false,
Visible::Editable => true,
@@ -441,6 +483,9 @@ impl Completions {
path: Option<hir::ModPath>,
local_name: Option<hir::Name>,
) {
+ if !ctx.check_stability(Some(&strukt.attrs(ctx.db))) {
+ return;
+ }
if let Some(builder) =
render_struct_literal(RenderContext::new(ctx), path_ctx, strukt, path, local_name)
{
@@ -455,6 +500,9 @@ impl Completions {
path: Option<hir::ModPath>,
local_name: Option<hir::Name>,
) {
+ if !ctx.check_stability(Some(&un.attrs(ctx.db))) {
+ return;
+ }
let item = render_union_literal(RenderContext::new(ctx), un, path, local_name);
self.add_opt(item);
}
@@ -466,6 +514,8 @@ impl Completions {
field: usize,
ty: &hir::Type,
) {
+ // Only used for (unnamed) tuples, whose all fields *are* stable. No need to check
+ // stability here.
let item = render_tuple_field(RenderContext::new(ctx), receiver, field, ty);
self.add(item);
}
@@ -487,6 +537,9 @@ impl Completions {
variant: hir::Variant,
local_name: Option<hir::Name>,
) {
+ if !ctx.check_stability(Some(&variant.attrs(ctx.db))) {
+ return;
+ }
self.add_opt(render_variant_pat(
RenderContext::new(ctx),
pattern_ctx,
@@ -504,6 +557,9 @@ impl Completions {
variant: hir::Variant,
path: hir::ModPath,
) {
+ if !ctx.check_stability(Some(&variant.attrs(ctx.db))) {
+ return;
+ }
let path = Some(&path);
self.add_opt(render_variant_pat(
RenderContext::new(ctx),
@@ -522,6 +578,9 @@ impl Completions {
strukt: hir::Struct,
local_name: Option<hir::Name>,
) {
+ if !ctx.check_stability(Some(&strukt.attrs(ctx.db))) {
+ return;
+ }
self.add_opt(render_struct_pat(RenderContext::new(ctx), pattern_ctx, strukt, local_name));
}
}