diff options
author | Aleksey Kladov <[email protected]> | 2018-10-07 11:18:25 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-10-15 19:19:49 +0100 |
commit | d8aee31a600a8a8a56ddee0ee2ff1c5d5ba2320b (patch) | |
tree | 2610e72a444870434fcca6f1d69751800b957543 /crates/ra_analysis/src/roots.rs | |
parent | 93d77e9b22c38a3587f3b7d5c3c6d517b66f3314 (diff) |
start salsa migration
Diffstat (limited to 'crates/ra_analysis/src/roots.rs')
-rw-r--r-- | crates/ra_analysis/src/roots.rs | 68 |
1 files changed, 40 insertions, 28 deletions
diff --git a/crates/ra_analysis/src/roots.rs b/crates/ra_analysis/src/roots.rs index 208acc4c2..7a7d1169e 100644 --- a/crates/ra_analysis/src/roots.rs +++ b/crates/ra_analysis/src/roots.rs | |||
@@ -1,11 +1,13 @@ | |||
1 | use std::{ | 1 | use std::{ |
2 | collections::{HashMap, HashSet}, | ||
2 | sync::Arc, | 3 | sync::Arc, |
3 | panic, | 4 | panic, |
4 | }; | 5 | }; |
6 | use parking_lot::RwLock; | ||
5 | 7 | ||
6 | use once_cell::sync::OnceCell; | 8 | use once_cell::sync::OnceCell; |
7 | use rayon::prelude::*; | 9 | use rayon::prelude::*; |
8 | use rustc_hash::FxHashMap; | 10 | use salsa::Database; |
9 | use ra_editor::LineIndex; | 11 | use ra_editor::LineIndex; |
10 | use ra_syntax::File; | 12 | use ra_syntax::File; |
11 | 13 | ||
@@ -14,7 +16,7 @@ use crate::{ | |||
14 | imp::FileResolverImp, | 16 | imp::FileResolverImp, |
15 | symbol_index::SymbolIndex, | 17 | symbol_index::SymbolIndex, |
16 | descriptors::{ModuleDescriptor, ModuleTreeDescriptor}, | 18 | descriptors::{ModuleDescriptor, ModuleTreeDescriptor}, |
17 | db::Db, | 19 | db::{self, FilesDatabase, SyntaxDatabase} |
18 | }; | 20 | }; |
19 | 21 | ||
20 | pub(crate) trait SourceRoot { | 22 | pub(crate) trait SourceRoot { |
@@ -25,9 +27,9 @@ pub(crate) trait SourceRoot { | |||
25 | fn symbols(&self, acc: &mut Vec<Arc<SymbolIndex>>); | 27 | fn symbols(&self, acc: &mut Vec<Arc<SymbolIndex>>); |
26 | } | 28 | } |
27 | 29 | ||
28 | #[derive(Default, Debug)] | 30 | #[derive(Default, Debug, Clone)] |
29 | pub(crate) struct WritableSourceRoot { | 31 | pub(crate) struct WritableSourceRoot { |
30 | db: Db, | 32 | db: Arc<RwLock<db::RootDatabase>>, |
31 | } | 33 | } |
32 | 34 | ||
33 | impl WritableSourceRoot { | 35 | impl WritableSourceRoot { |
@@ -36,51 +38,61 @@ impl WritableSourceRoot { | |||
36 | changes: &mut dyn Iterator<Item=(FileId, Option<String>)>, | 38 | changes: &mut dyn Iterator<Item=(FileId, Option<String>)>, |
37 | file_resolver: Option<FileResolverImp>, | 39 | file_resolver: Option<FileResolverImp>, |
38 | ) -> WritableSourceRoot { | 40 | ) -> WritableSourceRoot { |
39 | let resolver_changed = file_resolver.is_some(); | 41 | let db = self.db.write(); |
40 | let mut changed_files = Vec::new(); | 42 | let mut changed = HashSet::new(); |
41 | let mut new_state = self.db.state().clone(); | 43 | let mut removed = HashSet::new(); |
42 | |||
43 | for (file_id, text) in changes { | 44 | for (file_id, text) in changes { |
44 | changed_files.push(file_id); | ||
45 | match text { | 45 | match text { |
46 | Some(text) => { | ||
47 | new_state.file_map.insert(file_id, Arc::new(text)); | ||
48 | }, | ||
49 | None => { | 46 | None => { |
50 | new_state.file_map.remove(&file_id); | 47 | removed.insert(file_id); |
48 | } | ||
49 | Some(text) => { | ||
50 | db.query(db::FileTextQuery) | ||
51 | .set(file_id, Arc::new(text)); | ||
52 | changed.insert(file_id); | ||
51 | } | 53 | } |
52 | } | 54 | } |
53 | } | 55 | } |
54 | if let Some(file_resolver) = file_resolver { | 56 | if let Some(resolver) = file_resolver { |
55 | new_state.file_resolver = file_resolver | 57 | let mut files: HashSet<FileId> = db.file_set(()) |
56 | } | 58 | .files |
57 | WritableSourceRoot { | 59 | .clone(); |
58 | db: self.db.with_changes(new_state, &changed_files, resolver_changed) | 60 | for file_id in removed { |
61 | files.remove(&file_id); | ||
62 | } | ||
63 | files.extend(changed); | ||
64 | db.query(db::FileSetQuery) | ||
65 | .set((), Arc::new(db::FileSet { files, resolver })) | ||
59 | } | 66 | } |
67 | // TODO: reconcile sasla's API with our needs | ||
68 | // https://github.com/salsa-rs/salsa/issues/12 | ||
69 | self.clone() | ||
60 | } | 70 | } |
61 | } | 71 | } |
62 | 72 | ||
63 | impl SourceRoot for WritableSourceRoot { | 73 | impl SourceRoot for WritableSourceRoot { |
64 | fn module_tree(&self) -> Arc<ModuleTreeDescriptor> { | 74 | fn module_tree(&self) -> Arc<ModuleTreeDescriptor> { |
65 | self.db.make_query(crate::module_map::module_tree) | 75 | unimplemented!() |
76 | //self.db.make_query(::module_map::module_tree) | ||
66 | } | 77 | } |
67 | 78 | ||
68 | fn contains(&self, file_id: FileId) -> bool { | 79 | fn contains(&self, file_id: FileId) -> bool { |
69 | self.db.state().file_map.contains_key(&file_id) | 80 | self.db.read().file_set(()).files.contains(&file_id) |
70 | } | 81 | } |
71 | fn lines(&self, file_id: FileId) -> Arc<LineIndex> { | 82 | fn lines(&self, file_id: FileId) -> Arc<LineIndex> { |
72 | self.db.make_query(|ctx| crate::queries::file_lines(ctx, file_id)) | 83 | self.db.read().file_lines(file_id) |
73 | } | 84 | } |
74 | fn syntax(&self, file_id: FileId) -> File { | 85 | fn syntax(&self, file_id: FileId) -> File { |
75 | self.db.make_query(|ctx| crate::queries::file_syntax(ctx, file_id)) | 86 | self.db.read().file_syntax(file_id) |
76 | } | 87 | } |
77 | fn symbols<'a>(&'a self, acc: &mut Vec<Arc<SymbolIndex>>) { | 88 | fn symbols<'a>(&'a self, acc: &mut Vec<Arc<SymbolIndex>>) { |
78 | self.db.make_query(|ctx| { | 89 | let db = self.db.read(); |
79 | let file_set = crate::queries::file_set(ctx); | 90 | let symbols = db.file_set(()); |
80 | let syms = file_set.0.iter() | 91 | let symbols = symbols |
81 | .map(|file_id| crate::queries::file_symbols(ctx, *file_id)); | 92 | .files |
82 | acc.extend(syms); | 93 | .iter() |
83 | }); | 94 | .map(|&file_id| db.file_symbols(file_id)); |
95 | acc.extend(symbols); | ||
84 | } | 96 | } |
85 | } | 97 | } |
86 | 98 | ||