diff options
author | Aleksey Kladov <[email protected]> | 2019-02-24 17:56:19 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-02-24 17:56:53 +0000 |
commit | 5887c0e574064934f2b090746a89894efc6c8f8f (patch) | |
tree | cbe4ac6e321d794351ead3acfda4c812930e2402 /crates | |
parent | 9af525dbd69bb22c968ba42d758657b2ad9bdd37 (diff) |
move enum-variants to presentation
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_path.rs | 26 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/presentation.rs | 16 |
2 files changed, 21 insertions, 21 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index d2f65310f..74ea8d600 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs | |||
@@ -1,9 +1,8 @@ | |||
1 | use join_to_string::join; | 1 | use hir::{Resolution}; |
2 | use hir::{Docs, Resolution}; | ||
3 | use ra_syntax::{AstNode, ast::NameOwner}; | 2 | use ra_syntax::{AstNode, ast::NameOwner}; |
4 | use test_utils::tested_by; | 3 | use test_utils::tested_by; |
5 | 4 | ||
6 | use crate::completion::{CompletionItem, CompletionItemKind, Completions, CompletionKind, CompletionContext}; | 5 | use crate::completion::{CompletionItem, Completions, CompletionKind, CompletionContext}; |
7 | 6 | ||
8 | pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | 7 | pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { |
9 | let path = match &ctx.path_prefix { | 8 | let path = match &ctx.path_prefix { |
@@ -39,24 +38,9 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { | |||
39 | } | 38 | } |
40 | } | 39 | } |
41 | hir::ModuleDef::Enum(e) => { | 40 | hir::ModuleDef::Enum(e) => { |
42 | e.variants(ctx.db).into_iter().for_each(|variant| { | 41 | for variant in e.variants(ctx.db) { |
43 | if let Some(name) = variant.name(ctx.db) { | 42 | acc.add_enum_variant(ctx, variant); |
44 | let detail_types = | 43 | } |
45 | variant.fields(ctx.db).into_iter().map(|field| field.ty(ctx.db)); | ||
46 | let detail = | ||
47 | join(detail_types).separator(", ").surround_with("(", ")").to_string(); | ||
48 | |||
49 | CompletionItem::new( | ||
50 | CompletionKind::Reference, | ||
51 | ctx.source_range(), | ||
52 | name.to_string(), | ||
53 | ) | ||
54 | .kind(CompletionItemKind::EnumVariant) | ||
55 | .set_documentation(variant.docs(ctx.db)) | ||
56 | .set_detail(Some(detail)) | ||
57 | .add_to(acc) | ||
58 | } | ||
59 | }); | ||
60 | } | 44 | } |
61 | hir::ModuleDef::Struct(s) => { | 45 | hir::ModuleDef::Struct(s) => { |
62 | let ty = s.ty(ctx.db); | 46 | let ty = s.ty(ctx.db); |
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index 514f3b539..bc2cb4a0f 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs | |||
@@ -1,4 +1,5 @@ | |||
1 | //! This modules takes care of rendering various defenitions as completion items. | 1 | //! This modules takes care of rendering various defenitions as completion items. |
2 | use join_to_string::join; | ||
2 | use test_utils::tested_by; | 3 | use test_utils::tested_by; |
3 | use hir::Docs; | 4 | use hir::Docs; |
4 | 5 | ||
@@ -60,6 +61,21 @@ impl Completions { | |||
60 | } | 61 | } |
61 | self.add(builder) | 62 | self.add(builder) |
62 | } | 63 | } |
64 | |||
65 | pub(crate) fn add_enum_variant(&mut self, ctx: &CompletionContext, variant: hir::EnumVariant) { | ||
66 | let name = match variant.name(ctx.db) { | ||
67 | Some(it) => it, | ||
68 | None => return, | ||
69 | }; | ||
70 | let detail_types = variant.fields(ctx.db).into_iter().map(|field| field.ty(ctx.db)); | ||
71 | let detail = join(detail_types).separator(", ").surround_with("(", ")").to_string(); | ||
72 | |||
73 | CompletionItem::new(CompletionKind::Reference, ctx.source_range(), name.to_string()) | ||
74 | .kind(CompletionItemKind::EnumVariant) | ||
75 | .set_documentation(variant.docs(ctx.db)) | ||
76 | .detail(detail) | ||
77 | .add_to(self); | ||
78 | } | ||
63 | } | 79 | } |
64 | 80 | ||
65 | fn function_item_label(ctx: &CompletionContext, function: hir::Function) -> Option<String> { | 81 | fn function_item_label(ctx: &CompletionContext, function: hir::Function) -> Option<String> { |