aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/code_model_api.rs26
-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.rs7
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 @@
1use ra_db::{CrateId, Cancelable};
2
3use 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)]
9pub struct Crate {
10 pub(crate) crate_id: CrateId,
11}
12
13#[derive(Debug)]
14pub struct CrateDependency {
15 pub krate: Crate,
16 pub name: Name,
17}
18
19impl 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 @@
1pub use ra_db::{CrateId, Cancelable}; 1use ra_db::{CrateId, Cancelable};
2 2
3use crate::{HirDatabase, Module, Name, AsName, HirFileId}; 3use 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)]
9pub struct Crate {
10 crate_id: CrateId,
11}
12
13#[derive(Debug)]
14pub struct CrateDependency {
15 pub krate: Crate,
16 pub name: Name,
17}
18 4
19impl Crate { 5impl 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;
24mod ids; 24mod ids;
25mod macros; 25mod macros;
26mod name; 26mod name;
27// can't use `crate` or `r#crate` here :(
28mod krate;
29mod module; 27mod module;
30mod function; 28mod function;
31mod adt; 29mod adt;
@@ -34,16 +32,19 @@ mod ty;
34mod impl_block; 32mod impl_block;
35mod expr; 33mod expr;
36 34
35pub mod code_model_api;
36mod code_model_impl;
37
37use crate::{ 38use 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
43pub use self::{ 45pub 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},