aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_analysis/src/db.rs9
-rw-r--r--crates/ra_analysis/src/imp.rs39
-rw-r--r--crates/ra_analysis/src/lib.rs2
-rw-r--r--crates/ra_analysis/src/mock_analysis.rs6
-rw-r--r--crates/ra_db/src/input.rs10
-rw-r--r--crates/ra_db/src/lib.rs4
6 files changed, 37 insertions, 33 deletions
diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs
index b79baf037..3d0f13f34 100644
--- a/crates/ra_analysis/src/db.rs
+++ b/crates/ra_analysis/src/db.rs
@@ -30,11 +30,11 @@ impl Default for RootDatabase {
30 runtime: salsa::Runtime::default(), 30 runtime: salsa::Runtime::default(),
31 id_maps: Default::default(), 31 id_maps: Default::default(),
32 }; 32 };
33 db.query_mut(ra_db::SourceRootQuery)
34 .set(ra_db::WORKSPACE, Default::default());
35 db.query_mut(ra_db::CrateGraphQuery) 33 db.query_mut(ra_db::CrateGraphQuery)
36 .set((), Default::default()); 34 .set((), Default::default());
37 db.query_mut(ra_db::LibrariesQuery) 35 db.query_mut(ra_db::LocalRootsQuery)
36 .set((), Default::default());
37 db.query_mut(ra_db::LibraryRootsQuery)
38 .set((), Default::default()); 38 .set((), Default::default());
39 db 39 db
40 } 40 }
@@ -64,7 +64,8 @@ salsa::database_storage! {
64 fn file_relative_path() for ra_db::FileRelativePathQuery; 64 fn file_relative_path() for ra_db::FileRelativePathQuery;
65 fn file_source_root() for ra_db::FileSourceRootQuery; 65 fn file_source_root() for ra_db::FileSourceRootQuery;
66 fn source_root() for ra_db::SourceRootQuery; 66 fn source_root() for ra_db::SourceRootQuery;
67 fn libraries() for ra_db::LibrariesQuery; 67 fn local_roots() for ra_db::LocalRootsQuery;
68 fn library_roots() for ra_db::LibraryRootsQuery;
68 fn crate_graph() for ra_db::CrateGraphQuery; 69 fn crate_graph() for ra_db::CrateGraphQuery;
69 } 70 }
70 impl ra_db::SyntaxDatabase { 71 impl ra_db::SyntaxDatabase {
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index 54f38b285..46169d863 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -10,7 +10,7 @@ use ra_syntax::{
10 SyntaxKind::*, 10 SyntaxKind::*,
11 SyntaxNodeRef, TextRange, TextUnit, 11 SyntaxNodeRef, TextRange, TextUnit,
12}; 12};
13use ra_db::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE, SyntaxDatabase}; 13use ra_db::{FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase};
14use rayon::prelude::*; 14use rayon::prelude::*;
15use salsa::{Database, ParallelDatabase}; 15use salsa::{Database, ParallelDatabase};
16use hir::{ 16use hir::{
@@ -56,7 +56,7 @@ impl AnalysisHostImpl {
56 self.db.query_mut(ra_db::FileTextQuery).set(file_id, text) 56 self.db.query_mut(ra_db::FileTextQuery).set(file_id, text)
57 } 57 }
58 if !change.libraries_added.is_empty() { 58 if !change.libraries_added.is_empty() {
59 let mut libraries = Vec::clone(&self.db.libraries()); 59 let mut libraries = Vec::clone(&self.db.library_roots());
60 for library in change.libraries_added { 60 for library in change.libraries_added {
61 libraries.push(library.root_id); 61 libraries.push(library.root_id);
62 self.db 62 self.db
@@ -65,7 +65,7 @@ impl AnalysisHostImpl {
65 self.apply_root_change(library.root_id, library.root_change); 65 self.apply_root_change(library.root_id, library.root_change);
66 } 66 }
67 self.db 67 self.db
68 .query_mut(ra_db::LibrariesQuery) 68 .query_mut(ra_db::LibraryRootsQuery)
69 .set((), Arc::new(libraries)); 69 .set((), Arc::new(libraries));
70 } 70 }
71 if let Some(crate_graph) = change.crate_graph { 71 if let Some(crate_graph) = change.crate_graph {
@@ -142,27 +142,26 @@ impl AnalysisImpl {
142 self.db.file_lines(file_id) 142 self.db.file_lines(file_id)
143 } 143 }
144 pub fn world_symbols(&self, query: Query) -> Cancelable<Vec<(FileId, FileSymbol)>> { 144 pub fn world_symbols(&self, query: Query) -> Cancelable<Vec<(FileId, FileSymbol)>> {
145 /// Need to wrap Snapshot to provide `Clone` impl for `map_with`
146 struct Snap(salsa::Snapshot<db::RootDatabase>);
147 impl Clone for Snap {
148 fn clone(&self) -> Snap {
149 Snap(self.0.snapshot())
150 }
151 }
152
145 let buf: Vec<Arc<SymbolIndex>> = if query.libs { 153 let buf: Vec<Arc<SymbolIndex>> = if query.libs {
154 let snap = Snap(self.db.snapshot());
146 self.db 155 self.db
147 .libraries() 156 .library_roots()
148 .iter() 157 .par_iter()
149 .map(|&lib_id| self.db.library_symbols(lib_id)) 158 .map_with(snap, |db, &lib_id| db.0.library_symbols(lib_id))
150 .collect() 159 .collect()
151 } else { 160 } else {
152 let files: Vec<FileId> = self 161 let mut files = Vec::new();
153 .db 162 for &root in self.db.local_roots().iter() {
154 .source_root(WORKSPACE) 163 let sr = self.db.source_root(root);
155 .files 164 files.extend(sr.files.values().map(|&it| it))
156 .values()
157 .map(|&it| it)
158 .collect();
159
160 /// Need to wrap Snapshot to provide `Clone` impl for `map_with`
161 struct Snap(salsa::Snapshot<db::RootDatabase>);
162 impl Clone for Snap {
163 fn clone(&self) -> Snap {
164 Snap(self.0.snapshot())
165 }
166 } 165 }
167 166
168 let snap = Snap(self.db.snapshot()); 167 let snap = Snap(self.db.snapshot());
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs
index 300dfc5dd..0db3c3479 100644
--- a/crates/ra_analysis/src/lib.rs
+++ b/crates/ra_analysis/src/lib.rs
@@ -39,7 +39,7 @@ pub use hir::FnSignatureInfo;
39 39
40pub use ra_db::{ 40pub use ra_db::{
41 Canceled, Cancelable, FilePosition, 41 Canceled, Cancelable, FilePosition,
42 CrateGraph, CrateId, SourceRootId, FileId, WORKSPACE 42 CrateGraph, CrateId, SourceRootId, FileId
43}; 43};
44 44
45#[derive(Default)] 45#[derive(Default)]
diff --git a/crates/ra_analysis/src/mock_analysis.rs b/crates/ra_analysis/src/mock_analysis.rs
index 691af4a48..0c042e672 100644
--- a/crates/ra_analysis/src/mock_analysis.rs
+++ b/crates/ra_analysis/src/mock_analysis.rs
@@ -4,7 +4,7 @@ use relative_path::{RelativePathBuf};
4use test_utils::{extract_offset, parse_fixture, CURSOR_MARKER}; 4use test_utils::{extract_offset, parse_fixture, CURSOR_MARKER};
5use ra_db::mock::FileMap; 5use ra_db::mock::FileMap;
6 6
7use crate::{Analysis, AnalysisChange, AnalysisHost, FileId, FilePosition, WORKSPACE}; 7use crate::{Analysis, AnalysisChange, AnalysisHost, FileId, FilePosition, SourceRootId};
8 8
9/// Mock analysis is used in test to bootstrap an AnalysisHost/Analysis 9/// Mock analysis is used in test to bootstrap an AnalysisHost/Analysis
10/// from a set of in-memory files. 10/// from a set of in-memory files.
@@ -78,12 +78,14 @@ impl MockAnalysis {
78 pub fn analysis_host(self) -> AnalysisHost { 78 pub fn analysis_host(self) -> AnalysisHost {
79 let mut host = AnalysisHost::default(); 79 let mut host = AnalysisHost::default();
80 let mut file_map = FileMap::default(); 80 let mut file_map = FileMap::default();
81 let source_root = SourceRootId(0);
81 let mut change = AnalysisChange::new(); 82 let mut change = AnalysisChange::new();
83 change.add_root(source_root);
82 for (path, contents) in self.files.into_iter() { 84 for (path, contents) in self.files.into_iter() {
83 assert!(path.starts_with('/')); 85 assert!(path.starts_with('/'));
84 let path = RelativePathBuf::from_path(&path[1..]).unwrap(); 86 let path = RelativePathBuf::from_path(&path[1..]).unwrap();
85 let file_id = file_map.add(path.clone()); 87 let file_id = file_map.add(path.clone());
86 change.add_file(WORKSPACE, file_id, path, Arc::new(contents)); 88 change.add_file(source_root, file_id, path, Arc::new(contents));
87 } 89 }
88 // change.set_file_resolver(Arc::new(file_map)); 90 // change.set_file_resolver(Arc::new(file_map));
89 host.apply_change(change); 91 host.apply_change(change);
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs
index 51daa8e86..cccf37cc2 100644
--- a/crates/ra_db/src/input.rs
+++ b/crates/ra_db/src/input.rs
@@ -8,8 +8,6 @@ use salsa;
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] 8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
9pub struct SourceRootId(pub u32); 9pub struct SourceRootId(pub u32);
10 10
11pub const WORKSPACE: SourceRootId = SourceRootId(0);
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] 11#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
14pub struct FileId(pub u32); 12pub struct FileId(pub u32);
15 13
@@ -102,8 +100,12 @@ salsa::query_group! {
102 type SourceRootQuery; 100 type SourceRootQuery;
103 storage input; 101 storage input;
104 } 102 }
105 fn libraries() -> Arc<Vec<SourceRootId>> { 103 fn local_roots() -> Arc<Vec<SourceRootId>> {
106 type LibrariesQuery; 104 type LocalRootsQuery;
105 storage input;
106 }
107 fn library_roots() -> Arc<Vec<SourceRootId>> {
108 type LibraryRootsQuery;
107 storage input; 109 storage input;
108 } 110 }
109 fn crate_graph() -> Arc<CrateGraph> { 111 fn crate_graph() -> Arc<CrateGraph> {
diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs
index eeb305b1b..65fa3cbfa 100644
--- a/crates/ra_db/src/lib.rs
+++ b/crates/ra_db/src/lib.rs
@@ -24,8 +24,8 @@ impl std::error::Error for Canceled {}
24pub use crate::{ 24pub use crate::{
25 syntax_ptr::LocalSyntaxPtr, 25 syntax_ptr::LocalSyntaxPtr,
26 input::{ 26 input::{
27 FilesDatabase, FileId, CrateId, SourceRoot, SourceRootId, CrateGraph, WORKSPACE, 27 FilesDatabase, FileId, CrateId, SourceRoot, SourceRootId, CrateGraph,
28 FileTextQuery, FileSourceRootQuery, SourceRootQuery, LibrariesQuery, CrateGraphQuery, 28 FileTextQuery, FileSourceRootQuery, SourceRootQuery, LocalRootsQuery, LibraryRootsQuery, CrateGraphQuery,
29 FileRelativePathQuery 29 FileRelativePathQuery
30 }, 30 },
31 loc2id::{LocationIntener, NumericId}, 31 loc2id::{LocationIntener, NumericId},