diff options
author | Aleksey Kladov <[email protected]> | 2018-10-15 20:29:24 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-10-15 20:29:24 +0100 |
commit | bbcd998433075aba66ef0677bcdd821ca5fc926e (patch) | |
tree | 58130242a9a726bb552d01f5c72d1c4d13ead701 /crates/ra_analysis/src/roots.rs | |
parent | 76c51fae77d5dc2d7791132ecc78e444118e48de (diff) |
make analysis sync
Diffstat (limited to 'crates/ra_analysis/src/roots.rs')
-rw-r--r-- | crates/ra_analysis/src/roots.rs | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/crates/ra_analysis/src/roots.rs b/crates/ra_analysis/src/roots.rs index 42833af36..76bcecd38 100644 --- a/crates/ra_analysis/src/roots.rs +++ b/crates/ra_analysis/src/roots.rs | |||
@@ -2,7 +2,6 @@ use std::{ | |||
2 | sync::Arc, | 2 | sync::Arc, |
3 | panic, | 3 | panic, |
4 | }; | 4 | }; |
5 | use parking_lot::RwLock; | ||
6 | 5 | ||
7 | use once_cell::sync::OnceCell; | 6 | use once_cell::sync::OnceCell; |
8 | use rayon::prelude::*; | 7 | use rayon::prelude::*; |
@@ -30,7 +29,7 @@ pub(crate) trait SourceRoot { | |||
30 | 29 | ||
31 | #[derive(Default, Debug, Clone)] | 30 | #[derive(Default, Debug, Clone)] |
32 | pub(crate) struct WritableSourceRoot { | 31 | pub(crate) struct WritableSourceRoot { |
33 | db: Arc<RwLock<db::RootDatabase>>, | 32 | db: db::RootDatabase, |
34 | } | 33 | } |
35 | 34 | ||
36 | impl WritableSourceRoot { | 35 | impl WritableSourceRoot { |
@@ -39,7 +38,6 @@ impl WritableSourceRoot { | |||
39 | changes: &mut dyn Iterator<Item=(FileId, Option<String>)>, | 38 | changes: &mut dyn Iterator<Item=(FileId, Option<String>)>, |
40 | file_resolver: Option<FileResolverImp>, | 39 | file_resolver: Option<FileResolverImp>, |
41 | ) { | 40 | ) { |
42 | let db = self.db.write(); | ||
43 | let mut changed = FxHashSet::default(); | 41 | let mut changed = FxHashSet::default(); |
44 | let mut removed = FxHashSet::default(); | 42 | let mut removed = FxHashSet::default(); |
45 | for (file_id, text) in changes { | 43 | for (file_id, text) in changes { |
@@ -48,13 +46,13 @@ impl WritableSourceRoot { | |||
48 | removed.insert(file_id); | 46 | removed.insert(file_id); |
49 | } | 47 | } |
50 | Some(text) => { | 48 | Some(text) => { |
51 | db.query(db::FileTextQuery) | 49 | self.db.query(db::FileTextQuery) |
52 | .set(file_id, Arc::new(text)); | 50 | .set(file_id, Arc::new(text)); |
53 | changed.insert(file_id); | 51 | changed.insert(file_id); |
54 | } | 52 | } |
55 | } | 53 | } |
56 | } | 54 | } |
57 | let file_set = db.file_set(()); | 55 | let file_set = self.db.file_set(()); |
58 | let mut files: FxHashSet<FileId> = file_set | 56 | let mut files: FxHashSet<FileId> = file_set |
59 | .files | 57 | .files |
60 | .clone(); | 58 | .clone(); |
@@ -63,28 +61,28 @@ impl WritableSourceRoot { | |||
63 | } | 61 | } |
64 | files.extend(changed); | 62 | files.extend(changed); |
65 | let resolver = file_resolver.unwrap_or_else(|| file_set.resolver.clone()); | 63 | let resolver = file_resolver.unwrap_or_else(|| file_set.resolver.clone()); |
66 | db.query(db::FileSetQuery) | 64 | self.db.query(db::FileSetQuery) |
67 | .set((), Arc::new(db::FileSet { files, resolver })); | 65 | .set((), Arc::new(db::FileSet { files, resolver })); |
68 | } | 66 | } |
69 | } | 67 | } |
70 | 68 | ||
71 | impl SourceRoot for WritableSourceRoot { | 69 | impl SourceRoot for WritableSourceRoot { |
72 | fn module_tree(&self) -> Arc<ModuleTreeDescriptor> { | 70 | fn module_tree(&self) -> Arc<ModuleTreeDescriptor> { |
73 | self.db.read().module_tree(()) | 71 | self.db.module_tree(()) |
74 | } | 72 | } |
75 | fn contains(&self, file_id: FileId) -> bool { | 73 | fn contains(&self, file_id: FileId) -> bool { |
76 | let db = self.db.read(); | 74 | self.db.file_set(()) |
77 | let files = &db.file_set(()).files; | 75 | .files |
78 | files.contains(&file_id) | 76 | .contains(&file_id) |
79 | } | 77 | } |
80 | fn lines(&self, file_id: FileId) -> Arc<LineIndex> { | 78 | fn lines(&self, file_id: FileId) -> Arc<LineIndex> { |
81 | self.db.read().file_lines(file_id) | 79 | self.db.file_lines(file_id) |
82 | } | 80 | } |
83 | fn syntax(&self, file_id: FileId) -> File { | 81 | fn syntax(&self, file_id: FileId) -> File { |
84 | self.db.read().file_syntax(file_id) | 82 | self.db.file_syntax(file_id) |
85 | } | 83 | } |
86 | fn symbols<'a>(&'a self, acc: &mut Vec<Arc<SymbolIndex>>) { | 84 | fn symbols<'a>(&'a self, acc: &mut Vec<Arc<SymbolIndex>>) { |
87 | let db = self.db.read(); | 85 | let db = &self.db; |
88 | let symbols = db.file_set(()); | 86 | let symbols = db.file_set(()); |
89 | let symbols = symbols | 87 | let symbols = symbols |
90 | .files | 88 | .files |