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.rs93
1 files changed, 72 insertions, 21 deletions
diff --git a/crates/ide_completion/src/completions.rs b/crates/ide_completion/src/completions.rs
index 91e6b84294..d187d56cb5 100644
--- a/crates/ide_completion/src/completions.rs
+++ b/crates/ide_completion/src/completions.rs
@@ -29,11 +29,11 @@ use crate::{
item::Builder,
render::{
const_::render_const,
- enum_variant::render_variant,
function::{render_fn, render_method},
+ literal::{render_struct_literal, render_variant_lit},
+ macro_::render_macro,
pattern::{render_struct_pat, render_variant_pat},
- render_field, render_resolution, render_tuple_field,
- struct_literal::render_struct_literal,
+ render_field, render_resolution, render_resolution_simple, render_tuple_field,
type_alias::{render_type_alias, render_type_alias_with_eq},
union_literal::render_union_literal,
RenderContext,
@@ -124,7 +124,37 @@ impl Completions {
cov_mark::hit!(qualified_path_doc_hidden);
return;
}
- self.add(render_resolution(RenderContext::new(ctx, false), local_name, resolution));
+ self.add(render_resolution(RenderContext::new(ctx), local_name, resolution));
+ }
+
+ pub(crate) fn add_resolution_simple(
+ &mut self,
+ ctx: &CompletionContext,
+ local_name: hir::Name,
+ resolution: hir::ScopeDef,
+ ) {
+ if ctx.is_scope_def_hidden(resolution) {
+ return;
+ }
+ self.add(render_resolution_simple(RenderContext::new(ctx), local_name, resolution));
+ }
+
+ pub(crate) fn add_macro(
+ &mut self,
+ ctx: &CompletionContext,
+ mac: hir::Macro,
+ local_name: hir::Name,
+ ) {
+ let is_private_editable = match ctx.is_visible(&mac) {
+ Visible::Yes => false,
+ Visible::Editable => true,
+ Visible::No => return,
+ };
+ self.add(render_macro(
+ RenderContext::new(ctx).private_editable(is_private_editable),
+ local_name,
+ mac,
+ ));
}
pub(crate) fn add_function(
@@ -138,7 +168,11 @@ impl Completions {
Visible::Editable => true,
Visible::No => return,
};
- self.add(render_fn(RenderContext::new(ctx, is_private_editable), None, local_name, func));
+ self.add(render_fn(
+ RenderContext::new(ctx).private_editable(is_private_editable),
+ local_name,
+ func,
+ ));
}
pub(crate) fn add_method(
@@ -154,8 +188,7 @@ impl Completions {
Visible::No => return,
};
self.add(render_method(
- RenderContext::new(ctx, is_private_editable),
- None,
+ RenderContext::new(ctx).private_editable(is_private_editable),
receiver,
local_name,
func,
@@ -168,7 +201,10 @@ impl Completions {
Visible::Editable => true,
Visible::No => return,
};
- self.add_opt(render_const(RenderContext::new(ctx, is_private_editable), konst));
+ self.add_opt(render_const(
+ RenderContext::new(ctx).private_editable(is_private_editable),
+ konst,
+ ));
}
pub(crate) fn add_type_alias(&mut self, ctx: &CompletionContext, type_alias: hir::TypeAlias) {
@@ -177,7 +213,10 @@ impl Completions {
Visible::Editable => true,
Visible::No => return,
};
- self.add_opt(render_type_alias(RenderContext::new(ctx, is_private_editable), type_alias));
+ self.add_opt(render_type_alias(
+ RenderContext::new(ctx).private_editable(is_private_editable),
+ type_alias,
+ ));
}
pub(crate) fn add_type_alias_with_eq(
@@ -185,7 +224,7 @@ impl Completions {
ctx: &CompletionContext,
type_alias: hir::TypeAlias,
) {
- self.add_opt(render_type_alias_with_eq(RenderContext::new(ctx, false), type_alias));
+ self.add_opt(render_type_alias_with_eq(RenderContext::new(ctx), type_alias));
}
pub(crate) fn add_qualified_enum_variant(
@@ -194,8 +233,7 @@ impl Completions {
variant: hir::Variant,
path: hir::ModPath,
) {
- let item = render_variant(RenderContext::new(ctx, false), None, None, variant, Some(path));
- self.add(item);
+ self.add_opt(render_variant_lit(RenderContext::new(ctx), None, variant, Some(path)));
}
pub(crate) fn add_enum_variant(
@@ -204,8 +242,7 @@ impl Completions {
variant: hir::Variant,
local_name: Option<hir::Name>,
) {
- let item = render_variant(RenderContext::new(ctx, false), None, local_name, variant, None);
- self.add(item);
+ self.add_opt(render_variant_lit(RenderContext::new(ctx), local_name, variant, None));
}
pub(crate) fn add_field(
@@ -220,7 +257,12 @@ impl Completions {
Visible::Editable => true,
Visible::No => return,
};
- let item = render_field(RenderContext::new(ctx, is_private_editable), receiver, field, ty);
+ let item = render_field(
+ RenderContext::new(ctx).private_editable(is_private_editable),
+ receiver,
+ field,
+ ty,
+ );
self.add(item);
}
@@ -231,7 +273,7 @@ impl Completions {
path: Option<hir::ModPath>,
local_name: Option<hir::Name>,
) {
- let item = render_struct_literal(RenderContext::new(ctx, false), strukt, path, local_name);
+ let item = render_struct_literal(RenderContext::new(ctx), strukt, path, local_name);
self.add_opt(item);
}
@@ -242,7 +284,7 @@ impl Completions {
path: Option<hir::ModPath>,
local_name: Option<hir::Name>,
) {
- let item = render_union_literal(RenderContext::new(ctx, false), un, path, local_name);
+ let item = render_union_literal(RenderContext::new(ctx), un, path, local_name);
self.add_opt(item);
}
@@ -253,7 +295,7 @@ impl Completions {
field: usize,
ty: &hir::Type,
) {
- let item = render_tuple_field(RenderContext::new(ctx, false), receiver, field, ty);
+ let item = render_tuple_field(RenderContext::new(ctx), receiver, field, ty);
self.add(item);
}
@@ -272,7 +314,14 @@ impl Completions {
variant: hir::Variant,
local_name: Option<hir::Name>,
) {
- self.add_opt(render_variant_pat(RenderContext::new(ctx, false), variant, local_name, None));
+ self.add_opt(render_variant_pat(
+ RenderContext::new(ctx),
+ variant,
+ local_name.clone(),
+ None,
+ false,
+ ));
+ self.add_opt(render_variant_pat(RenderContext::new(ctx), variant, local_name, None, true));
}
pub(crate) fn add_qualified_variant_pat(
@@ -281,7 +330,9 @@ impl Completions {
variant: hir::Variant,
path: hir::ModPath,
) {
- self.add_opt(render_variant_pat(RenderContext::new(ctx, false), variant, None, Some(path)));
+ let path = Some(&path);
+ self.add_opt(render_variant_pat(RenderContext::new(ctx), variant, None, path, false));
+ self.add_opt(render_variant_pat(RenderContext::new(ctx), variant, None, path, true));
}
pub(crate) fn add_struct_pat(
@@ -290,7 +341,7 @@ impl Completions {
strukt: hir::Struct,
local_name: Option<hir::Name>,
) {
- self.add_opt(render_struct_pat(RenderContext::new(ctx, false), strukt, local_name));
+ self.add_opt(render_struct_pat(RenderContext::new(ctx), strukt, local_name));
}
}