diff options
Diffstat (limited to 'crates/ra_analysis/src/symbol_index.rs')
-rw-r--r-- | crates/ra_analysis/src/symbol_index.rs | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/crates/ra_analysis/src/symbol_index.rs b/crates/ra_analysis/src/symbol_index.rs index 54672fde4..51eef8170 100644 --- a/crates/ra_analysis/src/symbol_index.rs +++ b/crates/ra_analysis/src/symbol_index.rs | |||
@@ -1,15 +1,16 @@ | |||
1 | use std::{ | 1 | use crate::{FileId, JobToken, Query}; |
2 | sync::Arc, | 2 | use fst::{self, Streamer}; |
3 | hash::{Hash, Hasher}, | 3 | use ra_editor::{file_symbols, FileSymbol}; |
4 | }; | ||
5 | use ra_editor::{FileSymbol, file_symbols}; | ||
6 | use ra_syntax::{ | 4 | use ra_syntax::{ |
7 | File, | 5 | File, |
8 | SyntaxKind::{self, *}, | 6 | SyntaxKind::{self, *}, |
9 | }; | 7 | }; |
10 | use fst::{self, Streamer}; | ||
11 | use rayon::prelude::*; | 8 | use rayon::prelude::*; |
12 | use crate::{Query, FileId, JobToken}; | 9 | |
10 | use std::{ | ||
11 | hash::{Hash, Hasher}, | ||
12 | sync::Arc, | ||
13 | }; | ||
13 | 14 | ||
14 | #[derive(Debug)] | 15 | #[derive(Debug)] |
15 | pub(crate) struct SymbolIndex { | 16 | pub(crate) struct SymbolIndex { |
@@ -23,8 +24,7 @@ impl PartialEq for SymbolIndex { | |||
23 | } | 24 | } |
24 | } | 25 | } |
25 | 26 | ||
26 | impl Eq for SymbolIndex { | 27 | impl Eq for SymbolIndex {} |
27 | } | ||
28 | 28 | ||
29 | impl Hash for SymbolIndex { | 29 | impl Hash for SymbolIndex { |
30 | fn hash<H: Hasher>(&self, hasher: &mut H) { | 30 | fn hash<H: Hasher>(&self, hasher: &mut H) { |
@@ -33,14 +33,12 @@ impl Hash for SymbolIndex { | |||
33 | } | 33 | } |
34 | 34 | ||
35 | impl SymbolIndex { | 35 | impl SymbolIndex { |
36 | pub(crate) fn for_files(files: impl ParallelIterator<Item=(FileId, File)>) -> SymbolIndex { | 36 | pub(crate) fn for_files(files: impl ParallelIterator<Item = (FileId, File)>) -> SymbolIndex { |
37 | let mut symbols = files | 37 | let mut symbols = files |
38 | .flat_map(|(file_id, file)| { | 38 | .flat_map(|(file_id, file)| { |
39 | file_symbols(&file) | 39 | file_symbols(&file) |
40 | .into_iter() | 40 | .into_iter() |
41 | .map(move |symbol| { | 41 | .map(move |symbol| (symbol.name.as_str().to_lowercase(), (file_id, symbol))) |
42 | (symbol.name.as_str().to_lowercase(), (file_id, symbol)) | ||
43 | }) | ||
44 | .collect::<Vec<_>>() | 42 | .collect::<Vec<_>>() |
45 | }) | 43 | }) |
46 | .collect::<Vec<_>>(); | 44 | .collect::<Vec<_>>(); |
@@ -48,9 +46,7 @@ impl SymbolIndex { | |||
48 | symbols.dedup_by(|s1, s2| s1.0 == s2.0); | 46 | symbols.dedup_by(|s1, s2| s1.0 == s2.0); |
49 | let (names, symbols): (Vec<String>, Vec<(FileId, FileSymbol)>) = | 47 | let (names, symbols): (Vec<String>, Vec<(FileId, FileSymbol)>) = |
50 | symbols.into_iter().unzip(); | 48 | symbols.into_iter().unzip(); |
51 | let map = fst::Map::from_iter( | 49 | let map = fst::Map::from_iter(names.into_iter().zip(0u64..)).unwrap(); |
52 | names.into_iter().zip(0u64..) | ||
53 | ).unwrap(); | ||
54 | SymbolIndex { symbols, map } | 50 | SymbolIndex { symbols, map } |
55 | } | 51 | } |
56 | 52 | ||
@@ -65,7 +61,6 @@ impl Query { | |||
65 | indices: &[Arc<SymbolIndex>], | 61 | indices: &[Arc<SymbolIndex>], |
66 | token: &JobToken, | 62 | token: &JobToken, |
67 | ) -> Vec<(FileId, FileSymbol)> { | 63 | ) -> Vec<(FileId, FileSymbol)> { |
68 | |||
69 | let mut op = fst::map::OpBuilder::new(); | 64 | let mut op = fst::map::OpBuilder::new(); |
70 | for file_symbols in indices.iter() { | 65 | for file_symbols in indices.iter() { |
71 | let automaton = fst::automaton::Subsequence::new(&self.lowercased); | 66 | let automaton = fst::automaton::Subsequence::new(&self.lowercased); |