]> 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 e19edb21252e5232e54e3966bcc9f22c7ce0a751..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;
 
@@ -21,7 +22,7 @@
 use ide_db::SymbolKind;
 
 use crate::{
-    item::{Builder, CompletionKind},
+    item::Builder,
     render::{
         const_::render_const,
         enum_variant::render_variant,
@@ -29,6 +30,7 @@
         macro_::render_macro,
         pattern::{render_struct_pat, render_variant_pat},
         render_field, render_resolution, render_tuple_field,
+        struct_literal::render_struct_literal,
         type_alias::{render_type_alias, render_type_alias_with_eq},
         RenderContext,
     },
@@ -75,8 +77,7 @@ pub(crate) fn add_all<I>(&mut self, items: I)
     }
 
     pub(crate) fn add_keyword(&mut self, ctx: &CompletionContext, keyword: &'static str) {
-        let mut item = CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), keyword);
-        item.kind(CompletionItemKind::Keyword);
+        let item = CompletionItem::new(CompletionItemKind::Keyword, ctx.source_range(), keyword);
         item.add_to(self);
     }
 
@@ -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,10 +181,24 @@ 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);
     }
 
+    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, path, local_name);
+        self.add_opt(item);
+    }
+
     pub(crate) fn add_tuple_field(
         &mut self,
         ctx: &CompletionContext,
@@ -180,9 +211,7 @@ pub(crate) fn add_tuple_field(
     }
 
     pub(crate) fn add_static_lifetime(&mut self, ctx: &CompletionContext) {
-        let mut item =
-            CompletionItem::new(CompletionKind::Reference, ctx.source_range(), "'static");
-        item.kind(CompletionItemKind::SymbolKind(SymbolKind::LifetimeParam));
+        let item = CompletionItem::new(SymbolKind::LifetimeParam, ctx.source_range(), "'static");
         self.add(item.build());
     }