diff options
Diffstat (limited to 'crates/ide_completion/src/render')
-rw-r--r-- | crates/ide_completion/src/render/builder_ext.rs | 6 | ||||
-rw-r--r-- | crates/ide_completion/src/render/const_.rs | 10 | ||||
-rw-r--r-- | crates/ide_completion/src/render/enum_variant.rs | 18 | ||||
-rw-r--r-- | crates/ide_completion/src/render/function.rs | 12 | ||||
-rw-r--r-- | crates/ide_completion/src/render/macro_.rs | 23 | ||||
-rw-r--r-- | crates/ide_completion/src/render/pattern.rs | 9 | ||||
-rw-r--r-- | crates/ide_completion/src/render/type_alias.rs | 10 |
7 files changed, 49 insertions, 39 deletions
diff --git a/crates/ide_completion/src/render/builder_ext.rs b/crates/ide_completion/src/render/builder_ext.rs index 95a7596c1..6d062b3b9 100644 --- a/crates/ide_completion/src/render/builder_ext.rs +++ b/crates/ide_completion/src/render/builder_ext.rs | |||
@@ -52,11 +52,11 @@ impl Builder { | |||
52 | } | 52 | } |
53 | 53 | ||
54 | pub(super) fn add_call_parens( | 54 | pub(super) fn add_call_parens( |
55 | mut self, | 55 | &mut self, |
56 | ctx: &CompletionContext, | 56 | ctx: &CompletionContext, |
57 | name: String, | 57 | name: String, |
58 | params: Params, | 58 | params: Params, |
59 | ) -> Builder { | 59 | ) -> &mut Builder { |
60 | if !self.should_add_parens(ctx) { | 60 | if !self.should_add_parens(ctx) { |
61 | return self; | 61 | return self; |
62 | } | 62 | } |
@@ -71,7 +71,7 @@ impl Builder { | |||
71 | let (snippet, label) = if params.is_empty() { | 71 | let (snippet, label) = if params.is_empty() { |
72 | (format!("{}()$0", name), format!("{}()", name)) | 72 | (format!("{}()$0", name), format!("{}()", name)) |
73 | } else { | 73 | } else { |
74 | self = self.trigger_call_info(); | 74 | self.trigger_call_info(); |
75 | let snippet = match (ctx.config.add_call_argument_snippets, params) { | 75 | let snippet = match (ctx.config.add_call_argument_snippets, params) { |
76 | (true, Params::Named(params)) => { | 76 | (true, Params::Named(params)) => { |
77 | let function_params_snippet = | 77 | let function_params_snippet = |
diff --git a/crates/ide_completion/src/render/const_.rs b/crates/ide_completion/src/render/const_.rs index 5010b642a..8add369e4 100644 --- a/crates/ide_completion/src/render/const_.rs +++ b/crates/ide_completion/src/render/const_.rs | |||
@@ -36,17 +36,17 @@ impl<'a> ConstRender<'a> { | |||
36 | let name = self.name()?; | 36 | let name = self.name()?; |
37 | let detail = self.detail(); | 37 | let detail = self.detail(); |
38 | 38 | ||
39 | let item = CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), name) | 39 | let mut item = |
40 | .kind(SymbolKind::Const) | 40 | CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), name); |
41 | item.kind(SymbolKind::Const) | ||
41 | .set_documentation(self.ctx.docs(self.const_)) | 42 | .set_documentation(self.ctx.docs(self.const_)) |
42 | .set_deprecated( | 43 | .set_deprecated( |
43 | self.ctx.is_deprecated(self.const_) | 44 | self.ctx.is_deprecated(self.const_) |
44 | || self.ctx.is_deprecated_assoc_item(self.const_), | 45 | || self.ctx.is_deprecated_assoc_item(self.const_), |
45 | ) | 46 | ) |
46 | .detail(detail) | 47 | .detail(detail); |
47 | .build(); | ||
48 | 48 | ||
49 | Some(item) | 49 | Some(item.build()) |
50 | } | 50 | } |
51 | 51 | ||
52 | fn name(&self) -> Option<String> { | 52 | fn name(&self) -> Option<String> { |
diff --git a/crates/ide_completion/src/render/enum_variant.rs b/crates/ide_completion/src/render/enum_variant.rs index ed055c1fb..23c43496e 100644 --- a/crates/ide_completion/src/render/enum_variant.rs +++ b/crates/ide_completion/src/render/enum_variant.rs | |||
@@ -59,20 +59,20 @@ impl<'a> EnumRender<'a> { | |||
59 | CompletionKind::Reference, | 59 | CompletionKind::Reference, |
60 | self.ctx.source_range(), | 60 | self.ctx.source_range(), |
61 | self.qualified_name.clone(), | 61 | self.qualified_name.clone(), |
62 | ) | 62 | ); |
63 | .kind(SymbolKind::Variant) | 63 | builder |
64 | .set_documentation(self.variant.docs(self.ctx.db())) | 64 | .kind(SymbolKind::Variant) |
65 | .set_deprecated(self.ctx.is_deprecated(self.variant)) | 65 | .set_documentation(self.variant.docs(self.ctx.db())) |
66 | .add_import(import_to_add) | 66 | .set_deprecated(self.ctx.is_deprecated(self.variant)) |
67 | .detail(self.detail()); | 67 | .add_import(import_to_add) |
68 | .detail(self.detail()); | ||
68 | 69 | ||
69 | if self.variant_kind == StructKind::Tuple { | 70 | if self.variant_kind == StructKind::Tuple { |
70 | cov_mark::hit!(inserts_parens_for_tuple_enums); | 71 | cov_mark::hit!(inserts_parens_for_tuple_enums); |
71 | let params = Params::Anonymous(self.variant.fields(self.ctx.db()).len()); | 72 | let params = Params::Anonymous(self.variant.fields(self.ctx.db()).len()); |
72 | builder = | 73 | builder.add_call_parens(self.ctx.completion, self.short_qualified_name, params); |
73 | builder.add_call_parens(self.ctx.completion, self.short_qualified_name, params); | ||
74 | } else if self.path.is_some() { | 74 | } else if self.path.is_some() { |
75 | builder = builder.lookup_by(self.short_qualified_name); | 75 | builder.lookup_by(self.short_qualified_name); |
76 | } | 76 | } |
77 | 77 | ||
78 | builder.build() | 78 | builder.build() |
diff --git a/crates/ide_completion/src/render/function.rs b/crates/ide_completion/src/render/function.rs index 5931945a8..1e2f45f14 100644 --- a/crates/ide_completion/src/render/function.rs +++ b/crates/ide_completion/src/render/function.rs | |||
@@ -41,7 +41,12 @@ impl<'a> FunctionRender<'a> { | |||
41 | 41 | ||
42 | fn render(self, import_to_add: Option<ImportEdit>) -> CompletionItem { | 42 | fn render(self, import_to_add: Option<ImportEdit>) -> CompletionItem { |
43 | let params = self.params(); | 43 | let params = self.params(); |
44 | CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), self.name.clone()) | 44 | let mut builder = CompletionItem::new( |
45 | CompletionKind::Reference, | ||
46 | self.ctx.source_range(), | ||
47 | self.name.clone(), | ||
48 | ); | ||
49 | builder | ||
45 | .kind(self.kind()) | 50 | .kind(self.kind()) |
46 | .set_documentation(self.ctx.docs(self.func)) | 51 | .set_documentation(self.ctx.docs(self.func)) |
47 | .set_deprecated( | 52 | .set_deprecated( |
@@ -49,8 +54,9 @@ impl<'a> FunctionRender<'a> { | |||
49 | ) | 54 | ) |
50 | .detail(self.detail()) | 55 | .detail(self.detail()) |
51 | .add_call_parens(self.ctx.completion, self.name, params) | 56 | .add_call_parens(self.ctx.completion, self.name, params) |
52 | .add_import(import_to_add) | 57 | .add_import(import_to_add); |
53 | .build() | 58 | |
59 | builder.build() | ||
54 | } | 60 | } |
55 | 61 | ||
56 | fn detail(&self) -> String { | 62 | fn detail(&self) -> String { |
diff --git a/crates/ide_completion/src/render/macro_.rs b/crates/ide_completion/src/render/macro_.rs index a6cf3e479..727f5e02e 100644 --- a/crates/ide_completion/src/render/macro_.rs +++ b/crates/ide_completion/src/render/macro_.rs | |||
@@ -40,24 +40,27 @@ impl<'a> MacroRender<'a> { | |||
40 | 40 | ||
41 | fn render(&self, import_to_add: Option<ImportEdit>) -> Option<CompletionItem> { | 41 | fn render(&self, import_to_add: Option<ImportEdit>) -> Option<CompletionItem> { |
42 | let mut builder = | 42 | let mut builder = |
43 | CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), &self.label()) | 43 | CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), &self.label()); |
44 | .kind(SymbolKind::Macro) | 44 | builder |
45 | .set_documentation(self.docs.clone()) | 45 | .kind(SymbolKind::Macro) |
46 | .set_deprecated(self.ctx.is_deprecated(self.macro_)) | 46 | .set_documentation(self.docs.clone()) |
47 | .add_import(import_to_add) | 47 | .set_deprecated(self.ctx.is_deprecated(self.macro_)) |
48 | .set_detail(self.detail()); | 48 | .add_import(import_to_add) |
49 | .set_detail(self.detail()); | ||
49 | 50 | ||
50 | let needs_bang = self.needs_bang(); | 51 | let needs_bang = self.needs_bang(); |
51 | builder = match self.ctx.snippet_cap() { | 52 | match self.ctx.snippet_cap() { |
52 | Some(cap) if needs_bang => { | 53 | Some(cap) if needs_bang => { |
53 | let snippet = self.snippet(); | 54 | let snippet = self.snippet(); |
54 | let lookup = self.lookup(); | 55 | let lookup = self.lookup(); |
55 | builder.insert_snippet(cap, snippet).lookup_by(lookup) | 56 | builder.insert_snippet(cap, snippet).lookup_by(lookup); |
57 | } | ||
58 | None if needs_bang => { | ||
59 | builder.insert_text(self.banged_name()); | ||
56 | } | 60 | } |
57 | None if needs_bang => builder.insert_text(self.banged_name()), | ||
58 | _ => { | 61 | _ => { |
59 | cov_mark::hit!(dont_insert_macro_call_parens_unncessary); | 62 | cov_mark::hit!(dont_insert_macro_call_parens_unncessary); |
60 | builder.insert_text(&self.name) | 63 | builder.insert_text(&self.name); |
61 | } | 64 | } |
62 | }; | 65 | }; |
63 | 66 | ||
diff --git a/crates/ide_completion/src/render/pattern.rs b/crates/ide_completion/src/render/pattern.rs index 465dfe00c..4d8f2b17d 100644 --- a/crates/ide_completion/src/render/pattern.rs +++ b/crates/ide_completion/src/render/pattern.rs | |||
@@ -71,15 +71,16 @@ fn build_completion( | |||
71 | pat: String, | 71 | pat: String, |
72 | item: impl HasAttrs + Copy, | 72 | item: impl HasAttrs + Copy, |
73 | ) -> CompletionItem { | 73 | ) -> CompletionItem { |
74 | let completion = CompletionItem::new(CompletionKind::Snippet, ctx.source_range(), name) | 74 | let mut completion = CompletionItem::new(CompletionKind::Snippet, ctx.source_range(), name); |
75 | completion | ||
75 | .kind(CompletionItemKind::Binding) | 76 | .kind(CompletionItemKind::Binding) |
76 | .set_documentation(ctx.docs(item)) | 77 | .set_documentation(ctx.docs(item)) |
77 | .set_deprecated(ctx.is_deprecated(item)) | 78 | .set_deprecated(ctx.is_deprecated(item)) |
78 | .detail(&pat); | 79 | .detail(&pat); |
79 | let completion = if let Some(snippet_cap) = ctx.snippet_cap() { | 80 | if let Some(snippet_cap) = ctx.snippet_cap() { |
80 | completion.insert_snippet(snippet_cap, pat) | 81 | completion.insert_snippet(snippet_cap, pat); |
81 | } else { | 82 | } else { |
82 | completion.insert_text(pat) | 83 | completion.insert_text(pat); |
83 | }; | 84 | }; |
84 | completion.build() | 85 | completion.build() |
85 | } | 86 | } |
diff --git a/crates/ide_completion/src/render/type_alias.rs b/crates/ide_completion/src/render/type_alias.rs index bd97c3692..e47b4c745 100644 --- a/crates/ide_completion/src/render/type_alias.rs +++ b/crates/ide_completion/src/render/type_alias.rs | |||
@@ -36,17 +36,17 @@ impl<'a> TypeAliasRender<'a> { | |||
36 | let name = self.name()?; | 36 | let name = self.name()?; |
37 | let detail = self.detail(); | 37 | let detail = self.detail(); |
38 | 38 | ||
39 | let item = CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), name) | 39 | let mut item = |
40 | .kind(SymbolKind::TypeAlias) | 40 | CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), name); |
41 | item.kind(SymbolKind::TypeAlias) | ||
41 | .set_documentation(self.ctx.docs(self.type_alias)) | 42 | .set_documentation(self.ctx.docs(self.type_alias)) |
42 | .set_deprecated( | 43 | .set_deprecated( |
43 | self.ctx.is_deprecated(self.type_alias) | 44 | self.ctx.is_deprecated(self.type_alias) |
44 | || self.ctx.is_deprecated_assoc_item(self.type_alias), | 45 | || self.ctx.is_deprecated_assoc_item(self.type_alias), |
45 | ) | 46 | ) |
46 | .detail(detail) | 47 | .detail(detail); |
47 | .build(); | ||
48 | 48 | ||
49 | Some(item) | 49 | Some(item.build()) |
50 | } | 50 | } |
51 | 51 | ||
52 | fn name(&self) -> Option<String> { | 52 | fn name(&self) -> Option<String> { |