diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-02-17 10:54:32 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-02-17 10:54:32 +0000 |
commit | fcf15cc05afaeda6880664777ff2a3db342ea088 (patch) | |
tree | ac34e90a9884d7166daa5022ea402196483c26c0 /crates/ra_hir | |
parent | 334f53465f5baf5094844ab3ca2d28e477d07b24 (diff) | |
parent | 0e260aa6b15d9dc8c067adb05f3774aec3fb66ec (diff) |
Merge #3169
3169: Show record field names in Enum completion r=flodiebold a=adamrk
Adresses https://github.com/rust-analyzer/rust-analyzer/issues/2947.
Previously the details shown when autocompleting an Enum variant would look like the variant was a tuple even if it was a record:
![2020-02-16-15:59:32_crop](https://user-images.githubusercontent.com/16367467/74607233-64f21980-50d7-11ea-99db-e973e29c71d7.png)
This change will show the names of the fields for a record and use curly braces instead of parentheses:
![2020-02-16-15:33:00_crop](https://user-images.githubusercontent.com/16367467/74607251-8ce17d00-50d7-11ea-9d4d-38d198a4aec0.png)
This required exposing the type `adt::StructKind` from `ra_hir` and adding a function
```
kind(self, db: &impl HirDatabase) -> StructKind
```
in the `impl` of `EnumVariant`.
There was also a previously existing function `is_unit(self, db: &impl HirDatabase) -> bool` for `EnumVariant` which I removed because it seemed redundant after adding `kind`.
Co-authored-by: adamrk <[email protected]>
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 1 |
2 files changed, 6 insertions, 0 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index a56b8ab04..b6adb7589 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -3,6 +3,7 @@ use std::sync::Arc; | |||
3 | 3 | ||
4 | use either::Either; | 4 | use either::Either; |
5 | use hir_def::{ | 5 | use hir_def::{ |
6 | adt::StructKind, | ||
6 | adt::VariantData, | 7 | adt::VariantData, |
7 | builtin_type::BuiltinType, | 8 | builtin_type::BuiltinType, |
8 | docs::Documentation, | 9 | docs::Documentation, |
@@ -424,6 +425,10 @@ impl EnumVariant { | |||
424 | .collect() | 425 | .collect() |
425 | } | 426 | } |
426 | 427 | ||
428 | pub fn kind(self, db: &impl HirDatabase) -> StructKind { | ||
429 | self.variant_data(db).kind() | ||
430 | } | ||
431 | |||
427 | pub(crate) fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> { | 432 | pub(crate) fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> { |
428 | db.enum_data(self.parent.id).variants[self.id].variant_data.clone() | 433 | db.enum_data(self.parent.id).variants[self.id].variant_data.clone() |
429 | } | 434 | } |
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index 5cd965f7a..7a9745ebe 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -50,6 +50,7 @@ pub use crate::{ | |||
50 | }; | 50 | }; |
51 | 51 | ||
52 | pub use hir_def::{ | 52 | pub use hir_def::{ |
53 | adt::StructKind, | ||
53 | body::scope::ExprScopes, | 54 | body::scope::ExprScopes, |
54 | builtin_type::BuiltinType, | 55 | builtin_type::BuiltinType, |
55 | docs::Documentation, | 56 | docs::Documentation, |