aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_db/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_db/src')
-rw-r--r--crates/ide_db/src/apply_change.rs (renamed from crates/ide_db/src/change.rs)78
-rw-r--r--crates/ide_db/src/lib.rs2
2 files changed, 7 insertions, 73 deletions
diff --git a/crates/ide_db/src/change.rs b/crates/ide_db/src/apply_change.rs
index 7f98111c4..da16fa21d 100644
--- a/crates/ide_db/src/change.rs
+++ b/crates/ide_db/src/apply_change.rs
@@ -1,58 +1,16 @@
1//! Defines a unit of change that can applied to a state of IDE to get the next 1//! Applies changes to the IDE state transactionally.
2//! state. Changes are transactional.
3 2
4use std::{fmt, sync::Arc}; 3use std::{fmt, sync::Arc};
5 4
6use base_db::{ 5use base_db::{
7 salsa::{Database, Durability, SweepStrategy}, 6 salsa::{Database, Durability, SweepStrategy},
8 CrateGraph, FileId, SourceDatabase, SourceDatabaseExt, SourceRoot, SourceRootId, 7 Change, FileId, SourceRootId,
9}; 8};
10use profile::{memory_usage, Bytes}; 9use profile::{memory_usage, Bytes};
11use rustc_hash::FxHashSet; 10use rustc_hash::FxHashSet;
12 11
13use crate::{symbol_index::SymbolsDatabase, RootDatabase}; 12use crate::{symbol_index::SymbolsDatabase, RootDatabase};
14 13
15#[derive(Default)]
16pub struct AnalysisChange {
17 roots: Option<Vec<SourceRoot>>,
18 files_changed: Vec<(FileId, Option<Arc<String>>)>,
19 crate_graph: Option<CrateGraph>,
20}
21
22impl fmt::Debug for AnalysisChange {
23 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
24 let mut d = fmt.debug_struct("AnalysisChange");
25 if let Some(roots) = &self.roots {
26 d.field("roots", roots);
27 }
28 if !self.files_changed.is_empty() {
29 d.field("files_changed", &self.files_changed.len());
30 }
31 if self.crate_graph.is_some() {
32 d.field("crate_graph", &self.crate_graph);
33 }
34 d.finish()
35 }
36}
37
38impl AnalysisChange {
39 pub fn new() -> AnalysisChange {
40 AnalysisChange::default()
41 }
42
43 pub fn set_roots(&mut self, roots: Vec<SourceRoot>) {
44 self.roots = Some(roots);
45 }
46
47 pub fn change_file(&mut self, file_id: FileId, new_text: Option<Arc<String>>) {
48 self.files_changed.push((file_id, new_text))
49 }
50
51 pub fn set_crate_graph(&mut self, graph: CrateGraph) {
52 self.crate_graph = Some(graph);
53 }
54}
55
56#[derive(Debug)] 14#[derive(Debug)]
57struct AddFile { 15struct AddFile {
58 file_id: FileId, 16 file_id: FileId,
@@ -87,41 +45,25 @@ impl RootDatabase {
87 self.salsa_runtime_mut().synthetic_write(Durability::LOW); 45 self.salsa_runtime_mut().synthetic_write(Durability::LOW);
88 } 46 }
89 47
90 pub fn apply_change(&mut self, change: AnalysisChange) { 48 pub fn apply_change(&mut self, change: Change) {
91 let _p = profile::span("RootDatabase::apply_change"); 49 let _p = profile::span("RootDatabase::apply_change");
92 self.request_cancellation(); 50 self.request_cancellation();
93 log::info!("apply_change {:?}", change); 51 log::info!("apply_change {:?}", change);
94 if let Some(roots) = change.roots { 52 if let Some(roots) = &change.roots {
95 let mut local_roots = FxHashSet::default(); 53 let mut local_roots = FxHashSet::default();
96 let mut library_roots = FxHashSet::default(); 54 let mut library_roots = FxHashSet::default();
97 for (idx, root) in roots.into_iter().enumerate() { 55 for (idx, root) in roots.iter().enumerate() {
98 let root_id = SourceRootId(idx as u32); 56 let root_id = SourceRootId(idx as u32);
99 let durability = durability(&root);
100 if root.is_library { 57 if root.is_library {
101 library_roots.insert(root_id); 58 library_roots.insert(root_id);
102 } else { 59 } else {
103 local_roots.insert(root_id); 60 local_roots.insert(root_id);
104 } 61 }
105 for file_id in root.iter() {
106 self.set_file_source_root_with_durability(file_id, root_id, durability);
107 }
108 self.set_source_root_with_durability(root_id, Arc::new(root), durability);
109 } 62 }
110 self.set_local_roots_with_durability(Arc::new(local_roots), Durability::HIGH); 63 self.set_local_roots_with_durability(Arc::new(local_roots), Durability::HIGH);
111 self.set_library_roots_with_durability(Arc::new(library_roots), Durability::HIGH); 64 self.set_library_roots_with_durability(Arc::new(library_roots), Durability::HIGH);
112 } 65 }
113 66 change.apply(self);
114 for (file_id, text) in change.files_changed {
115 let source_root_id = self.file_source_root(file_id);
116 let source_root = self.source_root(source_root_id);
117 let durability = durability(&source_root);
118 // XXX: can't actually remove the file, just reset the text
119 let text = text.unwrap_or_default();
120 self.set_file_text_with_durability(file_id, text, durability)
121 }
122 if let Some(crate_graph) = change.crate_graph {
123 self.set_crate_graph_with_durability(Arc::new(crate_graph), Durability::HIGH)
124 }
125 } 67 }
126 68
127 pub fn collect_garbage(&mut self) { 69 pub fn collect_garbage(&mut self) {
@@ -295,11 +237,3 @@ impl RootDatabase {
295 acc 237 acc
296 } 238 }
297} 239}
298
299fn durability(source_root: &SourceRoot) -> Durability {
300 if source_root.is_library {
301 Durability::HIGH
302 } else {
303 Durability::LOW
304 }
305}
diff --git a/crates/ide_db/src/lib.rs b/crates/ide_db/src/lib.rs
index 0d209c6ec..7eff247c7 100644
--- a/crates/ide_db/src/lib.rs
+++ b/crates/ide_db/src/lib.rs
@@ -2,10 +2,10 @@
2//! 2//!
3//! It is mainly a `HirDatabase` for semantic analysis, plus a `SymbolsDatabase`, for fuzzy search. 3//! It is mainly a `HirDatabase` for semantic analysis, plus a `SymbolsDatabase`, for fuzzy search.
4 4
5mod apply_change;
5pub mod label; 6pub mod label;
6pub mod line_index; 7pub mod line_index;
7pub mod symbol_index; 8pub mod symbol_index;
8pub mod change;
9pub mod defs; 9pub mod defs;
10pub mod search; 10pub mod search;
11pub mod imports_locator; 11pub mod imports_locator;