aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_ide_db/src/symbol_index.rs43
1 files changed, 34 insertions, 9 deletions
diff --git a/crates/ra_ide_db/src/symbol_index.rs b/crates/ra_ide_db/src/symbol_index.rs
index 78c714356..c974891ea 100644
--- a/crates/ra_ide_db/src/symbol_index.rs
+++ b/crates/ra_ide_db/src/symbol_index.rs
@@ -29,9 +29,10 @@ use std::{
29}; 29};
30 30
31use fst::{self, Streamer}; 31use fst::{self, Streamer};
32use hir::db::DefDatabase;
32use ra_db::{ 33use ra_db::{
33 salsa::{self, ParallelDatabase}, 34 salsa::{self, ParallelDatabase},
34 FileId, SourceDatabaseExt, SourceRootId, 35 CrateId, FileId, SourceDatabaseExt, SourceRootId,
35}; 36};
36use ra_syntax::{ 37use ra_syntax::{
37 ast::{self, NameOwner}, 38 ast::{self, NameOwner},
@@ -110,6 +111,14 @@ fn file_symbols(db: &impl SymbolsDatabase, file_id: FileId) -> Arc<SymbolIndex>
110 Arc::new(SymbolIndex::new(symbols)) 111 Arc::new(SymbolIndex::new(symbols))
111} 112}
112 113
114/// Need to wrap Snapshot to provide `Clone` impl for `map_with`
115struct Snap(salsa::Snapshot<RootDatabase>);
116impl Clone for Snap {
117 fn clone(&self) -> Snap {
118 Snap(self.0.snapshot())
119 }
120}
121
113// Feature: Workspace Symbol 122// Feature: Workspace Symbol
114// 123//
115// Uses fuzzy-search to find types, modules and functions by name across your 124// Uses fuzzy-search to find types, modules and functions by name across your
@@ -134,14 +143,6 @@ fn file_symbols(db: &impl SymbolsDatabase, file_id: FileId) -> Arc<SymbolIndex>
134pub fn world_symbols(db: &RootDatabase, query: Query) -> Vec<FileSymbol> { 143pub fn world_symbols(db: &RootDatabase, query: Query) -> Vec<FileSymbol> {
135 let _p = ra_prof::profile("world_symbols").detail(|| query.query.clone()); 144 let _p = ra_prof::profile("world_symbols").detail(|| query.query.clone());
136 145
137 /// Need to wrap Snapshot to provide `Clone` impl for `map_with`
138 struct Snap(salsa::Snapshot<RootDatabase>);
139 impl Clone for Snap {
140 fn clone(&self) -> Snap {
141 Snap(self.0.snapshot())
142 }
143 }
144
145 let buf: Vec<Arc<SymbolIndex>> = if query.libs { 146 let buf: Vec<Arc<SymbolIndex>> = if query.libs {
146 let snap = Snap(db.snapshot()); 147 let snap = Snap(db.snapshot());
147 #[cfg(not(feature = "wasm"))] 148 #[cfg(not(feature = "wasm"))]
@@ -175,6 +176,30 @@ pub fn world_symbols(db: &RootDatabase, query: Query) -> Vec<FileSymbol> {
175 query.search(&buf) 176 query.search(&buf)
176} 177}
177 178
179pub fn crate_symbols(db: &RootDatabase, krate: CrateId, query: Query) -> Vec<FileSymbol> {
180 let def_map = db.crate_def_map(krate);
181 let mut files = Vec::new();
182 let mut modules = vec![def_map.root];
183 while let Some(module) = modules.pop() {
184 let data = &def_map[module];
185 files.extend(data.origin.file_id());
186 modules.extend(data.children.values());
187 }
188
189 let snap = Snap(db.snapshot());
190
191 #[cfg(not(feature = "wasm"))]
192 let buf = files
193 .par_iter()
194 .map_with(snap, |db, &file_id| db.0.file_symbols(file_id))
195 .collect::<Vec<_>>();
196
197 #[cfg(feature = "wasm")]
198 let buf = files.iter().map(|&file_id| snap.0.file_symbols(file_id)).collect::<Vec<_>>();
199
200 query.search(&buf)
201}
202
178pub fn index_resolve(db: &RootDatabase, name_ref: &ast::NameRef) -> Vec<FileSymbol> { 203pub fn index_resolve(db: &RootDatabase, name_ref: &ast::NameRef) -> Vec<FileSymbol> {
179 let name = name_ref.text(); 204 let name = name_ref.text();
180 let mut query = Query::new(name.to_string()); 205 let mut query = Query::new(name.to_string());