aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-02-17 10:54:32 +0000
committerGitHub <[email protected]>2020-02-17 10:54:32 +0000
commitfcf15cc05afaeda6880664777ff2a3db342ea088 (patch)
treeac34e90a9884d7166daa5022ea402196483c26c0 /crates/ra_hir_def
parent334f53465f5baf5094844ab3ca2d28e477d07b24 (diff)
parent0e260aa6b15d9dc8c067adb05f3774aec3fb66ec (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_def')
-rw-r--r--crates/ra_hir_def/src/adt.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs
index aac5f3e15..985f409e8 100644
--- a/crates/ra_hir_def/src/adt.rs
+++ b/crates/ra_hir_def/src/adt.rs
@@ -140,10 +140,11 @@ impl VariantData {
140 self.fields().iter().find_map(|(id, data)| if &data.name == name { Some(id) } else { None }) 140 self.fields().iter().find_map(|(id, data)| if &data.name == name { Some(id) } else { None })
141 } 141 }
142 142
143 pub fn is_unit(&self) -> bool { 143 pub fn kind(&self) -> StructKind {
144 match self { 144 match self {
145 VariantData::Unit => true, 145 VariantData::Record(_) => StructKind::Record,
146 _ => false, 146 VariantData::Tuple(_) => StructKind::Tuple,
147 VariantData::Unit => StructKind::Unit,
147 } 148 }
148 } 149 }
149} 150}
@@ -173,7 +174,7 @@ impl HasChildSource for VariantId {
173 } 174 }
174} 175}
175 176
176enum StructKind { 177pub enum StructKind {
177 Tuple, 178 Tuple,
178 Record, 179 Record,
179 Unit, 180 Unit,