diff options
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/src/code_model_api.rs | 26 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model_impl.rs (renamed from crates/ra_hir/src/krate.rs) | 22 | ||||
-rw-r--r-- | crates/ra_hir/src/lib.rs | 7 |
3 files changed, 34 insertions, 21 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs new file mode 100644 index 000000000..e8b3a1fb6 --- /dev/null +++ b/crates/ra_hir/src/code_model_api.rs | |||
@@ -0,0 +1,26 @@ | |||
1 | use ra_db::{CrateId, Cancelable}; | ||
2 | |||
3 | use crate::{Module, Name, db::HirDatabase}; | ||
4 | |||
5 | /// 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 | /// root module. | ||
8 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
9 | pub struct Crate { | ||
10 | pub(crate) crate_id: CrateId, | ||
11 | } | ||
12 | |||
13 | #[derive(Debug)] | ||
14 | pub struct CrateDependency { | ||
15 | pub krate: Crate, | ||
16 | pub name: Name, | ||
17 | } | ||
18 | |||
19 | impl Crate { | ||
20 | pub fn dependencies(&self, db: &impl HirDatabase) -> Vec<CrateDependency> { | ||
21 | self.dependencies_impl(db) | ||
22 | } | ||
23 | pub fn root_module(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> { | ||
24 | self.root_module_impl(db) | ||
25 | } | ||
26 | } | ||
diff --git a/crates/ra_hir/src/krate.rs b/crates/ra_hir/src/code_model_impl.rs index 5194e280b..75d4e04c1 100644 --- a/crates/ra_hir/src/krate.rs +++ b/crates/ra_hir/src/code_model_impl.rs | |||
@@ -1,26 +1,12 @@ | |||
1 | pub use ra_db::{CrateId, Cancelable}; | 1 | use ra_db::{CrateId, Cancelable}; |
2 | 2 | ||
3 | use crate::{HirDatabase, Module, Name, AsName, HirFileId}; | 3 | use crate::{Module, HirFileId, db::HirDatabase, Crate, CrateDependency, AsName}; |
4 | |||
5 | /// 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 | /// root module. | ||
8 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
9 | pub struct Crate { | ||
10 | crate_id: CrateId, | ||
11 | } | ||
12 | |||
13 | #[derive(Debug)] | ||
14 | pub struct CrateDependency { | ||
15 | pub krate: Crate, | ||
16 | pub name: Name, | ||
17 | } | ||
18 | 4 | ||
19 | impl Crate { | 5 | impl Crate { |
20 | pub(crate) fn new(crate_id: CrateId) -> Crate { | 6 | pub(crate) fn new(crate_id: CrateId) -> Crate { |
21 | Crate { crate_id } | 7 | Crate { crate_id } |
22 | } | 8 | } |
23 | pub fn dependencies(&self, db: &impl HirDatabase) -> Vec<CrateDependency> { | 9 | pub(crate) fn dependencies_impl(&self, db: &impl HirDatabase) -> Vec<CrateDependency> { |
24 | let crate_graph = db.crate_graph(); | 10 | let crate_graph = db.crate_graph(); |
25 | crate_graph | 11 | crate_graph |
26 | .dependencies(self.crate_id) | 12 | .dependencies(self.crate_id) |
@@ -31,7 +17,7 @@ impl Crate { | |||
31 | }) | 17 | }) |
32 | .collect() | 18 | .collect() |
33 | } | 19 | } |
34 | pub fn root_module(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> { | 20 | pub(crate) fn root_module_impl(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> { |
35 | let crate_graph = db.crate_graph(); | 21 | let crate_graph = db.crate_graph(); |
36 | let file_id = crate_graph.crate_root(self.crate_id); | 22 | let file_id = crate_graph.crate_root(self.crate_id); |
37 | let source_root_id = db.file_source_root(file_id); | 23 | let source_root_id = db.file_source_root(file_id); |
diff --git a/crates/ra_hir/src/lib.rs b/crates/ra_hir/src/lib.rs index d600b91df..0fe80deb5 100644 --- a/crates/ra_hir/src/lib.rs +++ b/crates/ra_hir/src/lib.rs | |||
@@ -24,8 +24,6 @@ pub mod source_binder; | |||
24 | mod ids; | 24 | mod ids; |
25 | mod macros; | 25 | mod macros; |
26 | mod name; | 26 | mod name; |
27 | // can't use `crate` or `r#crate` here :( | ||
28 | mod krate; | ||
29 | mod module; | 27 | mod module; |
30 | mod function; | 28 | mod function; |
31 | mod adt; | 29 | mod adt; |
@@ -34,16 +32,19 @@ mod ty; | |||
34 | mod impl_block; | 32 | mod impl_block; |
35 | mod expr; | 33 | mod expr; |
36 | 34 | ||
35 | pub mod code_model_api; | ||
36 | mod code_model_impl; | ||
37 | |||
37 | use crate::{ | 38 | use crate::{ |
38 | db::HirDatabase, | 39 | db::HirDatabase, |
39 | name::{AsName, KnownName}, | 40 | name::{AsName, KnownName}, |
40 | ids::{DefKind, SourceItemId, SourceFileItemId, SourceFileItems}, | 41 | ids::{DefKind, SourceItemId, SourceFileItemId, SourceFileItems}, |
42 | code_model_api::{Crate, CrateDependency} | ||
41 | }; | 43 | }; |
42 | 44 | ||
43 | pub use self::{ | 45 | pub use self::{ |
44 | path::{Path, PathKind}, | 46 | path::{Path, PathKind}, |
45 | name::Name, | 47 | name::Name, |
46 | krate::Crate, | ||
47 | ids::{HirFileId, DefId, DefLoc, MacroCallId, MacroCallLoc}, | 48 | ids::{HirFileId, DefId, DefLoc, MacroCallId, MacroCallLoc}, |
48 | macros::{MacroDef, MacroInput, MacroExpansion}, | 49 | macros::{MacroDef, MacroInput, MacroExpansion}, |
49 | module::{Module, ModuleId, Problem, nameres::{ItemMap, PerNs, Namespace}, ModuleScope, Resolution}, | 50 | module::{Module, ModuleId, Problem, nameres::{ItemMap, PerNs, Namespace}, ModuleScope, Resolution}, |