diff options
author | Aleksey Kladov <[email protected]> | 2021-02-17 14:53:31 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-02-17 14:53:31 +0000 |
commit | 3db64a400c78bbd2708e67ddc07df1001fff3f29 (patch) | |
tree | 5386aab9c452981be09bc3e4362643a34e6e3617 /crates/ide_completion/src/render/type_alias.rs | |
parent | 6334ce866ab095215381c4b72692b20a84d26e96 (diff) |
rename completion -> ide_completion
We don't have completion-related PRs in flight, so lets do it
Diffstat (limited to 'crates/ide_completion/src/render/type_alias.rs')
-rw-r--r-- | crates/ide_completion/src/render/type_alias.rs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/crates/ide_completion/src/render/type_alias.rs b/crates/ide_completion/src/render/type_alias.rs new file mode 100644 index 000000000..bd97c3692 --- /dev/null +++ b/crates/ide_completion/src/render/type_alias.rs | |||
@@ -0,0 +1,59 @@ | |||
1 | //! Renderer for type aliases. | ||
2 | |||
3 | use hir::HasSource; | ||
4 | use ide_db::SymbolKind; | ||
5 | use syntax::{ | ||
6 | ast::{NameOwner, TypeAlias}, | ||
7 | display::type_label, | ||
8 | }; | ||
9 | |||
10 | use crate::{ | ||
11 | item::{CompletionItem, CompletionKind}, | ||
12 | render::RenderContext, | ||
13 | }; | ||
14 | |||
15 | pub(crate) fn render_type_alias<'a>( | ||
16 | ctx: RenderContext<'a>, | ||
17 | type_alias: hir::TypeAlias, | ||
18 | ) -> Option<CompletionItem> { | ||
19 | TypeAliasRender::new(ctx, type_alias)?.render() | ||
20 | } | ||
21 | |||
22 | #[derive(Debug)] | ||
23 | struct TypeAliasRender<'a> { | ||
24 | ctx: RenderContext<'a>, | ||
25 | type_alias: hir::TypeAlias, | ||
26 | ast_node: TypeAlias, | ||
27 | } | ||
28 | |||
29 | impl<'a> TypeAliasRender<'a> { | ||
30 | fn new(ctx: RenderContext<'a>, type_alias: hir::TypeAlias) -> Option<TypeAliasRender<'a>> { | ||
31 | let ast_node = type_alias.source(ctx.db())?.value; | ||
32 | Some(TypeAliasRender { ctx, type_alias, ast_node }) | ||
33 | } | ||
34 | |||
35 | fn render(self) -> Option<CompletionItem> { | ||
36 | let name = self.name()?; | ||
37 | let detail = self.detail(); | ||
38 | |||
39 | let item = CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), name) | ||
40 | .kind(SymbolKind::TypeAlias) | ||
41 | .set_documentation(self.ctx.docs(self.type_alias)) | ||
42 | .set_deprecated( | ||
43 | self.ctx.is_deprecated(self.type_alias) | ||
44 | || self.ctx.is_deprecated_assoc_item(self.type_alias), | ||
45 | ) | ||
46 | .detail(detail) | ||
47 | .build(); | ||
48 | |||
49 | Some(item) | ||
50 | } | ||
51 | |||
52 | fn name(&self) -> Option<String> { | ||
53 | self.ast_node.name().map(|name| name.text().to_string()) | ||
54 | } | ||
55 | |||
56 | fn detail(&self) -> String { | ||
57 | type_label(&self.ast_node) | ||
58 | } | ||
59 | } | ||