aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_db
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-06-23 16:53:56 +0100
committerGitHub <[email protected]>2020-06-23 16:53:56 +0100
commit0c12c4f9609ee72487af9b55a558b01af73ffe3e (patch)
tree29be52a980b4cae72f46a48c48135a15e31641e0 /crates/ra_ide_db
parent7aa66371ee3e8b31217513204c8b4f683584419d (diff)
parentdad1333b48c38bc7a5628fc0ff5304d003776a85 (diff)
Merge #4976
4976: New VFS r=matklad a=matklad Still a draft, but mostly working already. Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide_db')
-rw-r--r--crates/ra_ide_db/src/change.rs85
-rw-r--r--crates/ra_ide_db/src/search.rs4
-rw-r--r--crates/ra_ide_db/src/symbol_index.rs10
3 files changed, 30 insertions, 69 deletions
diff --git a/crates/ra_ide_db/src/change.rs b/crates/ra_ide_db/src/change.rs
index 98993d571..a95f6c13c 100644
--- a/crates/ra_ide_db/src/change.rs
+++ b/crates/ra_ide_db/src/change.rs
@@ -9,26 +9,22 @@ use ra_db::{
9 SourceRootId, 9 SourceRootId,
10}; 10};
11use ra_prof::{memory_usage, profile, Bytes}; 11use ra_prof::{memory_usage, profile, Bytes};
12use rustc_hash::FxHashMap; 12use rustc_hash::FxHashSet;
13 13
14use crate::{symbol_index::SymbolsDatabase, RootDatabase}; 14use crate::{symbol_index::SymbolsDatabase, RootDatabase};
15 15
16#[derive(Default)] 16#[derive(Default)]
17pub struct AnalysisChange { 17pub struct AnalysisChange {
18 new_roots: Vec<(SourceRootId, bool)>, 18 roots: Option<Vec<SourceRoot>>,
19 roots_changed: FxHashMap<SourceRootId, RootChange>, 19 files_changed: Vec<(FileId, Option<Arc<String>>)>,
20 files_changed: Vec<(FileId, Arc<String>)>,
21 crate_graph: Option<CrateGraph>, 20 crate_graph: Option<CrateGraph>,
22} 21}
23 22
24impl fmt::Debug for AnalysisChange { 23impl fmt::Debug for AnalysisChange {
25 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { 24 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
26 let mut d = fmt.debug_struct("AnalysisChange"); 25 let mut d = fmt.debug_struct("AnalysisChange");
27 if !self.new_roots.is_empty() { 26 if let Some(roots) = &self.roots {
28 d.field("new_roots", &self.new_roots); 27 d.field("roots", roots);
29 }
30 if !self.roots_changed.is_empty() {
31 d.field("roots_changed", &self.roots_changed);
32 } 28 }
33 if !self.files_changed.is_empty() { 29 if !self.files_changed.is_empty() {
34 d.field("files_changed", &self.files_changed.len()); 30 d.field("files_changed", &self.files_changed.len());
@@ -45,30 +41,14 @@ impl AnalysisChange {
45 AnalysisChange::default() 41 AnalysisChange::default()
46 } 42 }
47 43
48 pub fn add_root(&mut self, root_id: SourceRootId, is_local: bool) { 44 pub fn set_roots(&mut self, roots: Vec<SourceRoot>) {
49 self.new_roots.push((root_id, is_local)); 45 self.roots = Some(roots);
50 }
51
52 pub fn add_file(
53 &mut self,
54 root_id: SourceRootId,
55 file_id: FileId,
56 path: RelativePathBuf,
57 text: Arc<String>,
58 ) {
59 let file = AddFile { file_id, path, text };
60 self.roots_changed.entry(root_id).or_default().added.push(file);
61 } 46 }
62 47
63 pub fn change_file(&mut self, file_id: FileId, new_text: Arc<String>) { 48 pub fn change_file(&mut self, file_id: FileId, new_text: Option<Arc<String>>) {
64 self.files_changed.push((file_id, new_text)) 49 self.files_changed.push((file_id, new_text))
65 } 50 }
66 51
67 pub fn remove_file(&mut self, root_id: SourceRootId, file_id: FileId, path: RelativePathBuf) {
68 let file = RemoveFile { file_id, path };
69 self.roots_changed.entry(root_id).or_default().removed.push(file);
70 }
71
72 pub fn set_crate_graph(&mut self, graph: CrateGraph) { 52 pub fn set_crate_graph(&mut self, graph: CrateGraph) {
73 self.crate_graph = Some(graph); 53 self.crate_graph = Some(graph);
74 } 54 }
@@ -114,31 +94,32 @@ impl RootDatabase {
114 let _p = profile("RootDatabase::apply_change"); 94 let _p = profile("RootDatabase::apply_change");
115 self.request_cancellation(); 95 self.request_cancellation();
116 log::info!("apply_change {:?}", change); 96 log::info!("apply_change {:?}", change);
117 if !change.new_roots.is_empty() { 97 if let Some(roots) = change.roots {
118 let mut local_roots = Vec::clone(&self.local_roots()); 98 let mut local_roots = FxHashSet::default();
119 let mut libraries = Vec::clone(&self.library_roots()); 99 let mut library_roots = FxHashSet::default();
120 for (root_id, is_local) in change.new_roots { 100 for (idx, root) in roots.into_iter().enumerate() {
121 let root = 101 let root_id = SourceRootId(idx as u32);
122 if is_local { SourceRoot::new_local() } else { SourceRoot::new_library() };
123 let durability = durability(&root); 102 let durability = durability(&root);
124 self.set_source_root_with_durability(root_id, Arc::new(root), durability); 103 if root.is_library {
125 if is_local { 104 library_roots.insert(root_id);
126 local_roots.push(root_id);
127 } else { 105 } else {
128 libraries.push(root_id) 106 local_roots.insert(root_id);
107 }
108 for file_id in root.iter() {
109 self.set_file_source_root_with_durability(file_id, root_id, durability);
129 } 110 }
111 self.set_source_root_with_durability(root_id, Arc::new(root), durability);
130 } 112 }
131 self.set_local_roots_with_durability(Arc::new(local_roots), Durability::HIGH); 113 self.set_local_roots_with_durability(Arc::new(local_roots), Durability::HIGH);
132 self.set_library_roots_with_durability(Arc::new(libraries), Durability::HIGH); 114 self.set_library_roots_with_durability(Arc::new(library_roots), Durability::HIGH);
133 } 115 }
134 116
135 for (root_id, root_change) in change.roots_changed {
136 self.apply_root_change(root_id, root_change);
137 }
138 for (file_id, text) in change.files_changed { 117 for (file_id, text) in change.files_changed {
139 let source_root_id = self.file_source_root(file_id); 118 let source_root_id = self.file_source_root(file_id);
140 let source_root = self.source_root(source_root_id); 119 let source_root = self.source_root(source_root_id);
141 let durability = durability(&source_root); 120 let durability = durability(&source_root);
121 // XXX: can't actually remove the file, just reset the text
122 let text = text.unwrap_or_default();
142 self.set_file_text_with_durability(file_id, text, durability) 123 self.set_file_text_with_durability(file_id, text, durability)
143 } 124 }
144 if let Some(crate_graph) = change.crate_graph { 125 if let Some(crate_graph) = change.crate_graph {
@@ -146,26 +127,6 @@ impl RootDatabase {
146 } 127 }
147 } 128 }
148 129
149 fn apply_root_change(&mut self, root_id: SourceRootId, root_change: RootChange) {
150 let mut source_root = SourceRoot::clone(&self.source_root(root_id));
151 let durability = durability(&source_root);
152 for add_file in root_change.added {
153 self.set_file_text_with_durability(add_file.file_id, add_file.text, durability);
154 self.set_file_relative_path_with_durability(
155 add_file.file_id,
156 add_file.path.clone(),
157 durability,
158 );
159 self.set_file_source_root_with_durability(add_file.file_id, root_id, durability);
160 source_root.insert_file(add_file.path, add_file.file_id);
161 }
162 for remove_file in root_change.removed {
163 self.set_file_text_with_durability(remove_file.file_id, Default::default(), durability);
164 source_root.remove_file(&remove_file.path);
165 }
166 self.set_source_root_with_durability(root_id, Arc::new(source_root), durability);
167 }
168
169 pub fn maybe_collect_garbage(&mut self) { 130 pub fn maybe_collect_garbage(&mut self) {
170 if cfg!(feature = "wasm") { 131 if cfg!(feature = "wasm") {
171 return; 132 return;
diff --git a/crates/ra_ide_db/src/search.rs b/crates/ra_ide_db/src/search.rs
index 335a1ad03..44d5c35e6 100644
--- a/crates/ra_ide_db/src/search.rs
+++ b/crates/ra_ide_db/src/search.rs
@@ -157,14 +157,14 @@ impl Definition {
157 if let Some(Visibility::Public) = vis { 157 if let Some(Visibility::Public) = vis {
158 let source_root_id = db.file_source_root(file_id); 158 let source_root_id = db.file_source_root(file_id);
159 let source_root = db.source_root(source_root_id); 159 let source_root = db.source_root(source_root_id);
160 let mut res = source_root.walk().map(|id| (id, None)).collect::<FxHashMap<_, _>>(); 160 let mut res = source_root.iter().map(|id| (id, None)).collect::<FxHashMap<_, _>>();
161 161
162 let krate = module.krate(); 162 let krate = module.krate();
163 for rev_dep in krate.reverse_dependencies(db) { 163 for rev_dep in krate.reverse_dependencies(db) {
164 let root_file = rev_dep.root_file(db); 164 let root_file = rev_dep.root_file(db);
165 let source_root_id = db.file_source_root(root_file); 165 let source_root_id = db.file_source_root(root_file);
166 let source_root = db.source_root(source_root_id); 166 let source_root = db.source_root(source_root_id);
167 res.extend(source_root.walk().map(|id| (id, None))); 167 res.extend(source_root.iter().map(|id| (id, None)));
168 } 168 }
169 return SearchScope::new(res); 169 return SearchScope::new(res);
170 } 170 }
diff --git a/crates/ra_ide_db/src/symbol_index.rs b/crates/ra_ide_db/src/symbol_index.rs
index 25c99813f..6929055b2 100644
--- a/crates/ra_ide_db/src/symbol_index.rs
+++ b/crates/ra_ide_db/src/symbol_index.rs
@@ -42,7 +42,7 @@ use ra_syntax::{
42 SyntaxNode, SyntaxNodePtr, TextRange, WalkEvent, 42 SyntaxNode, SyntaxNodePtr, TextRange, WalkEvent,
43}; 43};
44use rayon::prelude::*; 44use rayon::prelude::*;
45use rustc_hash::FxHashMap; 45use rustc_hash::{FxHashMap, FxHashSet};
46 46
47use crate::RootDatabase; 47use crate::RootDatabase;
48 48
@@ -93,11 +93,11 @@ pub trait SymbolsDatabase: hir::db::HirDatabase + SourceDatabaseExt + ParallelDa
93 /// The set of "local" (that is, from the current workspace) roots. 93 /// The set of "local" (that is, from the current workspace) roots.
94 /// Files in local roots are assumed to change frequently. 94 /// Files in local roots are assumed to change frequently.
95 #[salsa::input] 95 #[salsa::input]
96 fn local_roots(&self) -> Arc<Vec<SourceRootId>>; 96 fn local_roots(&self) -> Arc<FxHashSet<SourceRootId>>;
97 /// The set of roots for crates.io libraries. 97 /// The set of roots for crates.io libraries.
98 /// Files in libraries are assumed to never change. 98 /// Files in libraries are assumed to never change.
99 #[salsa::input] 99 #[salsa::input]
100 fn library_roots(&self) -> Arc<Vec<SourceRootId>>; 100 fn library_roots(&self) -> Arc<FxHashSet<SourceRootId>>;
101} 101}
102 102
103fn library_symbols( 103fn library_symbols(
@@ -111,7 +111,7 @@ fn library_symbols(
111 .map(|&root_id| { 111 .map(|&root_id| {
112 let root = db.source_root(root_id); 112 let root = db.source_root(root_id);
113 let files = root 113 let files = root
114 .walk() 114 .iter()
115 .map(|it| (it, SourceDatabaseExt::file_text(db, it))) 115 .map(|it| (it, SourceDatabaseExt::file_text(db, it)))
116 .collect::<Vec<_>>(); 116 .collect::<Vec<_>>();
117 let symbol_index = SymbolIndex::for_files( 117 let symbol_index = SymbolIndex::for_files(
@@ -175,7 +175,7 @@ pub fn world_symbols(db: &RootDatabase, query: Query) -> Vec<FileSymbol> {
175 let mut files = Vec::new(); 175 let mut files = Vec::new();
176 for &root in db.local_roots().iter() { 176 for &root in db.local_roots().iter() {
177 let sr = db.source_root(root); 177 let sr = db.source_root(root);
178 files.extend(sr.walk()) 178 files.extend(sr.iter())
179 } 179 }
180 180
181 let snap = Snap(db.snapshot()); 181 let snap = Snap(db.snapshot());