aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/imp.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-12-19 09:20:54 +0000
committerAleksey Kladov <[email protected]>2018-12-20 09:15:38 +0000
commit85290bc1342560d5560f0b2151cff1c0c6dac155 (patch)
treee7817987dc9dba9485659b8c2585e3c6315496c9 /crates/ra_analysis/src/imp.rs
parent815a0e577821a3876aa4c79c13200607acadcd2f (diff)
switch analysis to vfs
Diffstat (limited to 'crates/ra_analysis/src/imp.rs')
-rw-r--r--crates/ra_analysis/src/imp.rs88
1 files changed, 42 insertions, 46 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index e2c20b0e3..51bcd5a73 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -12,7 +12,6 @@ use ra_syntax::{
12}; 12};
13use ra_db::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE, SyntaxDatabase}; 13use ra_db::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE, SyntaxDatabase};
14use rayon::prelude::*; 14use rayon::prelude::*;
15use rustc_hash::FxHashSet;
16use salsa::{Database, ParallelDatabase}; 15use salsa::{Database, ParallelDatabase};
17use hir::{ 16use hir::{
18 self, 17 self,
@@ -25,7 +24,7 @@ use crate::{
25 completion::{completions, CompletionItem}, 24 completion::{completions, CompletionItem},
26 db, 25 db,
27 symbol_index::{SymbolIndex, SymbolsDatabase}, 26 symbol_index::{SymbolIndex, SymbolsDatabase},
28 AnalysisChange, Cancelable, CrateId, Diagnostic, FileId, 27 AnalysisChange, RootChange, Cancelable, CrateId, Diagnostic, FileId,
29 FileSystemEdit, FilePosition, Query, SourceChange, SourceFileNodeEdit, 28 FileSystemEdit, FilePosition, Query, SourceChange, SourceFileNodeEdit,
30 ReferenceResolution, 29 ReferenceResolution,
31}; 30};
@@ -45,59 +44,22 @@ impl AnalysisHostImpl {
45 log::info!("apply_change {:?}", change); 44 log::info!("apply_change {:?}", change);
46 // self.gc_syntax_trees(); 45 // self.gc_syntax_trees();
47 46
47 for (root_id, root_change) in change.roots_changed {
48 self.apply_root_change(root_id, root_change);
49 }
48 for (file_id, text) in change.files_changed { 50 for (file_id, text) in change.files_changed {
49 self.db 51 self.db
50 .query_mut(ra_db::FileTextQuery) 52 .query_mut(ra_db::FileTextQuery)
51 .set(file_id, Arc::new(text)) 53 .set(file_id, Arc::new(text))
52 } 54 }
53 if !(change.files_added.is_empty() && change.files_removed.is_empty()) {
54 let mut source_root = SourceRoot::clone(&self.db.source_root(WORKSPACE));
55 for (file_id, text) in change.files_added {
56 self.db
57 .query_mut(ra_db::FileTextQuery)
58 .set(file_id, Arc::new(text));
59 self.db
60 .query_mut(ra_db::FileSourceRootQuery)
61 .set(file_id, ra_db::WORKSPACE);
62 source_root.files.insert(file_id);
63 }
64 for file_id in change.files_removed {
65 self.db
66 .query_mut(ra_db::FileTextQuery)
67 .set(file_id, Arc::new(String::new()));
68 source_root.files.remove(&file_id);
69 }
70 self.db
71 .query_mut(ra_db::SourceRootQuery)
72 .set(WORKSPACE, Arc::new(source_root))
73 }
74 if !change.libraries_added.is_empty() { 55 if !change.libraries_added.is_empty() {
75 let mut libraries = Vec::clone(&self.db.libraries()); 56 let mut libraries = Vec::clone(&self.db.libraries());
76 for library in change.libraries_added { 57 for library in change.libraries_added {
77 let source_root_id = SourceRootId(1 + libraries.len() as u32); 58 libraries.push(library.root_id);
78 libraries.push(source_root_id);
79 let mut files = FxHashSet::default();
80 for (file_id, text) in library.files {
81 files.insert(file_id);
82 log::debug!(
83 "library file: {:?} {:?}",
84 file_id,
85 library.file_resolver.debug_path(file_id)
86 );
87 self.db
88 .query_mut(ra_db::FileSourceRootQuery)
89 .set_constant(file_id, source_root_id);
90 self.db
91 .query_mut(ra_db::FileTextQuery)
92 .set_constant(file_id, Arc::new(text));
93 }
94 let source_root = SourceRoot { files };
95 self.db 59 self.db
96 .query_mut(ra_db::SourceRootQuery) 60 .query_mut(ra_db::SourceRootQuery)
97 .set(source_root_id, Arc::new(source_root)); 61 .set(library.root_id, Default::default());
98 self.db 62 self.apply_root_change(library.root_id, library.root_change);
99 .query_mut(crate::symbol_index::LibrarySymbolsQuery)
100 .set(source_root_id, Arc::new(library.symbol_index));
101 } 63 }
102 self.db 64 self.db
103 .query_mut(ra_db::LibrariesQuery) 65 .query_mut(ra_db::LibrariesQuery)
@@ -110,6 +72,34 @@ impl AnalysisHostImpl {
110 } 72 }
111 } 73 }
112 74
75 fn apply_root_change(&mut self, root_id: SourceRootId, root_change: RootChange) {
76 let mut source_root = SourceRoot::clone(&self.db.source_root(root_id));
77 for add_file in root_change.added {
78 self.db
79 .query_mut(ra_db::FileTextQuery)
80 .set(add_file.file_id, add_file.text);
81 self.db
82 .query_mut(ra_db::FileRelativePathQuery)
83 .set(add_file.file_id, add_file.path.clone());
84 self.db
85 .query_mut(ra_db::FileSourceRootQuery)
86 .set(add_file.file_id, root_id);
87 source_root.files.insert(add_file.path, add_file.file_id);
88 }
89 for remove_file in root_change.removed {
90 self.db
91 .query_mut(ra_db::FileTextQuery)
92 .set(remove_file.file_id, Default::default());
93 self.db
94 .query_mut(ra_db::FileRelativePathQuery)
95 .set(remove_file.file_id, Default::default());
96 source_root.files.remove(&remove_file.path);
97 }
98 self.db
99 .query_mut(ra_db::SourceRootQuery)
100 .set(root_id, Arc::new(source_root));
101 }
102
113 #[allow(unused)] 103 #[allow(unused)]
114 /// Ideally, we should call this function from time to time to collect heavy 104 /// Ideally, we should call this function from time to time to collect heavy
115 /// syntax trees. However, if we actually do that, everything is recomputed 105 /// syntax trees. However, if we actually do that, everything is recomputed
@@ -156,7 +146,13 @@ impl AnalysisImpl {
156 .map(|&lib_id| self.db.library_symbols(lib_id)) 146 .map(|&lib_id| self.db.library_symbols(lib_id))
157 .collect() 147 .collect()
158 } else { 148 } else {
159 let files = &self.db.source_root(WORKSPACE).files; 149 let files: Vec<FileId> = self
150 .db
151 .source_root(WORKSPACE)
152 .files
153 .values()
154 .map(|&it| it)
155 .collect();
160 156
161 /// Need to wrap Snapshot to provide `Clone` impl for `map_with` 157 /// Need to wrap Snapshot to provide `Clone` impl for `map_with`
162 struct Snap(salsa::Snapshot<db::RootDatabase>); 158 struct Snap(salsa::Snapshot<db::RootDatabase>);