diff options
Diffstat (limited to 'crates/ra_hir/src/module.rs')
-rw-r--r-- | crates/ra_hir/src/module.rs | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/crates/ra_hir/src/module.rs b/crates/ra_hir/src/module.rs index 87e30191f..26171d27c 100644 --- a/crates/ra_hir/src/module.rs +++ b/crates/ra_hir/src/module.rs | |||
@@ -15,6 +15,7 @@ use relative_path::RelativePathBuf; | |||
15 | use crate::{ | 15 | use crate::{ |
16 | Def, DefKind, DefLoc, DefId, | 16 | Def, DefKind, DefLoc, DefId, |
17 | Name, Path, PathKind, HirDatabase, SourceItemId, SourceFileItemId, Crate, | 17 | Name, Path, PathKind, HirDatabase, SourceItemId, SourceFileItemId, Crate, |
18 | HirFileId, | ||
18 | arena::{Arena, Id}, | 19 | arena::{Arena, Id}, |
19 | }; | 20 | }; |
20 | 21 | ||
@@ -48,13 +49,17 @@ impl Module { | |||
48 | /// Returns `None` for the root module | 49 | /// Returns `None` for the root module |
49 | pub fn parent_link_source(&self, db: &impl HirDatabase) -> Option<(FileId, ast::ModuleNode)> { | 50 | pub fn parent_link_source(&self, db: &impl HirDatabase) -> Option<(FileId, ast::ModuleNode)> { |
50 | let link = self.module_id.parent_link(&self.tree)?; | 51 | let link = self.module_id.parent_link(&self.tree)?; |
51 | let file_id = link.owner(&self.tree).source(&self.tree).file_id(); | 52 | let file_id = link |
53 | .owner(&self.tree) | ||
54 | .source(&self.tree) | ||
55 | .file_id() | ||
56 | .as_original_file(); | ||
52 | let src = link.bind_source(&self.tree, db); | 57 | let src = link.bind_source(&self.tree, db); |
53 | Some((file_id, src)) | 58 | Some((file_id, src)) |
54 | } | 59 | } |
55 | 60 | ||
56 | pub fn source(&self) -> ModuleSource { | 61 | pub fn file_id(&self) -> FileId { |
57 | self.module_id.source(&self.tree) | 62 | self.source().file_id().as_original_file() |
58 | } | 63 | } |
59 | 64 | ||
60 | /// Parent module. Returns `None` if this is a root module. | 65 | /// Parent module. Returns `None` if this is a root module. |
@@ -69,7 +74,7 @@ impl Module { | |||
69 | /// Returns the crate this module is part of. | 74 | /// Returns the crate this module is part of. |
70 | pub fn krate(&self, db: &impl HirDatabase) -> Option<Crate> { | 75 | pub fn krate(&self, db: &impl HirDatabase) -> Option<Crate> { |
71 | let root_id = self.module_id.crate_root(&self.tree); | 76 | let root_id = self.module_id.crate_root(&self.tree); |
72 | let file_id = root_id.source(&self.tree).file_id(); | 77 | let file_id = root_id.source(&self.tree).file_id().as_original_file(); |
73 | let crate_graph = db.crate_graph(); | 78 | let crate_graph = db.crate_graph(); |
74 | let crate_id = crate_graph.crate_id_for_crate_root(file_id)?; | 79 | let crate_id = crate_graph.crate_id_for_crate_root(file_id)?; |
75 | Some(Crate::new(crate_id)) | 80 | Some(Crate::new(crate_id)) |
@@ -162,6 +167,10 @@ impl Module { | |||
162 | pub fn problems(&self, db: &impl HirDatabase) -> Vec<(SyntaxNode, Problem)> { | 167 | pub fn problems(&self, db: &impl HirDatabase) -> Vec<(SyntaxNode, Problem)> { |
163 | self.module_id.problems(&self.tree, db) | 168 | self.module_id.problems(&self.tree, db) |
164 | } | 169 | } |
170 | |||
171 | pub(crate) fn source(&self) -> ModuleSource { | ||
172 | self.module_id.source(&self.tree) | ||
173 | } | ||
165 | } | 174 | } |
166 | 175 | ||
167 | /// Physically, rust source is organized as a set of files, but logically it is | 176 | /// Physically, rust source is organized as a set of files, but logically it is |
@@ -291,18 +300,18 @@ pub struct ModuleData { | |||
291 | 300 | ||
292 | impl ModuleSource { | 301 | impl ModuleSource { |
293 | // precondition: item_id **must** point to module | 302 | // precondition: item_id **must** point to module |
294 | fn new(file_id: FileId, item_id: Option<SourceFileItemId>) -> ModuleSource { | 303 | fn new(file_id: HirFileId, item_id: Option<SourceFileItemId>) -> ModuleSource { |
295 | let source_item_id = SourceItemId { file_id, item_id }; | 304 | let source_item_id = SourceItemId { file_id, item_id }; |
296 | ModuleSource(source_item_id) | 305 | ModuleSource(source_item_id) |
297 | } | 306 | } |
298 | 307 | ||
299 | pub(crate) fn new_file(file_id: FileId) -> ModuleSource { | 308 | pub(crate) fn new_file(file_id: HirFileId) -> ModuleSource { |
300 | ModuleSource::new(file_id, None) | 309 | ModuleSource::new(file_id, None) |
301 | } | 310 | } |
302 | 311 | ||
303 | pub(crate) fn new_inline( | 312 | pub(crate) fn new_inline( |
304 | db: &impl HirDatabase, | 313 | db: &impl HirDatabase, |
305 | file_id: FileId, | 314 | file_id: HirFileId, |
306 | m: ast::Module, | 315 | m: ast::Module, |
307 | ) -> ModuleSource { | 316 | ) -> ModuleSource { |
308 | assert!(!m.has_semi()); | 317 | assert!(!m.has_semi()); |
@@ -311,7 +320,7 @@ impl ModuleSource { | |||
311 | ModuleSource::new(file_id, Some(item_id)) | 320 | ModuleSource::new(file_id, Some(item_id)) |
312 | } | 321 | } |
313 | 322 | ||
314 | pub fn file_id(self) -> FileId { | 323 | pub(crate) fn file_id(self) -> HirFileId { |
315 | self.0.file_id | 324 | self.0.file_id |
316 | } | 325 | } |
317 | 326 | ||