aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_db/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_db/src/lib.rs')
-rw-r--r--crates/ra_db/src/lib.rs27
1 files changed, 9 insertions, 18 deletions
diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs
index 3a0aa7d24..2664dc69a 100644
--- a/crates/ra_db/src/lib.rs
+++ b/crates/ra_db/src/lib.rs
@@ -20,7 +20,7 @@ pub use crate::{
20 loc2id::LocationIntener, 20 loc2id::LocationIntener,
21}; 21};
22 22
23pub trait BaseDatabase: salsa::Database + panic::RefUnwindSafe { 23pub trait CheckCanceled: salsa::Database + panic::RefUnwindSafe {
24 /// Aborts current query if there are pending changes. 24 /// Aborts current query if there are pending changes.
25 /// 25 ///
26 /// rust-analyzer needs to be able to answer semantic questions about the 26 /// rust-analyzer needs to be able to answer semantic questions about the
@@ -63,11 +63,15 @@ pub struct FileRange {
63 pub range: TextRange, 63 pub range: TextRange,
64} 64}
65 65
66#[salsa::query_group(FilesDatabaseStorage)] 66/// Database which stores all significant input facts: source code and project
67pub trait FilesDatabase: salsa::Database { 67/// model. Everything else in rust-analyzer is derived from these queries.
68#[salsa::query_group(SourceDatabaseStorage)]
69pub trait SourceDatabase: salsa::Database + CheckCanceled {
68 /// Text of the file. 70 /// Text of the file.
69 #[salsa::input] 71 #[salsa::input]
70 fn file_text(&self, file_id: FileId) -> Arc<String>; 72 fn file_text(&self, file_id: FileId) -> Arc<String>;
73 // Parses the file into the syntax tree.
74 fn source_file(&self, file_id: FileId) -> TreeArc<SourceFile>;
71 /// Path to a file, relative to the root of its source root. 75 /// Path to a file, relative to the root of its source root.
72 #[salsa::input] 76 #[salsa::input]
73 fn file_relative_path(&self, file_id: FileId) -> RelativePathBuf; 77 fn file_relative_path(&self, file_id: FileId) -> RelativePathBuf;
@@ -78,20 +82,12 @@ pub trait FilesDatabase: salsa::Database {
78 #[salsa::input] 82 #[salsa::input]
79 fn source_root(&self, id: SourceRootId) -> Arc<SourceRoot>; 83 fn source_root(&self, id: SourceRootId) -> Arc<SourceRoot>;
80 fn source_root_crates(&self, id: SourceRootId) -> Arc<Vec<CrateId>>; 84 fn source_root_crates(&self, id: SourceRootId) -> Arc<Vec<CrateId>>;
81 /// The set of "local" (that is, from the current workspace) roots.
82 /// Files in local roots are assumed to change frequently.
83 #[salsa::input]
84 fn local_roots(&self) -> Arc<Vec<SourceRootId>>;
85 /// The set of roots for crates.io libraries.
86 /// Files in libraries are assumed to never change.
87 #[salsa::input]
88 fn library_roots(&self) -> Arc<Vec<SourceRootId>>;
89 /// The crate graph. 85 /// The crate graph.
90 #[salsa::input] 86 #[salsa::input]
91 fn crate_graph(&self) -> Arc<CrateGraph>; 87 fn crate_graph(&self) -> Arc<CrateGraph>;
92} 88}
93 89
94fn source_root_crates(db: &impl FilesDatabase, id: SourceRootId) -> Arc<Vec<CrateId>> { 90fn source_root_crates(db: &impl SourceDatabase, id: SourceRootId) -> Arc<Vec<CrateId>> {
95 let root = db.source_root(id); 91 let root = db.source_root(id);
96 let graph = db.crate_graph(); 92 let graph = db.crate_graph();
97 let res = root 93 let res = root
@@ -102,12 +98,7 @@ fn source_root_crates(db: &impl FilesDatabase, id: SourceRootId) -> Arc<Vec<Crat
102 Arc::new(res) 98 Arc::new(res)
103} 99}
104 100
105#[salsa::query_group(SyntaxDatabaseStorage)] 101fn source_file(db: &impl SourceDatabase, file_id: FileId) -> TreeArc<SourceFile> {
106pub trait SyntaxDatabase: FilesDatabase + BaseDatabase {
107 fn source_file(&self, file_id: FileId) -> TreeArc<SourceFile>;
108}
109
110fn source_file(db: &impl SyntaxDatabase, file_id: FileId) -> TreeArc<SourceFile> {
111 let text = db.file_text(file_id); 102 let text = db.file_text(file_id);
112 SourceFile::parse(&*text) 103 SourceFile::parse(&*text)
113} 104}