aboutsummaryrefslogtreecommitdiff
path: root/crates/completion/src/render
diff options
context:
space:
mode:
Diffstat (limited to 'crates/completion/src/render')
-rw-r--r--crates/completion/src/render/enum_variant.rs15
-rw-r--r--crates/completion/src/render/function.rs17
-rw-r--r--crates/completion/src/render/macro_.rs17
3 files changed, 20 insertions, 29 deletions
diff --git a/crates/completion/src/render/enum_variant.rs b/crates/completion/src/render/enum_variant.rs
index 6070e9b1d..f4bd02f25 100644
--- a/crates/completion/src/render/enum_variant.rs
+++ b/crates/completion/src/render/enum_variant.rs
@@ -1,23 +1,23 @@
1//! Renderer for `enum` variants. 1//! Renderer for `enum` variants.
2 2
3use assists::utils::{ImportScope, MergeBehaviour};
4use hir::{HasAttrs, HirDisplay, ModPath, StructKind}; 3use hir::{HasAttrs, HirDisplay, ModPath, StructKind};
5use itertools::Itertools; 4use itertools::Itertools;
6use test_utils::mark; 5use test_utils::mark;
7 6
8use crate::{ 7use crate::{
9 item::{CompletionItem, CompletionItemKind, CompletionKind}, 8 item::{CompletionItem, CompletionItemKind, CompletionKind, ImportToAdd},
10 render::{builder_ext::Params, RenderContext}, 9 render::{builder_ext::Params, RenderContext},
11}; 10};
12 11
13pub(crate) fn render_enum_variant<'a>( 12pub(crate) fn render_enum_variant<'a>(
14 ctx: RenderContext<'a>, 13 ctx: RenderContext<'a>,
15 import_data: Option<(ModPath, ImportScope, Option<MergeBehaviour>)>, 14 import_to_add: Option<ImportToAdd>,
16 local_name: Option<String>, 15 local_name: Option<String>,
17 variant: hir::EnumVariant, 16 variant: hir::EnumVariant,
18 path: Option<ModPath>, 17 path: Option<ModPath>,
19) -> CompletionItem { 18) -> CompletionItem {
20 EnumVariantRender::new(ctx, local_name, variant, path).render(import_data) 19 let _p = profile::span("render_enum_variant");
20 EnumVariantRender::new(ctx, local_name, variant, path).render(import_to_add)
21} 21}
22 22
23#[derive(Debug)] 23#[derive(Debug)]
@@ -62,10 +62,7 @@ impl<'a> EnumVariantRender<'a> {
62 } 62 }
63 } 63 }
64 64
65 fn render( 65 fn render(self, import_to_add: Option<ImportToAdd>) -> CompletionItem {
66 self,
67 import_data: Option<(ModPath, ImportScope, Option<MergeBehaviour>)>,
68 ) -> CompletionItem {
69 let mut builder = CompletionItem::new( 66 let mut builder = CompletionItem::new(
70 CompletionKind::Reference, 67 CompletionKind::Reference,
71 self.ctx.source_range(), 68 self.ctx.source_range(),
@@ -74,7 +71,7 @@ impl<'a> EnumVariantRender<'a> {
74 .kind(CompletionItemKind::EnumVariant) 71 .kind(CompletionItemKind::EnumVariant)
75 .set_documentation(self.variant.docs(self.ctx.db())) 72 .set_documentation(self.variant.docs(self.ctx.db()))
76 .set_deprecated(self.ctx.is_deprecated(self.variant)) 73 .set_deprecated(self.ctx.is_deprecated(self.variant))
77 .import_data(import_data) 74 .add_import(import_to_add)
78 .detail(self.detail()); 75 .detail(self.detail());
79 76
80 if self.variant_kind == StructKind::Tuple { 77 if self.variant_kind == StructKind::Tuple {
diff --git a/crates/completion/src/render/function.rs b/crates/completion/src/render/function.rs
index 9dd5cd18c..542383d7e 100644
--- a/crates/completion/src/render/function.rs
+++ b/crates/completion/src/render/function.rs
@@ -1,21 +1,21 @@
1//! Renderer for function calls. 1//! Renderer for function calls.
2 2
3use assists::utils::{ImportScope, MergeBehaviour}; 3use hir::{HasSource, Type};
4use hir::{HasSource, ModPath, Type};
5use syntax::{ast::Fn, display::function_declaration}; 4use syntax::{ast::Fn, display::function_declaration};
6 5
7use crate::{ 6use crate::{
8 item::{CompletionItem, CompletionItemKind, CompletionKind}, 7 item::{CompletionItem, CompletionItemKind, CompletionKind, ImportToAdd},
9 render::{builder_ext::Params, RenderContext}, 8 render::{builder_ext::Params, RenderContext},
10}; 9};
11 10
12pub(crate) fn render_fn<'a>( 11pub(crate) fn render_fn<'a>(
13 ctx: RenderContext<'a>, 12 ctx: RenderContext<'a>,
14 import_data: Option<(ModPath, ImportScope, Option<MergeBehaviour>)>, 13 import_to_add: Option<ImportToAdd>,
15 local_name: Option<String>, 14 local_name: Option<String>,
16 fn_: hir::Function, 15 fn_: hir::Function,
17) -> CompletionItem { 16) -> CompletionItem {
18 FunctionRender::new(ctx, local_name, fn_).render(import_data) 17 let _p = profile::span("render_fn");
18 FunctionRender::new(ctx, local_name, fn_).render(import_to_add)
19} 19}
20 20
21#[derive(Debug)] 21#[derive(Debug)]
@@ -38,10 +38,7 @@ impl<'a> FunctionRender<'a> {
38 FunctionRender { ctx, name, fn_, ast_node } 38 FunctionRender { ctx, name, fn_, ast_node }
39 } 39 }
40 40
41 fn render( 41 fn render(self, import_to_add: Option<ImportToAdd>) -> CompletionItem {
42 self,
43 import_data: Option<(ModPath, ImportScope, Option<MergeBehaviour>)>,
44 ) -> CompletionItem {
45 let params = self.params(); 42 let params = self.params();
46 CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), self.name.clone()) 43 CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), self.name.clone())
47 .kind(self.kind()) 44 .kind(self.kind())
@@ -49,7 +46,7 @@ impl<'a> FunctionRender<'a> {
49 .set_deprecated(self.ctx.is_deprecated(self.fn_)) 46 .set_deprecated(self.ctx.is_deprecated(self.fn_))
50 .detail(self.detail()) 47 .detail(self.detail())
51 .add_call_parens(self.ctx.completion, self.name, params) 48 .add_call_parens(self.ctx.completion, self.name, params)
52 .import_data(import_data) 49 .add_import(import_to_add)
53 .build() 50 .build()
54 } 51 }
55 52
diff --git a/crates/completion/src/render/macro_.rs b/crates/completion/src/render/macro_.rs
index fead59e41..b4ab32c6e 100644
--- a/crates/completion/src/render/macro_.rs
+++ b/crates/completion/src/render/macro_.rs
@@ -1,22 +1,22 @@
1//! Renderer for macro invocations. 1//! Renderer for macro invocations.
2 2
3use assists::utils::{ImportScope, MergeBehaviour}; 3use hir::{Documentation, HasSource};
4use hir::{Documentation, HasSource, ModPath};
5use syntax::display::macro_label; 4use syntax::display::macro_label;
6use test_utils::mark; 5use test_utils::mark;
7 6
8use crate::{ 7use crate::{
9 item::{CompletionItem, CompletionItemKind, CompletionKind}, 8 item::{CompletionItem, CompletionItemKind, CompletionKind, ImportToAdd},
10 render::RenderContext, 9 render::RenderContext,
11}; 10};
12 11
13pub(crate) fn render_macro<'a>( 12pub(crate) fn render_macro<'a>(
14 ctx: RenderContext<'a>, 13 ctx: RenderContext<'a>,
15 import_data: Option<(ModPath, ImportScope, Option<MergeBehaviour>)>, 14 import_to_add: Option<ImportToAdd>,
16 name: String, 15 name: String,
17 macro_: hir::MacroDef, 16 macro_: hir::MacroDef,
18) -> Option<CompletionItem> { 17) -> Option<CompletionItem> {
19 MacroRender::new(ctx, name, macro_).render(import_data) 18 let _p = profile::span("render_macro");
19 MacroRender::new(ctx, name, macro_).render(import_to_add)
20} 20}
21 21
22#[derive(Debug)] 22#[derive(Debug)]
@@ -38,10 +38,7 @@ impl<'a> MacroRender<'a> {
38 MacroRender { ctx, name, macro_, docs, bra, ket } 38 MacroRender { ctx, name, macro_, docs, bra, ket }
39 } 39 }
40 40
41 fn render( 41 fn render(&self, import_to_add: Option<ImportToAdd>) -> Option<CompletionItem> {
42 &self,
43 import_data: Option<(ModPath, ImportScope, Option<MergeBehaviour>)>,
44 ) -> Option<CompletionItem> {
45 // FIXME: Currently proc-macro do not have ast-node, 42 // FIXME: Currently proc-macro do not have ast-node,
46 // such that it does not have source 43 // such that it does not have source
47 if self.macro_.is_proc_macro() { 44 if self.macro_.is_proc_macro() {
@@ -53,7 +50,7 @@ impl<'a> MacroRender<'a> {
53 .kind(CompletionItemKind::Macro) 50 .kind(CompletionItemKind::Macro)
54 .set_documentation(self.docs.clone()) 51 .set_documentation(self.docs.clone())
55 .set_deprecated(self.ctx.is_deprecated(self.macro_)) 52 .set_deprecated(self.ctx.is_deprecated(self.macro_))
56 .import_data(import_data) 53 .add_import(import_to_add)
57 .detail(self.detail()); 54 .detail(self.detail());
58 55
59 let needs_bang = self.needs_bang(); 56 let needs_bang = self.needs_bang();