diff options
author | Igor Aleksanov <[email protected]> | 2020-11-01 09:59:43 +0000 |
---|---|---|
committer | Igor Aleksanov <[email protected]> | 2020-11-03 07:16:35 +0000 |
commit | 944ccf60758305a1b15224defe622cfca6939aaa (patch) | |
tree | d300280524b06d66d96d04df6bc882293c788707 /crates/completion/src/completions.rs | |
parent | fc8a1cd8006b021541ff673ec7f37a0f4b7bef57 (diff) |
Add ConstRender
Diffstat (limited to 'crates/completion/src/completions.rs')
-rw-r--r-- | crates/completion/src/completions.rs | 20 |
1 files changed, 4 insertions, 16 deletions
diff --git a/crates/completion/src/completions.rs b/crates/completion/src/completions.rs index 1ca5cf33d..d8dc1b1c3 100644 --- a/crates/completion/src/completions.rs +++ b/crates/completion/src/completions.rs | |||
@@ -20,7 +20,7 @@ use test_utils::mark; | |||
20 | 20 | ||
21 | use crate::{ | 21 | use crate::{ |
22 | item::Builder, | 22 | item::Builder, |
23 | render::{EnumVariantRender, FunctionRender, MacroRender}, | 23 | render::{ConstRender, EnumVariantRender, FunctionRender, MacroRender}, |
24 | CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, CompletionScore, | 24 | CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, CompletionScore, |
25 | RootDatabase, | 25 | RootDatabase, |
26 | }; | 26 | }; |
@@ -194,7 +194,6 @@ impl Completions { | |||
194 | Some(it) => it, | 194 | Some(it) => it, |
195 | None => return, | 195 | None => return, |
196 | }; | 196 | }; |
197 | |||
198 | if let Some(item) = MacroRender::new(ctx.into(), name, macro_).render() { | 197 | if let Some(item) = MacroRender::new(ctx.into(), name, macro_).render() { |
199 | self.add(item); | 198 | self.add(item); |
200 | } | 199 | } |
@@ -207,24 +206,13 @@ impl Completions { | |||
207 | local_name: Option<String>, | 206 | local_name: Option<String>, |
208 | ) { | 207 | ) { |
209 | let item = FunctionRender::new(ctx.into(), local_name, func).render(); | 208 | let item = FunctionRender::new(ctx.into(), local_name, func).render(); |
210 | |||
211 | self.add(item) | 209 | self.add(item) |
212 | } | 210 | } |
213 | 211 | ||
214 | pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) { | 212 | pub(crate) fn add_const(&mut self, ctx: &CompletionContext, constant: hir::Const) { |
215 | let ast_node = constant.source(ctx.db).value; | 213 | if let Some(item) = ConstRender::new(ctx.into(), constant).render() { |
216 | let name = match ast_node.name() { | 214 | self.add(item); |
217 | Some(name) => name, | 215 | } |
218 | _ => return, | ||
219 | }; | ||
220 | let detail = const_label(&ast_node); | ||
221 | |||
222 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.text().to_string()) | ||
223 | .kind(CompletionItemKind::Const) | ||
224 | .set_documentation(constant.docs(ctx.db)) | ||
225 | .set_deprecated(is_deprecated(constant, ctx.db)) | ||
226 | .detail(detail) | ||
227 | .add_to(self); | ||
228 | } | 216 | } |
229 | 217 | ||
230 | pub(crate) fn add_type_alias(&mut self, ctx: &CompletionContext, type_alias: hir::TypeAlias) { | 218 | pub(crate) fn add_type_alias(&mut self, ctx: &CompletionContext, type_alias: hir::TypeAlias) { |