diff options
author | Aleksey Kladov <[email protected]> | 2019-09-05 20:36:04 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-09-06 12:21:11 +0100 |
commit | 9ae455ea52bf0bc60476fdb3d50d05f5873040c1 (patch) | |
tree | 5f5adc8ffd4c29d104e646057f636def67ac2549 /crates/ra_db | |
parent | 3bdb456d17660f3460bbf2c38315568b2f76aaa5 (diff) |
make source_root API more abstract
Diffstat (limited to 'crates/ra_db')
-rw-r--r-- | crates/ra_db/src/input.rs | 16 | ||||
-rw-r--r-- | crates/ra_db/src/lib.rs | 5 |
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. |
8 | use relative_path::RelativePathBuf; | 8 | use relative_path::{RelativePath, RelativePathBuf}; |
9 | use rustc_hash::FxHashMap; | 9 | use rustc_hash::FxHashMap; |
10 | 10 | ||
11 | use ra_syntax::SmolStr; | 11 | use 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 | ||
42 | impl SourceRoot { | 42 | impl 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 | }; |
15 | pub use ::salsa; | 15 | pub use salsa; |
16 | 16 | ||
17 | pub trait CheckCanceled { | 17 | pub 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 { | |||
93 | fn source_root_crates(db: &impl SourceDatabase, id: SourceRootId) -> Arc<Vec<CrateId>> { | 93 | fn 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 | ||