]> git.lizzy.rs Git - rust.git/blobdiff - crates/ide_completion/src/completions.rs
feat: Add very simplistic ident completion for format_args! macro input
[rust.git] / crates / ide_completion / src / completions.rs
index 3e658c6e91d898f4625dc678cee1f66a73e5ee6c..e399213731db84a87b25afb327056a35a6b69567 100644 (file)
@@ -14,6 +14,7 @@
 pub(crate) mod snippet;
 pub(crate) mod trait_impl;
 pub(crate) mod unqualified_path;
+pub(crate) mod format_string;
 
 use std::iter;
 
@@ -84,9 +85,13 @@ pub(crate) fn add_resolution(
         &mut self,
         ctx: &CompletionContext,
         local_name: hir::Name,
-        resolution: &hir::ScopeDef,
+        resolution: hir::ScopeDef,
     ) {
-        self.add_opt(render_resolution(RenderContext::new(ctx), local_name, resolution));
+        if ctx.is_scope_def_hidden(resolution) {
+            cov_mark::hit!(qualified_path_doc_hidden);
+            return;
+        }
+        self.add(render_resolution(RenderContext::new(ctx), local_name, resolution));
     }
 
     pub(crate) fn add_macro(
@@ -99,7 +104,7 @@ pub(crate) fn add_macro(
             Some(it) => it,
             None => return,
         };
-        self.add_opt(render_macro(RenderContext::new(ctx), None, name, macro_));
+        self.add(render_macro(RenderContext::new(ctx), None, name, macro_));
     }
 
     pub(crate) fn add_function(
@@ -108,7 +113,10 @@ pub(crate) fn add_function(
         func: hir::Function,
         local_name: Option<hir::Name>,
     ) {
-        self.add_opt(render_fn(RenderContext::new(ctx), None, local_name, func));
+        if !ctx.is_visible(&func) {
+            return;
+        }
+        self.add(render_fn(RenderContext::new(ctx), None, local_name, func));
     }
 
     pub(crate) fn add_method(
@@ -118,14 +126,23 @@ pub(crate) fn add_method(
         receiver: Option<hir::Name>,
         local_name: Option<hir::Name>,
     ) {
-        self.add_opt(render_method(RenderContext::new(ctx), None, receiver, local_name, func));
+        if !ctx.is_visible(&func) {
+            return;
+        }
+        self.add(render_method(RenderContext::new(ctx), None, receiver, local_name, func));
     }
 
-    pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) {
-        self.add_opt(render_const(RenderContext::new(ctx), constant));
+    pub(crate) fn add_const(&mut self, ctx: &CompletionContext, konst: hir::Const) {
+        if !ctx.is_visible(&konst) {
+            return;
+        }
+        self.add_opt(render_const(RenderContext::new(ctx), konst));
     }
 
     pub(crate) fn add_type_alias(&mut self, ctx: &CompletionContext, type_alias: hir::TypeAlias) {
+        if !ctx.is_visible(&type_alias) {
+            return;
+        }
         self.add_opt(render_type_alias(RenderContext::new(ctx), type_alias));
     }
 
@@ -164,6 +181,9 @@ pub(crate) fn add_field(
         field: hir::Field,
         ty: &hir::Type,
     ) {
+        if !ctx.is_visible(&field) {
+            return;
+        }
         let item = render_field(RenderContext::new(ctx), receiver, field, ty);
         self.add(item);
     }
@@ -172,9 +192,10 @@ pub(crate) fn add_struct_literal(
         &mut self,
         ctx: &CompletionContext,
         strukt: hir::Struct,
+        path: Option<hir::ModPath>,
         local_name: Option<hir::Name>,
     ) {
-        let item = render_struct_literal(RenderContext::new(ctx), strukt, local_name);
+        let item = render_struct_literal(RenderContext::new(ctx), strukt, path, local_name);
         self.add_opt(item);
     }