aboutsummaryrefslogtreecommitdiff
path: root/crates/libanalysis/src/imp.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-30 11:12:49 +0100
committerAleksey Kladov <[email protected]>2018-08-30 11:12:49 +0100
commitc2c64145cb0487b20b79d4bf470cda7e39fcb236 (patch)
tree133c220acab90d756ed48cc1951ed3752026e297 /crates/libanalysis/src/imp.rs
parent1f2fb4e27f8ba1cb7b1d96a332b7ffc2ee659921 (diff)
move
Diffstat (limited to 'crates/libanalysis/src/imp.rs')
-rw-r--r--crates/libanalysis/src/imp.rs46
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
12use rayon::prelude::*;
13use once_cell::sync::OnceCell;
14use libeditor::{self, FileSymbol, LineIndex, find_node_at_offset, LocalEdit};
12use libsyntax2::{ 15use 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};
17use rayon::prelude::*;
18use once_cell::sync::OnceCell;
19use libeditor::{self, FileSymbol, LineIndex, find_node_at_offset, LocalEdit};
20 20
21use { 21use {
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
85pub(crate) struct AnalysisImpl { 79pub(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
91impl fmt::Debug for AnalysisImpl { 85impl 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)]
302pub(crate) struct WorldData { 296struct 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)]
308pub(crate) struct FileData { 302struct 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
315impl FileData { 309impl 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(),