diff options
author | Aleksey Kladov <[email protected]> | 2018-12-19 13:13:16 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-12-20 09:15:38 +0000 |
commit | e6465e7e2a7e136edd652d5f4c93b961dd652cbc (patch) | |
tree | 4e82bd6b881d322936f7528a95d87763dca2e18c /crates/ra_analysis | |
parent | 51fec4ef844d7fe83bf96c74e02e5f820837ff2d (diff) |
index all local crates
Diffstat (limited to 'crates/ra_analysis')
-rw-r--r-- | crates/ra_analysis/src/db.rs | 9 | ||||
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 39 | ||||
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 2 | ||||
-rw-r--r-- | crates/ra_analysis/src/mock_analysis.rs | 6 |
4 files changed, 29 insertions, 27 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 | }; |
13 | use ra_db::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE, SyntaxDatabase}; | 13 | use ra_db::{FilesDatabase, SourceRoot, SourceRootId, SyntaxDatabase}; |
14 | use rayon::prelude::*; | 14 | use rayon::prelude::*; |
15 | use salsa::{Database, ParallelDatabase}; | 15 | use salsa::{Database, ParallelDatabase}; |
16 | use hir::{ | 16 | use 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 | ||
40 | pub use ra_db::{ | 40 | pub 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}; | |||
4 | use test_utils::{extract_offset, parse_fixture, CURSOR_MARKER}; | 4 | use test_utils::{extract_offset, parse_fixture, CURSOR_MARKER}; |
5 | use ra_db::mock::FileMap; | 5 | use ra_db::mock::FileMap; |
6 | 6 | ||
7 | use crate::{Analysis, AnalysisChange, AnalysisHost, FileId, FilePosition, WORKSPACE}; | 7 | use 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); |