diff options
author | Aleksey Kladov <[email protected]> | 2019-01-02 15:08:14 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-02 15:08:14 +0000 |
commit | a94530afb354d2f9a3e3864c678aa496c8de6a23 (patch) | |
tree | f8591449a13c9272fd1038c771cdff1de3349847 /crates | |
parent | 29d8bfb9c909847cb37ff6e564ea0e61744277ad (diff) |
move world-symbols to file_symbols
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 38 | ||||
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 4 | ||||
-rw-r--r-- | crates/ra_analysis/src/symbol_index.rs | 42 |
3 files changed, 42 insertions, 42 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index 8071554a7..9ac52b5c3 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs | |||
@@ -3,7 +3,6 @@ use std::{ | |||
3 | sync::Arc, | 3 | sync::Arc, |
4 | }; | 4 | }; |
5 | 5 | ||
6 | use rayon::prelude::*; | ||
7 | use salsa::{Database, ParallelDatabase}; | 6 | use salsa::{Database, ParallelDatabase}; |
8 | 7 | ||
9 | use hir::{ | 8 | use hir::{ |
@@ -25,7 +24,7 @@ use crate::{ | |||
25 | completion::{CompletionItem, completions}, | 24 | completion::{CompletionItem, completions}, |
26 | CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit, | 25 | CrateId, db, Diagnostic, FileId, FilePosition, FileRange, FileSystemEdit, |
27 | Query, ReferenceResolution, RootChange, SourceChange, SourceFileEdit, | 26 | Query, ReferenceResolution, RootChange, SourceChange, SourceFileEdit, |
28 | symbol_index::{LibrarySymbolsQuery, SymbolIndex, SymbolsDatabase, FileSymbol}, | 27 | symbol_index::{LibrarySymbolsQuery, FileSymbol}, |
29 | }; | 28 | }; |
30 | 29 | ||
31 | #[derive(Debug, Default)] | 30 | #[derive(Debug, Default)] |
@@ -149,39 +148,6 @@ impl AnalysisImpl { | |||
149 | pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> { | 148 | pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> { |
150 | self.db.file_lines(file_id) | 149 | self.db.file_lines(file_id) |
151 | } | 150 | } |
152 | pub fn world_symbols(&self, query: Query) -> Cancelable<Vec<(FileId, FileSymbol)>> { | ||
153 | /// Need to wrap Snapshot to provide `Clone` impl for `map_with` | ||
154 | struct Snap(salsa::Snapshot<db::RootDatabase>); | ||
155 | impl Clone for Snap { | ||
156 | fn clone(&self) -> Snap { | ||
157 | Snap(self.0.snapshot()) | ||
158 | } | ||
159 | } | ||
160 | |||
161 | let buf: Vec<Arc<SymbolIndex>> = if query.libs { | ||
162 | let snap = Snap(self.db.snapshot()); | ||
163 | self.db | ||
164 | .library_roots() | ||
165 | .par_iter() | ||
166 | .map_with(snap, |db, &lib_id| db.0.library_symbols(lib_id)) | ||
167 | .collect() | ||
168 | } else { | ||
169 | let mut files = Vec::new(); | ||
170 | for &root in self.db.local_roots().iter() { | ||
171 | let sr = self.db.source_root(root); | ||
172 | files.extend(sr.files.values().map(|&it| it)) | ||
173 | } | ||
174 | |||
175 | let snap = Snap(self.db.snapshot()); | ||
176 | files | ||
177 | .par_iter() | ||
178 | .map_with(snap, |db, &file_id| db.0.file_symbols(file_id)) | ||
179 | .filter_map(|it| it.ok()) | ||
180 | .collect() | ||
181 | }; | ||
182 | Ok(query.search(&buf)) | ||
183 | } | ||
184 | |||
185 | pub(crate) fn module_path(&self, position: FilePosition) -> Cancelable<Option<String>> { | 151 | pub(crate) fn module_path(&self, position: FilePosition) -> Cancelable<Option<String>> { |
186 | let descr = match source_binder::module_from_position(&*self.db, position)? { | 152 | let descr = match source_binder::module_from_position(&*self.db, position)? { |
187 | None => return Ok(None), | 153 | None => return Ok(None), |
@@ -555,7 +521,7 @@ impl AnalysisImpl { | |||
555 | let mut query = Query::new(name.to_string()); | 521 | let mut query = Query::new(name.to_string()); |
556 | query.exact(); | 522 | query.exact(); |
557 | query.limit(4); | 523 | query.limit(4); |
558 | self.world_symbols(query) | 524 | crate::symbol_index::world_symbols(&*self.db, query) |
559 | } | 525 | } |
560 | } | 526 | } |
561 | 527 | ||
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 9576453ab..03550832e 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs | |||
@@ -342,9 +342,7 @@ impl Analysis { | |||
342 | ra_editor::folding_ranges(&file) | 342 | ra_editor::folding_ranges(&file) |
343 | } | 343 | } |
344 | pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<NavigationTarget>> { | 344 | pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<NavigationTarget>> { |
345 | let res = self | 345 | let res = symbol_index::world_symbols(&*self.imp.db, query)? |
346 | .imp | ||
347 | .world_symbols(query)? | ||
348 | .into_iter() | 346 | .into_iter() |
349 | .map(|(file_id, symbol)| NavigationTarget { file_id, symbol }) | 347 | .map(|(file_id, symbol)| NavigationTarget { file_id, symbol }) |
350 | .collect(); | 348 | .collect(); |
diff --git a/crates/ra_analysis/src/symbol_index.rs b/crates/ra_analysis/src/symbol_index.rs index 56a84a850..ddcf3d052 100644 --- a/crates/ra_analysis/src/symbol_index.rs +++ b/crates/ra_analysis/src/symbol_index.rs | |||
@@ -10,12 +10,13 @@ use ra_syntax::{ | |||
10 | SyntaxKind::{self, *}, | 10 | SyntaxKind::{self, *}, |
11 | ast::{self, NameOwner, DocCommentsOwner}, | 11 | ast::{self, NameOwner, DocCommentsOwner}, |
12 | }; | 12 | }; |
13 | use ra_db::{SyntaxDatabase, SourceRootId}; | 13 | use ra_db::{SyntaxDatabase, SourceRootId, FilesDatabase}; |
14 | use salsa::ParallelDatabase; | ||
14 | use rayon::prelude::*; | 15 | use rayon::prelude::*; |
15 | 16 | ||
16 | use crate::{ | 17 | use crate::{ |
17 | Cancelable, | 18 | Cancelable, FileId, Query, |
18 | FileId, Query, | 19 | db::RootDatabase, |
19 | }; | 20 | }; |
20 | 21 | ||
21 | salsa::query_group! { | 22 | salsa::query_group! { |
@@ -36,6 +37,41 @@ fn file_symbols(db: &impl SyntaxDatabase, file_id: FileId) -> Cancelable<Arc<Sym | |||
36 | Ok(Arc::new(SymbolIndex::for_file(file_id, syntax))) | 37 | Ok(Arc::new(SymbolIndex::for_file(file_id, syntax))) |
37 | } | 38 | } |
38 | 39 | ||
40 | pub(crate) fn world_symbols( | ||
41 | db: &RootDatabase, | ||
42 | query: Query, | ||
43 | ) -> Cancelable<Vec<(FileId, FileSymbol)>> { | ||
44 | /// Need to wrap Snapshot to provide `Clone` impl for `map_with` | ||
45 | struct Snap(salsa::Snapshot<RootDatabase>); | ||
46 | impl Clone for Snap { | ||
47 | fn clone(&self) -> Snap { | ||
48 | Snap(self.0.snapshot()) | ||
49 | } | ||
50 | } | ||
51 | |||
52 | let buf: Vec<Arc<SymbolIndex>> = if query.libs { | ||
53 | let snap = Snap(db.snapshot()); | ||
54 | db.library_roots() | ||
55 | .par_iter() | ||
56 | .map_with(snap, |db, &lib_id| db.0.library_symbols(lib_id)) | ||
57 | .collect() | ||
58 | } else { | ||
59 | let mut files = Vec::new(); | ||
60 | for &root in db.local_roots().iter() { | ||
61 | let sr = db.source_root(root); | ||
62 | files.extend(sr.files.values().map(|&it| it)) | ||
63 | } | ||
64 | |||
65 | let snap = Snap(db.snapshot()); | ||
66 | files | ||
67 | .par_iter() | ||
68 | .map_with(snap, |db, &file_id| db.0.file_symbols(file_id)) | ||
69 | .filter_map(|it| it.ok()) | ||
70 | .collect() | ||
71 | }; | ||
72 | Ok(query.search(&buf)) | ||
73 | } | ||
74 | |||
39 | #[derive(Default, Debug)] | 75 | #[derive(Default, Debug)] |
40 | pub(crate) struct SymbolIndex { | 76 | pub(crate) struct SymbolIndex { |
41 | symbols: Vec<(FileId, FileSymbol)>, | 77 | symbols: Vec<(FileId, FileSymbol)>, |