diff options
author | Aleksey Kladov <[email protected]> | 2019-01-11 18:02:12 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-11 18:02:12 +0000 |
commit | f193fbcbae0783953cfaa88aaec6a8d4e1255007 (patch) | |
tree | c57734dc82350c2d853f557a40f7aafdc7470bdf /crates/ra_hir/src | |
parent | 19136cde000c2c227e79bf44febde990fe265cb7 (diff) |
actually produce missing def kinds
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r-- | crates/ra_hir/src/code_model_api.rs | 48 | ||||
-rw-r--r-- | crates/ra_hir/src/ids.rs | 32 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/ty.rs | 8 |
4 files changed, 82 insertions, 8 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 5f61bb589..d4244f70c 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs | |||
@@ -41,12 +41,17 @@ impl Crate { | |||
41 | } | 41 | } |
42 | } | 42 | } |
43 | 43 | ||
44 | #[derive(Debug)] | ||
44 | pub enum Def { | 45 | pub enum Def { |
45 | Module(Module), | 46 | Module(Module), |
46 | Struct(Struct), | 47 | Struct(Struct), |
47 | Enum(Enum), | 48 | Enum(Enum), |
48 | EnumVariant(EnumVariant), | 49 | EnumVariant(EnumVariant), |
49 | Function(Function), | 50 | Function(Function), |
51 | Const(Const), | ||
52 | Static(Static), | ||
53 | Trait(Trait), | ||
54 | Type(Type), | ||
50 | Item, | 55 | Item, |
51 | } | 56 | } |
52 | 57 | ||
@@ -317,17 +322,60 @@ pub struct Const { | |||
317 | pub(crate) def_id: DefId, | 322 | pub(crate) def_id: DefId, |
318 | } | 323 | } |
319 | 324 | ||
325 | impl Const { | ||
326 | pub(crate) fn new(def_id: DefId) -> Const { | ||
327 | Const { def_id } | ||
328 | } | ||
329 | |||
330 | pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc<ast::ConstDef>)> { | ||
331 | Ok(def_id_to_ast(db, self.def_id)) | ||
332 | } | ||
333 | } | ||
334 | |||
320 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 335 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
321 | pub struct Static { | 336 | pub struct Static { |
322 | pub(crate) def_id: DefId, | 337 | pub(crate) def_id: DefId, |
323 | } | 338 | } |
324 | 339 | ||
340 | impl Static { | ||
341 | pub(crate) fn new(def_id: DefId) -> Static { | ||
342 | Static { def_id } | ||
343 | } | ||
344 | |||
345 | pub fn source( | ||
346 | &self, | ||
347 | db: &impl HirDatabase, | ||
348 | ) -> Cancelable<(HirFileId, TreeArc<ast::StaticDef>)> { | ||
349 | Ok(def_id_to_ast(db, self.def_id)) | ||
350 | } | ||
351 | } | ||
352 | |||
325 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 353 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
326 | pub struct Trait { | 354 | pub struct Trait { |
327 | pub(crate) def_id: DefId, | 355 | pub(crate) def_id: DefId, |
328 | } | 356 | } |
329 | 357 | ||
358 | impl Trait { | ||
359 | pub(crate) fn new(def_id: DefId) -> Trait { | ||
360 | Trait { def_id } | ||
361 | } | ||
362 | |||
363 | pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc<ast::TraitDef>)> { | ||
364 | Ok(def_id_to_ast(db, self.def_id)) | ||
365 | } | ||
366 | } | ||
367 | |||
330 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 368 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
331 | pub struct Type { | 369 | pub struct Type { |
332 | pub(crate) def_id: DefId, | 370 | pub(crate) def_id: DefId, |
333 | } | 371 | } |
372 | |||
373 | impl Type { | ||
374 | pub(crate) fn new(def_id: DefId) -> Type { | ||
375 | Type { def_id } | ||
376 | } | ||
377 | |||
378 | pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc<ast::TypeDef>)> { | ||
379 | Ok(def_id_to_ast(db, self.def_id)) | ||
380 | } | ||
381 | } | ||
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index 0805fd3db..316896dce 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs | |||
@@ -4,11 +4,10 @@ use ra_arena::{Arena, RawId, impl_arena_id}; | |||
4 | 4 | ||
5 | use crate::{ | 5 | use crate::{ |
6 | HirDatabase, PerNs, Def, Function, Struct, Enum, EnumVariant, ImplBlock, Crate, | 6 | HirDatabase, PerNs, Def, Function, Struct, Enum, EnumVariant, ImplBlock, Crate, |
7 | Module, Trait, Type, Static, Const, | ||
7 | module_tree::ModuleId, | 8 | module_tree::ModuleId, |
8 | }; | 9 | }; |
9 | 10 | ||
10 | use crate::code_model_api::Module; | ||
11 | |||
12 | /// hir makes heavy use of ids: integer (u32) handlers to various things. You | 11 | /// hir makes heavy use of ids: integer (u32) handlers to various things. You |
13 | /// can think of id as a pointer (but without a lifetime) or a file descriptor | 12 | /// can think of id as a pointer (but without a lifetime) or a file descriptor |
14 | /// (but for hir objects). | 13 | /// (but for hir objects). |
@@ -146,6 +145,10 @@ pub(crate) enum DefKind { | |||
146 | Struct, | 145 | Struct, |
147 | Enum, | 146 | Enum, |
148 | EnumVariant, | 147 | EnumVariant, |
148 | Const, | ||
149 | Static, | ||
150 | Trait, | ||
151 | Type, | ||
149 | Item, | 152 | Item, |
150 | 153 | ||
151 | StructCtor, | 154 | StructCtor, |
@@ -173,6 +176,23 @@ impl DefId { | |||
173 | } | 176 | } |
174 | DefKind::Enum => Def::Enum(Enum::new(self)), | 177 | DefKind::Enum => Def::Enum(Enum::new(self)), |
175 | DefKind::EnumVariant => Def::EnumVariant(EnumVariant::new(self)), | 178 | DefKind::EnumVariant => Def::EnumVariant(EnumVariant::new(self)), |
179 | DefKind::Const => { | ||
180 | let def = Const::new(self); | ||
181 | Def::Const(def) | ||
182 | } | ||
183 | DefKind::Static => { | ||
184 | let def = Static::new(self); | ||
185 | Def::Static(def) | ||
186 | } | ||
187 | DefKind::Trait => { | ||
188 | let def = Trait::new(self); | ||
189 | Def::Trait(def) | ||
190 | } | ||
191 | DefKind::Type => { | ||
192 | let def = Type::new(self); | ||
193 | Def::Type(def) | ||
194 | } | ||
195 | |||
176 | DefKind::StructCtor => Def::Item, | 196 | DefKind::StructCtor => Def::Item, |
177 | DefKind::Item => Def::Item, | 197 | DefKind::Item => Def::Item, |
178 | }; | 198 | }; |
@@ -218,10 +238,10 @@ impl DefKind { | |||
218 | SyntaxKind::STRUCT_DEF => PerNs::both(DefKind::Struct, DefKind::StructCtor), | 238 | SyntaxKind::STRUCT_DEF => PerNs::both(DefKind::Struct, DefKind::StructCtor), |
219 | SyntaxKind::ENUM_DEF => PerNs::types(DefKind::Enum), | 239 | SyntaxKind::ENUM_DEF => PerNs::types(DefKind::Enum), |
220 | // These define items, but don't have their own DefKinds yet: | 240 | // These define items, but don't have their own DefKinds yet: |
221 | SyntaxKind::TRAIT_DEF => PerNs::types(DefKind::Item), | 241 | SyntaxKind::TRAIT_DEF => PerNs::types(DefKind::Trait), |
222 | SyntaxKind::TYPE_DEF => PerNs::types(DefKind::Item), | 242 | SyntaxKind::TYPE_DEF => PerNs::types(DefKind::Type), |
223 | SyntaxKind::CONST_DEF => PerNs::values(DefKind::Item), | 243 | SyntaxKind::CONST_DEF => PerNs::values(DefKind::Const), |
224 | SyntaxKind::STATIC_DEF => PerNs::values(DefKind::Item), | 244 | SyntaxKind::STATIC_DEF => PerNs::values(DefKind::Static), |
225 | _ => PerNs::none(), | 245 | _ => PerNs::none(), |
226 | } | 246 | } |
227 | } | 247 | } |
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index fe8be5700..45dda4f7f 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -60,4 +60,6 @@ pub use self::code_model_api::{ | |||
60 | Module, ModuleSource, Problem, | 60 | Module, ModuleSource, Problem, |
61 | Struct, Enum, EnumVariant, | 61 | Struct, Enum, EnumVariant, |
62 | Function, FnSignature, ScopeEntryWithSyntax, | 62 | Function, FnSignature, ScopeEntryWithSyntax, |
63 | Static, Const, | ||
64 | Trait, Type, | ||
63 | }; | 65 | }; |
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 18c41a015..0c24a0652 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -470,8 +470,12 @@ pub(super) fn type_for_def(db: &impl HirDatabase, def_id: DefId) -> Cancelable<T | |||
470 | Def::Struct(s) => type_for_struct(db, s), | 470 | Def::Struct(s) => type_for_struct(db, s), |
471 | Def::Enum(e) => type_for_enum(db, e), | 471 | Def::Enum(e) => type_for_enum(db, e), |
472 | Def::EnumVariant(ev) => type_for_enum_variant(db, ev), | 472 | Def::EnumVariant(ev) => type_for_enum_variant(db, ev), |
473 | Def::Item => { | 473 | _ => { |
474 | log::debug!("trying to get type for item of unknown type {:?}", def_id); | 474 | log::debug!( |
475 | "trying to get type for item of unknown type {:?} {:?}", | ||
476 | def_id, | ||
477 | def | ||
478 | ); | ||
475 | Ok(Ty::Unknown) | 479 | Ok(Ty::Unknown) |
476 | } | 480 | } |
477 | } | 481 | } |