diff options
author | Aleksey Kladov <[email protected]> | 2019-01-24 15:56:38 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-24 15:56:38 +0000 |
commit | 566c8e321e89e5ff8996daa615cc47aea0012881 (patch) | |
tree | 58c2f4741b9305e840d41eb35eb8f4e7d5761fe2 /crates/ra_hir/src/code_model_api.rs | |
parent | cefc5cbb4a95d2a473ea656efe603bef979b5c49 (diff) |
migrate enums to new id
Diffstat (limited to 'crates/ra_hir/src/code_model_api.rs')
-rw-r--r-- | crates/ra_hir/src/code_model_api.rs | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 948718aa6..0a96d6f6d 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs | |||
@@ -16,7 +16,7 @@ use crate::{ | |||
16 | code_model_impl::def_id_to_ast, | 16 | code_model_impl::def_id_to_ast, |
17 | docs::{Documentation, Docs, docs_from_ast}, | 17 | docs::{Documentation, Docs, docs_from_ast}, |
18 | module_tree::ModuleId, | 18 | module_tree::ModuleId, |
19 | ids::{FunctionId, StructId}, | 19 | ids::{FunctionId, StructId, EnumId}, |
20 | }; | 20 | }; |
21 | 21 | ||
22 | /// hir::Crate describes a single crate. It's the main interface with which | 22 | /// hir::Crate describes a single crate. It's the main interface with which |
@@ -69,30 +69,37 @@ pub enum ModuleDef { | |||
69 | Module(Module), | 69 | Module(Module), |
70 | Function(Function), | 70 | Function(Function), |
71 | Struct(Struct), | 71 | Struct(Struct), |
72 | Enum(Enum), | ||
72 | Def(DefId), | 73 | Def(DefId), |
73 | } | 74 | } |
75 | //FIXME: change to from | ||
76 | impl From<Module> for ModuleDef { | ||
77 | fn from(it: Module) -> ModuleDef { | ||
78 | ModuleDef::Module(it) | ||
79 | } | ||
80 | } | ||
74 | 81 | ||
75 | impl Into<ModuleDef> for Module { | 82 | impl From<Function> for ModuleDef { |
76 | fn into(self) -> ModuleDef { | 83 | fn from(it: Function) -> ModuleDef { |
77 | ModuleDef::Module(self) | 84 | ModuleDef::Function(it) |
78 | } | 85 | } |
79 | } | 86 | } |
80 | 87 | ||
81 | impl Into<ModuleDef> for Function { | 88 | impl From<Struct> for ModuleDef { |
82 | fn into(self) -> ModuleDef { | 89 | fn from(it: Struct) -> ModuleDef { |
83 | ModuleDef::Function(self) | 90 | ModuleDef::Struct(it) |
84 | } | 91 | } |
85 | } | 92 | } |
86 | 93 | ||
87 | impl Into<ModuleDef> for Struct { | 94 | impl From<Enum> for ModuleDef { |
88 | fn into(self) -> ModuleDef { | 95 | fn from(it: Enum) -> ModuleDef { |
89 | ModuleDef::Struct(self) | 96 | ModuleDef::Enum(it) |
90 | } | 97 | } |
91 | } | 98 | } |
92 | 99 | ||
93 | impl Into<ModuleDef> for DefId { | 100 | impl From<DefId> for ModuleDef { |
94 | fn into(self) -> ModuleDef { | 101 | fn from(it: DefId) -> ModuleDef { |
95 | ModuleDef::Def(self) | 102 | ModuleDef::Def(it) |
96 | } | 103 | } |
97 | } | 104 | } |
98 | 105 | ||
@@ -249,34 +256,30 @@ impl Docs for Struct { | |||
249 | } | 256 | } |
250 | } | 257 | } |
251 | 258 | ||
252 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 259 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
253 | pub struct Enum { | 260 | pub struct Enum { |
254 | pub(crate) def_id: DefId, | 261 | pub(crate) id: EnumId, |
255 | } | 262 | } |
256 | 263 | ||
257 | impl Enum { | 264 | impl Enum { |
258 | pub(crate) fn new(def_id: DefId) -> Self { | 265 | pub fn module(&self, db: &impl HirDatabase) -> Module { |
259 | Enum { def_id } | 266 | self.id.loc(db).module |
260 | } | ||
261 | |||
262 | pub fn def_id(&self) -> DefId { | ||
263 | self.def_id | ||
264 | } | 267 | } |
265 | 268 | ||
266 | pub fn name(&self, db: &impl HirDatabase) -> Option<Name> { | 269 | pub fn name(&self, db: &impl HirDatabase) -> Option<Name> { |
267 | db.enum_data(self.def_id).name.clone() | 270 | db.enum_data(*self).name.clone() |
268 | } | 271 | } |
269 | 272 | ||
270 | pub fn variants(&self, db: &impl HirDatabase) -> Vec<(Name, EnumVariant)> { | 273 | pub fn variants(&self, db: &impl HirDatabase) -> Vec<(Name, EnumVariant)> { |
271 | db.enum_data(self.def_id).variants.clone() | 274 | db.enum_data(*self).variants.clone() |
272 | } | 275 | } |
273 | 276 | ||
274 | pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::EnumDef>) { | 277 | pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::EnumDef>) { |
275 | def_id_to_ast(db, self.def_id) | 278 | self.id.loc(db).source(db) |
276 | } | 279 | } |
277 | 280 | ||
278 | pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { | 281 | pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> { |
279 | db.generic_params(self.def_id.into()) | 282 | db.generic_params((*self).into()) |
280 | } | 283 | } |
281 | } | 284 | } |
282 | 285 | ||