diff options
Diffstat (limited to 'crates/ra_analysis/src/symbol_index.rs')
-rw-r--r-- | crates/ra_analysis/src/symbol_index.rs | 42 |
1 files changed, 39 insertions, 3 deletions
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)>, |