diff options
Diffstat (limited to 'crates/ra_ide')
-rw-r--r-- | crates/ra_ide/src/call_info.rs | 14 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/complete_path.rs | 32 | ||||
-rw-r--r-- | crates/ra_ide/src/completion/presentation.rs | 6 | ||||
-rw-r--r-- | crates/ra_ide/src/display/function_signature.rs | 4 |
4 files changed, 52 insertions, 4 deletions
diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs index 2b35a3803..39d09a07f 100644 --- a/crates/ra_ide/src/call_info.rs +++ b/crates/ra_ide/src/call_info.rs | |||
@@ -544,6 +544,20 @@ fn main() { | |||
544 | } | 544 | } |
545 | 545 | ||
546 | #[test] | 546 | #[test] |
547 | fn generic_struct() { | ||
548 | let info = call_info( | ||
549 | r#" | ||
550 | struct TS<T>(T); | ||
551 | fn main() { | ||
552 | let s = TS(<|>); | ||
553 | }"#, | ||
554 | ); | ||
555 | |||
556 | assert_eq!(info.label(), "struct TS<T>(T) -> TS"); | ||
557 | assert_eq!(info.active_parameter, Some(0)); | ||
558 | } | ||
559 | |||
560 | #[test] | ||
547 | #[should_panic] | 561 | #[should_panic] |
548 | fn cant_call_named_structs() { | 562 | fn cant_call_named_structs() { |
549 | let _ = call_info( | 563 | let _ = call_info( |
diff --git a/crates/ra_ide/src/completion/complete_path.rs b/crates/ra_ide/src/completion/complete_path.rs index 65b3bf6e6..3db17f15f 100644 --- a/crates/ra_ide/src/completion/complete_path.rs +++ b/crates/ra_ide/src/completion/complete_path.rs | |||
@@ -1005,4 +1005,36 @@ mod tests { | |||
1005 | "### | 1005 | "### |
1006 | ); | 1006 | ); |
1007 | } | 1007 | } |
1008 | |||
1009 | #[test] | ||
1010 | fn completes_hashmap_new() { | ||
1011 | assert_debug_snapshot!( | ||
1012 | do_reference_completion( | ||
1013 | r" | ||
1014 | struct RandomState; | ||
1015 | struct HashMap<K, V, S = RandomState> {} | ||
1016 | |||
1017 | impl<K, V> HashMap<K, V, RandomState> { | ||
1018 | pub fn new() -> HashMap<K, V, RandomState> { } | ||
1019 | } | ||
1020 | fn foo() { | ||
1021 | HashMap::<|> | ||
1022 | } | ||
1023 | " | ||
1024 | ), | ||
1025 | @r###" | ||
1026 | [ | ||
1027 | CompletionItem { | ||
1028 | label: "new()", | ||
1029 | source_range: [292; 292), | ||
1030 | delete: [292; 292), | ||
1031 | insert: "new()$0", | ||
1032 | kind: Function, | ||
1033 | lookup: "new", | ||
1034 | detail: "pub fn new() -> HashMap<K, V, RandomState>", | ||
1035 | }, | ||
1036 | ] | ||
1037 | "### | ||
1038 | ); | ||
1039 | } | ||
1008 | } | 1040 | } |
diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index a4e9aefe2..910844244 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs | |||
@@ -273,8 +273,10 @@ impl Completions { | |||
273 | pub(crate) fn add_enum_variant(&mut self, ctx: &CompletionContext, variant: hir::EnumVariant) { | 273 | pub(crate) fn add_enum_variant(&mut self, ctx: &CompletionContext, variant: hir::EnumVariant) { |
274 | let is_deprecated = is_deprecated(variant, ctx.db); | 274 | let is_deprecated = is_deprecated(variant, ctx.db); |
275 | let name = variant.name(ctx.db); | 275 | let name = variant.name(ctx.db); |
276 | let detail_types = | 276 | let detail_types = variant |
277 | variant.fields(ctx.db).into_iter().map(|field| (field.name(ctx.db), field.ty(ctx.db))); | 277 | .fields(ctx.db) |
278 | .into_iter() | ||
279 | .map(|field| (field.name(ctx.db), field.signature_ty(ctx.db))); | ||
278 | let detail = match variant.kind(ctx.db) { | 280 | let detail = match variant.kind(ctx.db) { |
279 | StructKind::Tuple | StructKind::Unit => { | 281 | StructKind::Tuple | StructKind::Unit => { |
280 | join(detail_types.map(|(_, t)| t.display(ctx.db).to_string())) | 282 | join(detail_types.map(|(_, t)| t.display(ctx.db).to_string())) |
diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs index 2c4c932de..ec1bbd5a0 100644 --- a/crates/ra_ide/src/display/function_signature.rs +++ b/crates/ra_ide/src/display/function_signature.rs | |||
@@ -64,7 +64,7 @@ impl FunctionSignature { | |||
64 | .fields(db) | 64 | .fields(db) |
65 | .into_iter() | 65 | .into_iter() |
66 | .map(|field: hir::StructField| { | 66 | .map(|field: hir::StructField| { |
67 | let ty = field.ty(db); | 67 | let ty = field.signature_ty(db); |
68 | format!("{}", ty.display(db)) | 68 | format!("{}", ty.display(db)) |
69 | }) | 69 | }) |
70 | .collect(); | 70 | .collect(); |
@@ -102,7 +102,7 @@ impl FunctionSignature { | |||
102 | .into_iter() | 102 | .into_iter() |
103 | .map(|field: hir::StructField| { | 103 | .map(|field: hir::StructField| { |
104 | let name = field.name(db); | 104 | let name = field.name(db); |
105 | let ty = field.ty(db); | 105 | let ty = field.signature_ty(db); |
106 | format!("{}: {}", name, ty.display(db)) | 106 | format!("{}: {}", name, ty.display(db)) |
107 | }) | 107 | }) |
108 | .collect(); | 108 | .collect(); |