diff options
Diffstat (limited to 'crates/ra_analysis/src/input.rs')
-rw-r--r-- | crates/ra_analysis/src/input.rs | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/crates/ra_analysis/src/input.rs b/crates/ra_analysis/src/input.rs new file mode 100644 index 000000000..e64fad40c --- /dev/null +++ b/crates/ra_analysis/src/input.rs | |||
@@ -0,0 +1,79 @@ | |||
1 | use std::{ | ||
2 | sync::Arc, | ||
3 | fmt, | ||
4 | }; | ||
5 | |||
6 | use salsa; | ||
7 | use rustc_hash::FxHashSet; | ||
8 | use relative_path::RelativePath; | ||
9 | use rustc_hash::FxHashMap; | ||
10 | |||
11 | use crate::{symbol_index::SymbolIndex, FileResolverImp}; | ||
12 | |||
13 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
14 | pub struct FileId(pub u32); | ||
15 | |||
16 | #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
17 | pub struct CrateId(pub u32); | ||
18 | |||
19 | #[derive(Debug, Clone, Default, PartialEq, Eq)] | ||
20 | pub struct CrateGraph { | ||
21 | pub(crate) crate_roots: FxHashMap<CrateId, FileId>, | ||
22 | } | ||
23 | |||
24 | impl CrateGraph { | ||
25 | pub fn new() -> CrateGraph { | ||
26 | CrateGraph::default() | ||
27 | } | ||
28 | pub fn add_crate_root(&mut self, file_id: FileId) -> CrateId{ | ||
29 | let crate_id = CrateId(self.crate_roots.len() as u32); | ||
30 | let prev = self.crate_roots.insert(crate_id, file_id); | ||
31 | assert!(prev.is_none()); | ||
32 | crate_id | ||
33 | } | ||
34 | } | ||
35 | |||
36 | pub trait FileResolver: fmt::Debug + Send + Sync + 'static { | ||
37 | fn file_stem(&self, file_id: FileId) -> String; | ||
38 | fn resolve(&self, file_id: FileId, path: &RelativePath) -> Option<FileId>; | ||
39 | } | ||
40 | |||
41 | salsa::query_group! { | ||
42 | pub(crate) trait FilesDatabase: salsa::Database { | ||
43 | fn file_text(file_id: FileId) -> Arc<String> { | ||
44 | type FileTextQuery; | ||
45 | storage input; | ||
46 | } | ||
47 | fn file_source_root(file_id: FileId) -> SourceRootId { | ||
48 | type FileSourceRootQuery; | ||
49 | storage input; | ||
50 | } | ||
51 | fn source_root(id: SourceRootId) -> Arc<SourceRoot> { | ||
52 | type SourceRootQuery; | ||
53 | storage input; | ||
54 | } | ||
55 | fn libraries() -> Arc<Vec<SourceRootId>> { | ||
56 | type LibrarieseQuery; | ||
57 | storage input; | ||
58 | } | ||
59 | fn library_symbols(id: SourceRootId) -> Arc<SymbolIndex> { | ||
60 | type LibrarySymbolsQuery; | ||
61 | storage input; | ||
62 | } | ||
63 | fn crate_graph() -> Arc<CrateGraph> { | ||
64 | type CrateGraphQuery; | ||
65 | storage input; | ||
66 | } | ||
67 | } | ||
68 | } | ||
69 | |||
70 | #[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] | ||
71 | pub(crate) struct SourceRootId(pub(crate) u32); | ||
72 | |||
73 | #[derive(Clone, Default, Debug, PartialEq, Eq)] | ||
74 | pub(crate) struct SourceRoot { | ||
75 | pub(crate) file_resolver: FileResolverImp, | ||
76 | pub(crate) files: FxHashSet<FileId>, | ||
77 | } | ||
78 | |||
79 | pub(crate) const WORKSPACE: SourceRootId = SourceRootId(0); | ||