diff options
Diffstat (limited to 'crates/libanalysis/src/imp.rs')
-rw-r--r-- | crates/libanalysis/src/imp.rs | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/crates/libanalysis/src/imp.rs b/crates/libanalysis/src/imp.rs index 5f451f53f..06bbc7cf2 100644 --- a/crates/libanalysis/src/imp.rs +++ b/crates/libanalysis/src/imp.rs | |||
@@ -22,9 +22,65 @@ use { | |||
22 | FileId, FileResolver, Query, Diagnostic, SourceChange, SourceFileEdit, Position, FileSystemEdit, | 22 | FileId, FileResolver, Query, Diagnostic, SourceChange, SourceFileEdit, Position, FileSystemEdit, |
23 | module_map::Problem, | 23 | module_map::Problem, |
24 | symbol_index::FileSymbols, | 24 | symbol_index::FileSymbols, |
25 | module_map::ModuleMap, | 25 | module_map::{ModuleMap, ChangeKind}, |
26 | }; | 26 | }; |
27 | 27 | ||
28 | #[derive(Debug)] | ||
29 | pub(crate) struct AnalysisHostImpl { | ||
30 | data: Arc<WorldData> | ||
31 | } | ||
32 | |||
33 | impl AnalysisHostImpl { | ||
34 | pub fn new() -> AnalysisHostImpl { | ||
35 | AnalysisHostImpl { | ||
36 | data: Arc::new(WorldData::default()), | ||
37 | } | ||
38 | } | ||
39 | |||
40 | pub fn analysis( | ||
41 | &self, | ||
42 | file_resolver: impl FileResolver, | ||
43 | ) -> AnalysisImpl { | ||
44 | AnalysisImpl { | ||
45 | needs_reindex: AtomicBool::new(false), | ||
46 | file_resolver: Arc::new(file_resolver), | ||
47 | data: self.data.clone() | ||
48 | } | ||
49 | } | ||
50 | |||
51 | pub fn change_files(&mut self, changes: impl Iterator<Item=(FileId, Option<String>)>) { | ||
52 | let data = self.data_mut(); | ||
53 | for (file_id, text) in changes { | ||
54 | let change_kind = if data.file_map.remove(&file_id).is_some() { | ||
55 | if text.is_some() { | ||
56 | ChangeKind::Update | ||
57 | } else { | ||
58 | ChangeKind::Delete | ||
59 | } | ||
60 | } else { | ||
61 | ChangeKind::Insert | ||
62 | }; | ||
63 | data.module_map.update_file(file_id, change_kind); | ||
64 | data.file_map.remove(&file_id); | ||
65 | if let Some(text) = text { | ||
66 | let file_data = FileData::new(text); | ||
67 | data.file_map.insert(file_id, Arc::new(file_data)); | ||
68 | } else { | ||
69 | data.file_map.remove(&file_id); | ||
70 | } | ||
71 | } | ||
72 | } | ||
73 | |||
74 | fn data_mut(&mut self) -> &mut WorldData { | ||
75 | if Arc::get_mut(&mut self.data).is_none() { | ||
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 | } | ||
83 | } | ||
28 | 84 | ||
29 | pub(crate) struct AnalysisImpl { | 85 | pub(crate) struct AnalysisImpl { |
30 | pub(crate) needs_reindex: AtomicBool, | 86 | pub(crate) needs_reindex: AtomicBool, |