aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src/symbol_index.rs
diff options
context:
space:
mode:
authorJeremy A. Kolb <[email protected]>2018-10-15 22:44:23 +0100
committerJeremy A. Kolb <[email protected]>2018-10-16 14:41:10 +0100
commit61f3a438d3a729a6be941bca1ff4c6a97a33f221 (patch)
tree6551967cc8c6e921b66071453ad7888a9121d326 /crates/ra_analysis/src/symbol_index.rs
parent39cb6c6d3f78b193f5873c3492e530bbd24d5dd2 (diff)
Cargo Format
Run `cargo fmt` and ignore generated files
Diffstat (limited to 'crates/ra_analysis/src/symbol_index.rs')
-rw-r--r--crates/ra_analysis/src/symbol_index.rs29
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 @@
1use std::{ 1use crate::{FileId, JobToken, Query};
2 sync::Arc, 2use fst::{self, Streamer};
3 hash::{Hash, Hasher}, 3use ra_editor::{file_symbols, FileSymbol};
4};
5use ra_editor::{FileSymbol, file_symbols};
6use ra_syntax::{ 4use ra_syntax::{
7 File, 5 File,
8 SyntaxKind::{self, *}, 6 SyntaxKind::{self, *},
9}; 7};
10use fst::{self, Streamer};
11use rayon::prelude::*; 8use rayon::prelude::*;
12use crate::{Query, FileId, JobToken}; 9
10use std::{
11 hash::{Hash, Hasher},
12 sync::Arc,
13};
13 14
14#[derive(Debug)] 15#[derive(Debug)]
15pub(crate) struct SymbolIndex { 16pub(crate) struct SymbolIndex {
@@ -23,8 +24,7 @@ impl PartialEq for SymbolIndex {
23 } 24 }
24} 25}
25 26
26impl Eq for SymbolIndex { 27impl Eq for SymbolIndex {}
27}
28 28
29impl Hash for SymbolIndex { 29impl 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
35impl SymbolIndex { 35impl 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);