aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src')
-rw-r--r--crates/ra_analysis/src/lib.rs18
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;
15use std::{ 15use std::{
16 fmt, 16 fmt,
17 sync::Arc, 17 sync::Arc,
18 collections::BTreeMap,
19}; 18};
20 19
20use rustc_hash::FxHashMap;
21use ra_syntax::{AtomEdit, File, TextRange, TextUnit}; 21use ra_syntax::{AtomEdit, File, TextRange, TextUnit};
22use relative_path::{RelativePath, RelativePathBuf}; 22use relative_path::{RelativePath, RelativePathBuf};
23use rayon::prelude::*; 23use 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)]
56pub struct CrateId(pub u32); 56pub struct CrateId(pub u32);
57 57
58#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)] 58#[derive(Debug, Clone, Default, PartialEq, Eq)]
59pub struct CrateGraph { 59pub struct CrateGraph {
60 pub crate_roots: BTreeMap<CrateId, FileId>, 60 crate_roots: FxHashMap<CrateId, FileId>,
61}
62
63impl 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
63pub trait FileResolver: fmt::Debug + Send + Sync + 'static { 75pub trait FileResolver: fmt::Debug + Send + Sync + 'static {