aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_analysis/src/roots.rs116
1 files changed, 0 insertions, 116 deletions
diff --git a/crates/ra_analysis/src/roots.rs b/crates/ra_analysis/src/roots.rs
deleted file mode 100644
index 1e9e613ac..000000000
--- a/crates/ra_analysis/src/roots.rs
+++ /dev/null
@@ -1,116 +0,0 @@
1use std::{sync::Arc};
2
3use rustc_hash::FxHashSet;
4use rayon::prelude::*;
5use salsa::Database;
6
7use crate::{
8 Cancelable,
9 db::{self, FilesDatabase, SyntaxDatabase},
10 imp::FileResolverImp,
11 symbol_index::SymbolIndex,
12 FileId,
13};
14
15pub(crate) trait SourceRoot {
16 fn contains(&self, file_id: FileId) -> bool;
17 fn db(&self) -> &db::RootDatabase;
18 fn symbols(&self, acc: &mut Vec<Arc<SymbolIndex>>) -> Cancelable<()>;
19}
20
21#[derive(Default, Debug, Clone)]
22pub(crate) struct WritableSourceRoot {
23 db: db::RootDatabase,
24}
25
26impl WritableSourceRoot {
27 pub fn apply_changes(
28 &mut self,
29 changes: &mut dyn Iterator<Item = (FileId, Option<String>)>,
30 file_resolver: Option<FileResolverImp>,
31 ) {
32 let mut changed = FxHashSet::default();
33 let mut removed = FxHashSet::default();
34 for (file_id, text) in changes {
35 match text {
36 None => {
37 removed.insert(file_id);
38 }
39 Some(text) => {
40 self.db
41 .query(db::FileTextQuery)
42 .set(file_id, Arc::new(text));
43 changed.insert(file_id);
44 }
45 }
46 }
47 let file_set = self.db.file_set();
48 let mut files: FxHashSet<FileId> = file_set.files.clone();
49 for file_id in removed {
50 files.remove(&file_id);
51 }
52 files.extend(changed);
53 let resolver = file_resolver.unwrap_or_else(|| file_set.resolver.clone());
54 self.db
55 .query(db::FileSetQuery)
56 .set((), Arc::new(db::FileSet { files, resolver }));
57 }
58}
59
60impl SourceRoot for WritableSourceRoot {
61 fn contains(&self, file_id: FileId) -> bool {
62 self.db.file_set().files.contains(&file_id)
63 }
64 fn db(&self) -> &db::RootDatabase {
65 &self.db
66 }
67 fn symbols<'a>(&'a self, acc: &mut Vec<Arc<SymbolIndex>>) -> Cancelable<()> {
68 for &file_id in self.db.file_set().files.iter() {
69 let symbols = self.db.file_symbols(file_id)?;
70 acc.push(symbols)
71 }
72 Ok(())
73 }
74}
75
76#[derive(Debug, Clone)]
77pub(crate) struct ReadonlySourceRoot {
78 db: db::RootDatabase,
79 symbol_index: Arc<SymbolIndex>,
80}
81
82impl ReadonlySourceRoot {
83 pub(crate) fn new(
84 files: Vec<(FileId, String)>,
85 resolver: FileResolverImp,
86 ) -> ReadonlySourceRoot {
87 let db = db::RootDatabase::default();
88 let mut file_ids = FxHashSet::default();
89 for (file_id, text) in files {
90 file_ids.insert(file_id);
91 db.query(db::FileTextQuery).set(file_id, Arc::new(text));
92 }
93
94 db.query(db::FileSetQuery)
95 .set((), Arc::new(db::FileSet { files: file_ids, resolver }));
96 let file_set = db.file_set();
97 let symbol_index =
98 SymbolIndex::for_files(file_set.files.par_iter()
99 .map_with(db.clone(), |db, &file_id| (file_id, db.file_syntax(file_id))));
100
101 ReadonlySourceRoot { db, symbol_index: Arc::new(symbol_index) }
102 }
103}
104
105impl SourceRoot for ReadonlySourceRoot {
106 fn contains(&self, file_id: FileId) -> bool {
107 self.db.file_set().files.contains(&file_id)
108 }
109 fn db(&self) -> &db::RootDatabase {
110 &self.db
111 }
112 fn symbols(&self, acc: &mut Vec<Arc<SymbolIndex>>) -> Cancelable<()> {
113 acc.push(Arc::clone(&self.symbol_index));
114 Ok(())
115 }
116}