diff options
Diffstat (limited to 'crates/ra_db/src/input.rs')
-rw-r--r-- | crates/ra_db/src/input.rs | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index 7d9faa43c..ac144b991 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | use std::sync::Arc; | 1 | use std::sync::Arc; |
2 | 2 | ||
3 | use rustc_hash::FxHashMap; | 3 | use rustc_hash::{FxHashSet, FxHashMap}; |
4 | use rustc_hash::FxHashSet; | 4 | use ra_syntax::SmolStr; |
5 | use salsa; | 5 | use salsa; |
6 | 6 | ||
7 | use crate::file_resolver::FileResolverImp; | 7 | use crate::file_resolver::FileResolverImp; |
@@ -20,25 +20,32 @@ pub struct CrateGraph { | |||
20 | #[derive(Debug, Clone, PartialEq, Eq)] | 20 | #[derive(Debug, Clone, PartialEq, Eq)] |
21 | struct CrateData { | 21 | struct CrateData { |
22 | file_id: FileId, | 22 | file_id: FileId, |
23 | deps: Vec<Dependency>, | 23 | dependencies: Vec<Dependency>, |
24 | } | 24 | } |
25 | 25 | ||
26 | impl CrateData { | 26 | impl CrateData { |
27 | fn new(file_id: FileId) -> CrateData { | 27 | fn new(file_id: FileId) -> CrateData { |
28 | CrateData { | 28 | CrateData { |
29 | file_id, | 29 | file_id, |
30 | deps: Vec::new(), | 30 | dependencies: Vec::new(), |
31 | } | 31 | } |
32 | } | 32 | } |
33 | 33 | ||
34 | fn add_dep(&mut self, dep: CrateId) { | 34 | fn add_dep(&mut self, name: SmolStr, crate_id: CrateId) { |
35 | self.deps.push(Dependency { crate_: dep }) | 35 | self.dependencies.push(Dependency { name, crate_id }) |
36 | } | 36 | } |
37 | } | 37 | } |
38 | 38 | ||
39 | #[derive(Debug, Clone, PartialEq, Eq)] | 39 | #[derive(Debug, Clone, PartialEq, Eq)] |
40 | pub struct Dependency { | 40 | pub struct Dependency { |
41 | crate_: CrateId, | 41 | pub crate_id: CrateId, |
42 | pub name: SmolStr, | ||
43 | } | ||
44 | |||
45 | impl Dependency { | ||
46 | pub fn crate_id(&self) -> CrateId { | ||
47 | self.crate_id | ||
48 | } | ||
42 | } | 49 | } |
43 | 50 | ||
44 | impl CrateGraph { | 51 | impl CrateGraph { |
@@ -48,8 +55,11 @@ impl CrateGraph { | |||
48 | assert!(prev.is_none()); | 55 | assert!(prev.is_none()); |
49 | crate_id | 56 | crate_id |
50 | } | 57 | } |
51 | pub fn add_dep(&mut self, from: CrateId, to: CrateId) { | 58 | //FIXME: check that we don't have cycles here. |
52 | self.arena.get_mut(&from).unwrap().add_dep(to) | 59 | // Just a simple depth first search from `to` should work, |
60 | // the graph is small. | ||
61 | pub fn add_dep(&mut self, from: CrateId, name: SmolStr, to: CrateId) { | ||
62 | self.arena.get_mut(&from).unwrap().add_dep(name, to) | ||
53 | } | 63 | } |
54 | pub fn crate_root(&self, crate_id: CrateId) -> FileId { | 64 | pub fn crate_root(&self, crate_id: CrateId) -> FileId { |
55 | self.arena[&crate_id].file_id | 65 | self.arena[&crate_id].file_id |
@@ -61,6 +71,12 @@ impl CrateGraph { | |||
61 | .find(|(_crate_id, data)| data.file_id == file_id)?; | 71 | .find(|(_crate_id, data)| data.file_id == file_id)?; |
62 | Some(crate_id) | 72 | Some(crate_id) |
63 | } | 73 | } |
74 | pub fn dependencies<'a>( | ||
75 | &'a self, | ||
76 | crate_id: CrateId, | ||
77 | ) -> impl Iterator<Item = &'a Dependency> + 'a { | ||
78 | self.arena[&crate_id].dependencies.iter() | ||
79 | } | ||
64 | } | 80 | } |
65 | 81 | ||
66 | salsa::query_group! { | 82 | salsa::query_group! { |