diff options
Diffstat (limited to 'crates/ra_hir/src/code_model_api.rs')
-rw-r--r-- | crates/ra_hir/src/code_model_api.rs | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index fa3e4baa7..725bc7d80 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs | |||
@@ -44,6 +44,7 @@ pub enum Def { | |||
44 | Module(Module), | 44 | Module(Module), |
45 | Struct(Struct), | 45 | Struct(Struct), |
46 | Enum(Enum), | 46 | Enum(Enum), |
47 | EnumVariant(EnumVariant), | ||
47 | Function(Function), | 48 | Function(Function), |
48 | Item, | 49 | Item, |
49 | } | 50 | } |
@@ -188,6 +189,10 @@ pub struct Enum { | |||
188 | } | 189 | } |
189 | 190 | ||
190 | impl Enum { | 191 | impl Enum { |
192 | pub(crate) fn new(def_id: DefId) -> Self { | ||
193 | Enum { def_id } | ||
194 | } | ||
195 | |||
191 | pub fn def_id(&self) -> DefId { | 196 | pub fn def_id(&self) -> DefId { |
192 | self.def_id | 197 | self.def_id |
193 | } | 198 | } |
@@ -196,12 +201,39 @@ impl Enum { | |||
196 | Ok(db.enum_data(self.def_id)?.name.clone()) | 201 | Ok(db.enum_data(self.def_id)?.name.clone()) |
197 | } | 202 | } |
198 | 203 | ||
199 | pub fn variants(&self, db: &impl HirDatabase) -> Cancelable<Vec<(Name, Arc<VariantData>)>> { | 204 | pub fn variants(&self, db: &impl HirDatabase) -> Cancelable<Vec<(Name, EnumVariant)>> { |
200 | Ok(db.enum_data(self.def_id)?.variants.clone()) | 205 | Ok(db.enum_data(self.def_id)?.variants.clone()) |
201 | } | 206 | } |
202 | } | 207 | } |
203 | 208 | ||
204 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 209 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
210 | pub struct EnumVariant { | ||
211 | pub(crate) def_id: DefId, | ||
212 | } | ||
213 | |||
214 | impl EnumVariant { | ||
215 | pub(crate) fn new(def_id: DefId) -> Self { | ||
216 | EnumVariant { def_id } | ||
217 | } | ||
218 | |||
219 | pub fn def_id(&self) -> DefId { | ||
220 | self.def_id | ||
221 | } | ||
222 | |||
223 | pub fn parent_enum(&self, db: &impl HirDatabase) -> Cancelable<Enum> { | ||
224 | Ok(db.enum_variant_data(self.def_id)?.parent_enum.clone()) | ||
225 | } | ||
226 | |||
227 | pub fn name(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> { | ||
228 | Ok(db.enum_variant_data(self.def_id)?.name.clone()) | ||
229 | } | ||
230 | |||
231 | pub fn variant_data(&self, db: &impl HirDatabase) -> Cancelable<Arc<VariantData>> { | ||
232 | Ok(db.enum_variant_data(self.def_id)?.variant_data.clone()) | ||
233 | } | ||
234 | } | ||
235 | |||
236 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
205 | pub struct Function { | 237 | pub struct Function { |
206 | pub(crate) def_id: DefId, | 238 | pub(crate) def_id: DefId, |
207 | } | 239 | } |