diff options
author | Aleksey Kladov <[email protected]> | 2018-10-25 15:40:24 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-10-25 15:40:24 +0100 |
commit | e0eb33605a917d2e7289debe0c915e75286b834f (patch) | |
tree | ea35a9250c22fdc201daad5ae971a214f1c23e70 /crates/ra_analysis/src | |
parent | 75d9cbd7c22b09a0bc2731731228c95ae60573c3 (diff) |
Encapsulate CrateGraph a bit
Diffstat (limited to 'crates/ra_analysis/src')
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 703938cf9..af7894cd0 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -15,9 +15,9 @@ mod completion; | |||
15 | use std::{ | 15 | use std::{ |
16 | fmt, | 16 | fmt, |
17 | sync::Arc, | 17 | sync::Arc, |
18 | collections::BTreeMap, | ||
19 | }; | 18 | }; |
20 | 19 | ||
20 | use rustc_hash::FxHashMap; | ||
21 | use ra_syntax::{AtomEdit, File, TextRange, TextUnit}; | 21 | use ra_syntax::{AtomEdit, File, TextRange, TextUnit}; |
22 | use relative_path::{RelativePath, RelativePathBuf}; | 22 | use relative_path::{RelativePath, RelativePathBuf}; |
23 | use rayon::prelude::*; | 23 | use rayon::prelude::*; |
@@ -55,9 +55,21 @@ pub struct FileId(pub u32); | |||
55 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | 55 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
56 | pub struct CrateId(pub u32); | 56 | pub struct CrateId(pub u32); |
57 | 57 | ||
58 | #[derive(Debug, Clone, Default, PartialEq, Eq, Hash)] | 58 | #[derive(Debug, Clone, Default, PartialEq, Eq)] |
59 | pub struct CrateGraph { | 59 | pub struct CrateGraph { |
60 | pub crate_roots: BTreeMap<CrateId, FileId>, | 60 | crate_roots: FxHashMap<CrateId, FileId>, |
61 | } | ||
62 | |||
63 | impl CrateGraph { | ||
64 | pub fn new() -> CrateGraph { | ||
65 | CrateGraph::default() | ||
66 | } | ||
67 | pub fn add_crate_root(&mut self, file_id: FileId) -> CrateId{ | ||
68 | let crate_id = CrateId(self.crate_roots.len() as u32); | ||
69 | let prev = self.crate_roots.insert(crate_id, file_id); | ||
70 | assert!(prev.is_none()); | ||
71 | crate_id | ||
72 | } | ||
61 | } | 73 | } |
62 | 74 | ||
63 | pub trait FileResolver: fmt::Debug + Send + Sync + 'static { | 75 | pub trait FileResolver: fmt::Debug + Send + Sync + 'static { |