]> git.lizzy.rs Git - rust.git/blobdiff - crates/ide_completion/src/completions.rs
Merge #11393
[rust.git] / crates / ide_completion / src / completions.rs
index 5f751d83a83b515fd2514fca4611580f90abb5ee..a072d223e0daf610cbcfe33f27342d5bfaeeaaa9 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,
@@ -76,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);
     }
 
@@ -85,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(
@@ -100,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(
@@ -109,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(
@@ -119,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));
     }
 
@@ -165,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);
     }
@@ -173,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);
     }
 
@@ -191,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());
     }
 
@@ -235,7 +253,7 @@ fn enum_variants_with_paths(
 ) {
     let variants = enum_.variants(ctx.db);
 
-    let module = if let Some(module) = ctx.scope.module() {
+    let module = if let Some(module) = ctx.module {
         // Compute path from the completion site if available.
         module
     } else {