aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_db
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_db')
-rw-r--r--crates/ra_db/src/input.rs16
-rw-r--r--crates/ra_db/src/lib.rs5
2 files changed, 16 insertions, 5 deletions
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs
index ad8e10c52..d1ee3c036 100644
--- a/crates/ra_db/src/input.rs
+++ b/crates/ra_db/src/input.rs
@@ -5,7 +5,7 @@
5/// Note that neither this module, nor any other part of the analyzer's core do 5/// Note that neither this module, nor any other part of the analyzer's core do
6/// actual IO. See `vfs` and `project_model` in the `ra_lsp_server` crate for how 6/// actual IO. See `vfs` and `project_model` in the `ra_lsp_server` crate for how
7/// actual IO is done and lowered to input. 7/// actual IO is done and lowered to input.
8use relative_path::RelativePathBuf; 8use relative_path::{RelativePath, RelativePathBuf};
9use rustc_hash::FxHashMap; 9use rustc_hash::FxHashMap;
10 10
11use ra_syntax::SmolStr; 11use ra_syntax::SmolStr;
@@ -36,7 +36,7 @@ pub struct SourceRoot {
36 /// Libraries are considered mostly immutable, this assumption is used to 36 /// Libraries are considered mostly immutable, this assumption is used to
37 /// optimize salsa's query structure 37 /// optimize salsa's query structure
38 pub is_library: bool, 38 pub is_library: bool,
39 pub files: FxHashMap<RelativePathBuf, FileId>, 39 files: FxHashMap<RelativePathBuf, FileId>,
40} 40}
41 41
42impl SourceRoot { 42impl SourceRoot {
@@ -46,6 +46,18 @@ impl SourceRoot {
46 pub fn new_library() -> SourceRoot { 46 pub fn new_library() -> SourceRoot {
47 SourceRoot { is_library: true, ..SourceRoot::new() } 47 SourceRoot { is_library: true, ..SourceRoot::new() }
48 } 48 }
49 pub fn file_by_relative_path(&self, path: &RelativePath) -> Option<FileId> {
50 self.files.get(path).copied()
51 }
52 pub fn insert_file(&mut self, path: RelativePathBuf, file_id: FileId) {
53 self.files.insert(path, file_id);
54 }
55 pub fn remove_file(&mut self, path: &RelativePath) {
56 self.files.remove(path);
57 }
58 pub fn walk(&self) -> impl Iterator<Item = FileId> + '_ {
59 self.files.values().copied()
60 }
49} 61}
50 62
51/// `CrateGraph` is a bit of information which turns a set of text files into a 63/// `CrateGraph` is a bit of information which turns a set of text files into a
diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs
index b82d1bda0..c54791b7a 100644
--- a/crates/ra_db/src/lib.rs
+++ b/crates/ra_db/src/lib.rs
@@ -12,7 +12,7 @@ pub use crate::{
12 cancellation::Canceled, 12 cancellation::Canceled,
13 input::{CrateGraph, CrateId, Dependency, Edition, FileId, SourceRoot, SourceRootId}, 13 input::{CrateGraph, CrateId, Dependency, Edition, FileId, SourceRoot, SourceRootId},
14}; 14};
15pub use ::salsa; 15pub use salsa;
16 16
17pub trait CheckCanceled { 17pub trait CheckCanceled {
18 /// Aborts current query if there are pending changes. 18 /// Aborts current query if there are pending changes.
@@ -93,8 +93,7 @@ pub trait SourceDatabase: CheckCanceled + std::fmt::Debug {
93fn source_root_crates(db: &impl SourceDatabase, id: SourceRootId) -> Arc<Vec<CrateId>> { 93fn source_root_crates(db: &impl SourceDatabase, id: SourceRootId) -> Arc<Vec<CrateId>> {
94 let root = db.source_root(id); 94 let root = db.source_root(id);
95 let graph = db.crate_graph(); 95 let graph = db.crate_graph();
96 let res = 96 let res = root.walk().filter_map(|it| graph.crate_id_for_crate_root(it)).collect::<Vec<_>>();
97 root.files.values().filter_map(|&it| graph.crate_id_for_crate_root(it)).collect::<Vec<_>>();
98 Arc::new(res) 97 Arc::new(res)
99} 98}
100 99