aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/completion/presentation.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide/src/completion/presentation.rs')
-rw-r--r--crates/ra_ide/src/completion/presentation.rs22
1 files changed, 17 insertions, 5 deletions
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs
index 5213def20..253848602 100644
--- a/crates/ra_ide/src/completion/presentation.rs
+++ b/crates/ra_ide/src/completion/presentation.rs
@@ -1,6 +1,6 @@
1//! This modules takes care of rendering various definitions as completion items. 1//! This modules takes care of rendering various definitions as completion items.
2 2
3use hir::{db::HirDatabase, Docs, HasAttrs, HasSource, HirDisplay, ScopeDef, StructKind, Type}; 3use hir::{Docs, HasAttrs, HasSource, HirDisplay, ScopeDef, StructKind, Type};
4use join_to_string::join; 4use join_to_string::join;
5use ra_syntax::ast::NameOwner; 5use ra_syntax::ast::NameOwner;
6use test_utils::tested_by; 6use test_utils::tested_by;
@@ -9,7 +9,10 @@ use crate::completion::{
9 CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, Completions, 9 CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, Completions,
10}; 10};
11 11
12use crate::display::{const_label, macro_label, type_label, FunctionSignature}; 12use crate::{
13 display::{const_label, macro_label, type_label, FunctionSignature},
14 RootDatabase,
15};
13 16
14impl Completions { 17impl Completions {
15 pub(crate) fn add_field( 18 pub(crate) fn add_field(
@@ -273,8 +276,10 @@ impl Completions {
273 pub(crate) fn add_enum_variant(&mut self, ctx: &CompletionContext, variant: hir::EnumVariant) { 276 pub(crate) fn add_enum_variant(&mut self, ctx: &CompletionContext, variant: hir::EnumVariant) {
274 let is_deprecated = is_deprecated(variant, ctx.db); 277 let is_deprecated = is_deprecated(variant, ctx.db);
275 let name = variant.name(ctx.db); 278 let name = variant.name(ctx.db);
276 let detail_types = 279 let detail_types = variant
277 variant.fields(ctx.db).into_iter().map(|field| (field.name(ctx.db), field.ty(ctx.db))); 280 .fields(ctx.db)
281 .into_iter()
282 .map(|field| (field.name(ctx.db), field.signature_ty(ctx.db)));
278 let detail = match variant.kind(ctx.db) { 283 let detail = match variant.kind(ctx.db) {
279 StructKind::Tuple | StructKind::Unit => { 284 StructKind::Tuple | StructKind::Unit => {
280 join(detail_types.map(|(_, t)| t.display(ctx.db).to_string())) 285 join(detail_types.map(|(_, t)| t.display(ctx.db).to_string()))
@@ -298,7 +303,7 @@ impl Completions {
298 } 303 }
299} 304}
300 305
301fn is_deprecated(node: impl HasAttrs, db: &impl HirDatabase) -> bool { 306fn is_deprecated(node: impl HasAttrs, db: &RootDatabase) -> bool {
302 node.attrs(db).by_key("deprecated").exists() 307 node.attrs(db).by_key("deprecated").exists()
303} 308}
304 309
@@ -510,6 +515,7 @@ mod tests {
510 kind: Function, 515 kind: Function,
511 lookup: "with_args", 516 lookup: "with_args",
512 detail: "fn with_args(x: i32, y: String)", 517 detail: "fn with_args(x: i32, y: String)",
518 trigger_call_info: true,
513 }, 519 },
514 ] 520 ]
515 "### 521 "###
@@ -566,6 +572,7 @@ mod tests {
566 kind: Method, 572 kind: Method,
567 lookup: "foo", 573 lookup: "foo",
568 detail: "fn foo(&self, x: i32)", 574 detail: "fn foo(&self, x: i32)",
575 trigger_call_info: true,
569 }, 576 },
570 ] 577 ]
571 "### 578 "###
@@ -600,6 +607,7 @@ mod tests {
600 kind: Method, 607 kind: Method,
601 lookup: "foo", 608 lookup: "foo",
602 detail: "fn foo(&self, x: i32)", 609 detail: "fn foo(&self, x: i32)",
610 trigger_call_info: true,
603 }, 611 },
604 ] 612 ]
605 "### 613 "###
@@ -718,6 +726,7 @@ mod tests {
718 kind: Function, 726 kind: Function,
719 lookup: "foo", 727 lookup: "foo",
720 detail: "fn foo(xs: Ve)", 728 detail: "fn foo(xs: Ve)",
729 trigger_call_info: true,
721 }, 730 },
722 ] 731 ]
723 "### 732 "###
@@ -747,6 +756,7 @@ mod tests {
747 kind: Function, 756 kind: Function,
748 lookup: "foo", 757 lookup: "foo",
749 detail: "fn foo(xs: Ve)", 758 detail: "fn foo(xs: Ve)",
759 trigger_call_info: true,
750 }, 760 },
751 ] 761 ]
752 "### 762 "###
@@ -775,6 +785,7 @@ mod tests {
775 kind: Function, 785 kind: Function,
776 lookup: "foo", 786 lookup: "foo",
777 detail: "fn foo(xs: Ve)", 787 detail: "fn foo(xs: Ve)",
788 trigger_call_info: true,
778 }, 789 },
779 ] 790 ]
780 "### 791 "###
@@ -803,6 +814,7 @@ mod tests {
803 kind: Function, 814 kind: Function,
804 lookup: "foo", 815 lookup: "foo",
805 detail: "fn foo(xs: Ve<i128>)", 816 detail: "fn foo(xs: Ve<i128>)",
817 trigger_call_info: true,
806 }, 818 },
807 ] 819 ]
808 "### 820 "###