aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/input.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/src/input.rs')
-rw-r--r--crates/ra_analysis/src/input.rs79
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 @@
1use std::{
2 sync::Arc,
3 fmt,
4};
5
6use salsa;
7use rustc_hash::FxHashSet;
8use relative_path::RelativePath;
9use rustc_hash::FxHashMap;
10
11use crate::{symbol_index::SymbolIndex, FileResolverImp};
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
14pub struct FileId(pub u32);
15
16#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
17pub struct CrateId(pub u32);
18
19#[derive(Debug, Clone, Default, PartialEq, Eq)]
20pub struct CrateGraph {
21 pub(crate) crate_roots: FxHashMap<CrateId, FileId>,
22}
23
24impl 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
36pub 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
41salsa::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)]
71pub(crate) struct SourceRootId(pub(crate) u32);
72
73#[derive(Clone, Default, Debug, PartialEq, Eq)]
74pub(crate) struct SourceRoot {
75 pub(crate) file_resolver: FileResolverImp,
76 pub(crate) files: FxHashSet<FileId>,
77}
78
79pub(crate) const WORKSPACE: SourceRootId = SourceRootId(0);