diff options
Diffstat (limited to 'crates/libanalysis/src/symbol_index.rs')
-rw-r--r-- | crates/libanalysis/src/symbol_index.rs | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/crates/libanalysis/src/symbol_index.rs b/crates/libanalysis/src/symbol_index.rs index 54952cb94..8fef326ab 100644 --- a/crates/libanalysis/src/symbol_index.rs +++ b/crates/libanalysis/src/symbol_index.rs | |||
@@ -4,39 +4,46 @@ use libsyntax2::{ | |||
4 | SyntaxKind::{self, *}, | 4 | SyntaxKind::{self, *}, |
5 | }; | 5 | }; |
6 | use fst::{self, Streamer}; | 6 | use fst::{self, Streamer}; |
7 | use rayon::prelude::*; | ||
7 | use {Query, FileId, JobToken}; | 8 | use {Query, FileId, JobToken}; |
8 | 9 | ||
9 | #[derive(Debug)] | 10 | #[derive(Debug)] |
10 | pub(crate) struct FileSymbols { | 11 | pub(crate) struct SymbolIndex { |
11 | symbols: Vec<(FileId, FileSymbol)>, | 12 | symbols: Vec<(FileId, FileSymbol)>, |
12 | map: fst::Map, | 13 | map: fst::Map, |
13 | } | 14 | } |
14 | 15 | ||
15 | impl FileSymbols { | 16 | impl SymbolIndex { |
16 | pub(crate) fn new(file_id: FileId, file: &File) -> FileSymbols { | 17 | pub(crate) fn for_files(files: impl ParallelIterator<Item=(FileId, File)>) -> SymbolIndex { |
17 | let mut symbols = file_symbols(file) | 18 | let mut symbols = files |
18 | .into_iter() | 19 | .flat_map(|(file_id, file)| { |
19 | .map(|s| (s.name.as_str().to_lowercase(), s)) | 20 | file_symbols(&file) |
21 | .into_iter() | ||
22 | .map(move |symbol| { | ||
23 | (symbol.name.as_str().to_lowercase(), (file_id, symbol)) | ||
24 | }) | ||
25 | .collect::<Vec<_>>() | ||
26 | }) | ||
20 | .collect::<Vec<_>>(); | 27 | .collect::<Vec<_>>(); |
21 | 28 | symbols.par_sort_by(|s1, s2| s1.0.cmp(&s2.0)); | |
22 | symbols.sort_by(|s1, s2| s1.0.cmp(&s2.0)); | ||
23 | symbols.dedup_by(|s1, s2| s1.0 == s2.0); | 29 | symbols.dedup_by(|s1, s2| s1.0 == s2.0); |
24 | let (names, symbols): (Vec<String>, Vec<(FileId, FileSymbol)>) = | 30 | let (names, symbols): (Vec<String>, Vec<(FileId, FileSymbol)>) = |
25 | symbols.into_iter() | 31 | symbols.into_iter().unzip(); |
26 | .map(|(name, symbol)| (name, (file_id, symbol))) | ||
27 | .unzip(); | ||
28 | |||
29 | let map = fst::Map::from_iter( | 32 | let map = fst::Map::from_iter( |
30 | names.into_iter().zip(0u64..) | 33 | names.into_iter().zip(0u64..) |
31 | ).unwrap(); | 34 | ).unwrap(); |
32 | FileSymbols { symbols, map } | 35 | SymbolIndex { symbols, map } |
36 | } | ||
37 | |||
38 | pub(crate) fn for_file(file_id: FileId, file: File) -> SymbolIndex { | ||
39 | SymbolIndex::for_files(::rayon::iter::once((file_id, file))) | ||
33 | } | 40 | } |
34 | } | 41 | } |
35 | 42 | ||
36 | impl Query { | 43 | impl Query { |
37 | pub(crate) fn search( | 44 | pub(crate) fn search( |
38 | mut self, | 45 | mut self, |
39 | indices: &[&FileSymbols], | 46 | indices: &[&SymbolIndex], |
40 | token: &JobToken, | 47 | token: &JobToken, |
41 | ) -> Vec<(FileId, FileSymbol)> { | 48 | ) -> Vec<(FileId, FileSymbol)> { |
42 | 49 | ||