diff options
author | Aleksey Kladov <[email protected]> | 2019-01-06 12:58:45 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-06 14:35:57 +0000 |
commit | a7f4f7bfcc524a55ba559e0141a70aa799a8686d (patch) | |
tree | 458eeb6cf17012239eae2fd107441b63575870ee /crates/ra_hir/src/code_model_api.rs | |
parent | 9cb02fd931f436a7b39c33c752799f5530b8491b (diff) |
split module source into decl/defin
Diffstat (limited to 'crates/ra_hir/src/code_model_api.rs')
-rw-r--r-- | crates/ra_hir/src/code_model_api.rs | 40 |
1 files changed, 35 insertions, 5 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index eca7d0225..0c7f743d4 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs | |||
@@ -1,6 +1,7 @@ | |||
1 | use ra_db::{CrateId, Cancelable}; | 1 | use ra_db::{CrateId, Cancelable, FileId}; |
2 | use ra_syntax::{ast, SyntaxNode}; | ||
2 | 3 | ||
3 | use crate::{Name, db::HirDatabase, DefId, Path, PerNs, module::{ModuleSource, ModuleScope}}; | 4 | use crate::{Name, db::HirDatabase, DefId, Path, PerNs, module::{Problem, ModuleScope}}; |
4 | 5 | ||
5 | /// hir::Crate describes a single crate. It's the main inteface with which | 6 | /// hir::Crate describes a single crate. It's the main inteface with which |
6 | /// crate's dependencies interact. Mostly, it should be just a proxy for the | 7 | /// crate's dependencies interact. Mostly, it should be just a proxy for the |
@@ -33,10 +34,27 @@ pub struct Module { | |||
33 | pub(crate) def_id: DefId, | 34 | pub(crate) def_id: DefId, |
34 | } | 35 | } |
35 | 36 | ||
37 | /// An owned syntax node for a module. Unlike `ModuleSource`, | ||
38 | /// this holds onto the AST for the whole file. | ||
39 | pub enum ModuleSource { | ||
40 | SourceFile(ast::SourceFileNode), | ||
41 | Module(ast::ModuleNode), | ||
42 | } | ||
43 | |||
36 | impl Module { | 44 | impl Module { |
37 | // FIXME: what is a module source exactly? It should contain two nodes | 45 | pub fn name(&self, db: &impl HirDatabase) -> Cancelable<Option<Name>> { |
38 | pub fn source(&self, db: &impl HirDatabase) -> Cancelable<ModuleSource> { | 46 | self.name_impl(db) |
39 | Ok(self.source_impl(db)) | 47 | } |
48 | |||
49 | pub fn defenition_source(&self, db: &impl HirDatabase) -> Cancelable<(FileId, ModuleSource)> { | ||
50 | self.defenition_source_impl(db) | ||
51 | } | ||
52 | |||
53 | pub fn declaration_source( | ||
54 | &self, | ||
55 | db: &impl HirDatabase, | ||
56 | ) -> Cancelable<Option<(FileId, ast::ModuleNode)>> { | ||
57 | self.declaration_source_impl(db) | ||
40 | } | 58 | } |
41 | 59 | ||
42 | /// Returns the crate this module is part of. | 60 | /// Returns the crate this module is part of. |
@@ -56,6 +74,15 @@ impl Module { | |||
56 | pub fn parent(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> { | 74 | pub fn parent(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> { |
57 | self.parent_impl(db) | 75 | self.parent_impl(db) |
58 | } | 76 | } |
77 | pub fn path_to_root(&self, db: &impl HirDatabase) -> Cancelable<Vec<Module>> { | ||
78 | let mut res = vec![self.clone()]; | ||
79 | let mut curr = self.clone(); | ||
80 | while let Some(next) = curr.parent(db)? { | ||
81 | res.push(next.clone()); | ||
82 | curr = next | ||
83 | } | ||
84 | Ok(res) | ||
85 | } | ||
59 | /// Returns a `ModuleScope`: a set of items, visible in this module. | 86 | /// Returns a `ModuleScope`: a set of items, visible in this module. |
60 | pub fn scope(&self, db: &impl HirDatabase) -> Cancelable<ModuleScope> { | 87 | pub fn scope(&self, db: &impl HirDatabase) -> Cancelable<ModuleScope> { |
61 | self.scope_impl(db) | 88 | self.scope_impl(db) |
@@ -63,4 +90,7 @@ impl Module { | |||
63 | pub fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> Cancelable<PerNs<DefId>> { | 90 | pub fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> Cancelable<PerNs<DefId>> { |
64 | self.resolve_path_impl(db, path) | 91 | self.resolve_path_impl(db, path) |
65 | } | 92 | } |
93 | pub fn problems(&self, db: &impl HirDatabase) -> Cancelable<Vec<(SyntaxNode, Problem)>> { | ||
94 | self.problems_impl(db) | ||
95 | } | ||
66 | } | 96 | } |