diff options
Diffstat (limited to 'crates/libanalysis/src/imp.rs')
-rw-r--r-- | crates/libanalysis/src/imp.rs | 46 |
1 files changed, 20 insertions, 26 deletions
diff --git a/crates/libanalysis/src/imp.rs b/crates/libanalysis/src/imp.rs index 06bbc7cf2..004942e72 100644 --- a/crates/libanalysis/src/imp.rs +++ b/crates/libanalysis/src/imp.rs | |||
@@ -9,14 +9,14 @@ use std::{ | |||
9 | panic, | 9 | panic, |
10 | }; | 10 | }; |
11 | 11 | ||
12 | use rayon::prelude::*; | ||
13 | use once_cell::sync::OnceCell; | ||
14 | use libeditor::{self, FileSymbol, LineIndex, find_node_at_offset, LocalEdit}; | ||
12 | use libsyntax2::{ | 15 | use libsyntax2::{ |
13 | TextUnit, TextRange, SmolStr, File, AstNode, | 16 | TextUnit, TextRange, SmolStr, File, AstNode, |
14 | SyntaxKind::*, | 17 | SyntaxKind::*, |
15 | ast::{self, NameOwner}, | 18 | ast::{self, NameOwner}, |
16 | }; | 19 | }; |
17 | use rayon::prelude::*; | ||
18 | use once_cell::sync::OnceCell; | ||
19 | use libeditor::{self, FileSymbol, LineIndex, find_node_at_offset, LocalEdit}; | ||
20 | 20 | ||
21 | use { | 21 | use { |
22 | FileId, FileResolver, Query, Diagnostic, SourceChange, SourceFileEdit, Position, FileSystemEdit, | 22 | FileId, FileResolver, Query, Diagnostic, SourceChange, SourceFileEdit, Position, FileSystemEdit, |
@@ -44,11 +44,11 @@ impl AnalysisHostImpl { | |||
44 | AnalysisImpl { | 44 | AnalysisImpl { |
45 | needs_reindex: AtomicBool::new(false), | 45 | needs_reindex: AtomicBool::new(false), |
46 | file_resolver: Arc::new(file_resolver), | 46 | file_resolver: Arc::new(file_resolver), |
47 | data: self.data.clone() | 47 | data: self.data.clone(), |
48 | } | 48 | } |
49 | } | 49 | } |
50 | 50 | ||
51 | pub fn change_files(&mut self, changes: impl Iterator<Item=(FileId, Option<String>)>) { | 51 | pub fn change_files(&mut self, changes: &mut dyn Iterator<Item=(FileId, Option<String>)>) { |
52 | let data = self.data_mut(); | 52 | let data = self.data_mut(); |
53 | for (file_id, text) in changes { | 53 | for (file_id, text) in changes { |
54 | let change_kind = if data.file_map.remove(&file_id).is_some() { | 54 | let change_kind = if data.file_map.remove(&file_id).is_some() { |
@@ -72,20 +72,14 @@ impl AnalysisHostImpl { | |||
72 | } | 72 | } |
73 | 73 | ||
74 | fn data_mut(&mut self) -> &mut WorldData { | 74 | fn data_mut(&mut self) -> &mut WorldData { |
75 | if Arc::get_mut(&mut self.data).is_none() { | 75 | Arc::make_mut(&mut self.data) |
76 | self.data = Arc::new(WorldData { | ||
77 | file_map: self.data.file_map.clone(), | ||
78 | module_map: self.data.module_map.clone(), | ||
79 | }); | ||
80 | } | ||
81 | Arc::get_mut(&mut self.data).unwrap() | ||
82 | } | 76 | } |
83 | } | 77 | } |
84 | 78 | ||
85 | pub(crate) struct AnalysisImpl { | 79 | pub(crate) struct AnalysisImpl { |
86 | pub(crate) needs_reindex: AtomicBool, | 80 | needs_reindex: AtomicBool, |
87 | pub(crate) file_resolver: Arc<FileResolver>, | 81 | file_resolver: Arc<FileResolver>, |
88 | pub(crate) data: Arc<WorldData>, | 82 | data: Arc<WorldData>, |
89 | } | 83 | } |
90 | 84 | ||
91 | impl fmt::Debug for AnalysisImpl { | 85 | impl fmt::Debug for AnalysisImpl { |
@@ -280,7 +274,7 @@ impl AnalysisImpl { | |||
280 | } | 274 | } |
281 | 275 | ||
282 | fn reindex(&self) { | 276 | fn reindex(&self) { |
283 | if self.needs_reindex.compare_and_swap(false, true, SeqCst) { | 277 | if self.needs_reindex.compare_and_swap(true, false, SeqCst) { |
284 | let now = Instant::now(); | 278 | let now = Instant::now(); |
285 | let data = &*self.data; | 279 | let data = &*self.data; |
286 | data.file_map | 280 | data.file_map |
@@ -298,22 +292,22 @@ impl AnalysisImpl { | |||
298 | } | 292 | } |
299 | } | 293 | } |
300 | 294 | ||
301 | #[derive(Default, Debug)] | 295 | #[derive(Clone, Default, Debug)] |
302 | pub(crate) struct WorldData { | 296 | struct WorldData { |
303 | pub(crate) file_map: HashMap<FileId, Arc<FileData>>, | 297 | file_map: HashMap<FileId, Arc<FileData>>, |
304 | pub(crate) module_map: ModuleMap, | 298 | module_map: ModuleMap, |
305 | } | 299 | } |
306 | 300 | ||
307 | #[derive(Debug)] | 301 | #[derive(Debug)] |
308 | pub(crate) struct FileData { | 302 | struct FileData { |
309 | pub(crate) text: String, | 303 | text: String, |
310 | pub(crate) symbols: OnceCell<FileSymbols>, | 304 | symbols: OnceCell<FileSymbols>, |
311 | pub(crate) syntax: OnceCell<File>, | 305 | syntax: OnceCell<File>, |
312 | pub(crate) lines: OnceCell<LineIndex>, | 306 | lines: OnceCell<LineIndex>, |
313 | } | 307 | } |
314 | 308 | ||
315 | impl FileData { | 309 | impl FileData { |
316 | pub(crate) fn new(text: String) -> FileData { | 310 | fn new(text: String) -> FileData { |
317 | FileData { | 311 | FileData { |
318 | text, | 312 | text, |
319 | symbols: OnceCell::new(), | 313 | symbols: OnceCell::new(), |