diff options
Diffstat (limited to 'crates/ra_hir/src/ids.rs')
-rw-r--r-- | crates/ra_hir/src/ids.rs | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index 0aa687a08..c75ef4ae7 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs | |||
@@ -3,7 +3,7 @@ use ra_syntax::{TreePtr, SyntaxKind, SyntaxNode, SourceFile, AstNode, ast}; | |||
3 | use ra_arena::{Arena, RawId, impl_arena_id}; | 3 | use ra_arena::{Arena, RawId, impl_arena_id}; |
4 | 4 | ||
5 | use crate::{ | 5 | use crate::{ |
6 | HirDatabase, PerNs, Def, Function, Struct, Enum, ImplBlock, Crate, | 6 | HirDatabase, PerNs, Def, Function, Struct, Enum, EnumVariant, ImplBlock, Crate, |
7 | module_tree::ModuleId, | 7 | module_tree::ModuleId, |
8 | }; | 8 | }; |
9 | 9 | ||
@@ -34,7 +34,7 @@ pub struct HirFileId(HirFileIdRepr); | |||
34 | impl HirFileId { | 34 | impl HirFileId { |
35 | /// For macro-expansion files, returns the file original source file the | 35 | /// For macro-expansion files, returns the file original source file the |
36 | /// expansionoriginated from. | 36 | /// expansionoriginated from. |
37 | pub(crate) fn original_file(self, db: &impl HirDatabase) -> FileId { | 37 | pub fn original_file(self, db: &impl HirDatabase) -> FileId { |
38 | match self.0 { | 38 | match self.0 { |
39 | HirFileIdRepr::File(file_id) => file_id, | 39 | HirFileIdRepr::File(file_id) => file_id, |
40 | HirFileIdRepr::Macro(macro_call_id) => { | 40 | HirFileIdRepr::Macro(macro_call_id) => { |
@@ -145,6 +145,7 @@ pub(crate) enum DefKind { | |||
145 | Function, | 145 | Function, |
146 | Struct, | 146 | Struct, |
147 | Enum, | 147 | Enum, |
148 | EnumVariant, | ||
148 | Item, | 149 | Item, |
149 | 150 | ||
150 | StructCtor, | 151 | StructCtor, |
@@ -170,16 +171,20 @@ impl DefId { | |||
170 | let struct_def = Struct::new(self); | 171 | let struct_def = Struct::new(self); |
171 | Def::Struct(struct_def) | 172 | Def::Struct(struct_def) |
172 | } | 173 | } |
173 | DefKind::Enum => { | 174 | DefKind::Enum => Def::Enum(Enum::new(self)), |
174 | let enum_def = Enum::new(self); | 175 | DefKind::EnumVariant => Def::EnumVariant(EnumVariant::new(self)), |
175 | Def::Enum(enum_def) | ||
176 | } | ||
177 | DefKind::StructCtor => Def::Item, | 176 | DefKind::StructCtor => Def::Item, |
178 | DefKind::Item => Def::Item, | 177 | DefKind::Item => Def::Item, |
179 | }; | 178 | }; |
180 | Ok(res) | 179 | Ok(res) |
181 | } | 180 | } |
182 | 181 | ||
182 | pub(crate) fn source(self, db: &impl HirDatabase) -> (HirFileId, TreePtr<SyntaxNode>) { | ||
183 | let loc = self.loc(db); | ||
184 | let syntax = db.file_item(loc.source_item_id); | ||
185 | (loc.source_item_id.file_id, syntax) | ||
186 | } | ||
187 | |||
183 | /// For a module, returns that module; for any other def, returns the containing module. | 188 | /// For a module, returns that module; for any other def, returns the containing module. |
184 | pub fn module(self, db: &impl HirDatabase) -> Cancelable<Module> { | 189 | pub fn module(self, db: &impl HirDatabase) -> Cancelable<Module> { |
185 | let loc = self.loc(db); | 190 | let loc = self.loc(db); |
@@ -258,7 +263,9 @@ impl SourceFileItems { | |||
258 | // change parent's id. This means that, say, adding a new function to a | 263 | // change parent's id. This means that, say, adding a new function to a |
259 | // trait does not chage ids of top-level items, which helps caching. | 264 | // trait does not chage ids of top-level items, which helps caching. |
260 | bfs(source_file.syntax(), |it| { | 265 | bfs(source_file.syntax(), |it| { |
261 | if let Some(module_item) = ast::ModuleItem::cast(it) { | 266 | if let Some(enum_variant) = ast::EnumVariant::cast(it) { |
267 | self.alloc(enum_variant.syntax().to_owned()); | ||
268 | } else if let Some(module_item) = ast::ModuleItem::cast(it) { | ||
262 | self.alloc(module_item.syntax().to_owned()); | 269 | self.alloc(module_item.syntax().to_owned()); |
263 | } else if let Some(macro_call) = ast::MacroCall::cast(it) { | 270 | } else if let Some(macro_call) = ast::MacroCall::cast(it) { |
264 | self.alloc(macro_call.syntax().to_owned()); | 271 | self.alloc(macro_call.syntax().to_owned()); |