aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/symbol_index.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-02 16:42:29 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-02 16:42:29 +0000
commit4f30c459336e948790910e268d8f751b95815ac2 (patch)
tree5dbfb4e045d6b50ebee447cdaa36aad995089c8c /crates/ra_analysis/src/symbol_index.rs
parente6aadf6ef21a25a6dae55f39bc774b5a0ef2ad6c (diff)
parentef08b6c084fc2676655fe6dfb693ab097d3f9fd9 (diff)
Merge #406
406: Simplify r=matklad a=matklad Get rid of `AnalysisImpl` wrapper around salsa database. It was useful before we migrated by salsa, but it's long have been just a useless boilerplate. Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_analysis/src/symbol_index.rs')
-rw-r--r--crates/ra_analysis/src/symbol_index.rs42
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};
13use ra_db::{SyntaxDatabase, SourceRootId}; 13use ra_db::{SyntaxDatabase, SourceRootId, FilesDatabase};
14use salsa::ParallelDatabase;
14use rayon::prelude::*; 15use rayon::prelude::*;
15 16
16use crate::{ 17use crate::{
17 Cancelable, 18 Cancelable, FileId, Query,
18 FileId, Query, 19 db::RootDatabase,
19}; 20};
20 21
21salsa::query_group! { 22salsa::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
40pub(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)]
40pub(crate) struct SymbolIndex { 76pub(crate) struct SymbolIndex {
41 symbols: Vec<(FileId, FileSymbol)>, 77 symbols: Vec<(FileId, FileSymbol)>,