aboutsummaryrefslogtreecommitdiff
path: root/crates/libanalysis/src/symbol_index.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/libanalysis/src/symbol_index.rs')
-rw-r--r--crates/libanalysis/src/symbol_index.rs28
1 files changed, 12 insertions, 16 deletions
diff --git a/crates/libanalysis/src/symbol_index.rs b/crates/libanalysis/src/symbol_index.rs
index 1878fae99..4d90aac0c 100644
--- a/crates/libanalysis/src/symbol_index.rs
+++ b/crates/libanalysis/src/symbol_index.rs
@@ -5,8 +5,6 @@ use libsyntax2::{
5}; 5};
6use fst::{self, IntoStreamer}; 6use fst::{self, IntoStreamer};
7 7
8use Search;
9
10#[derive(Debug)] 8#[derive(Debug)]
11pub(crate) struct FileSymbols { 9pub(crate) struct FileSymbols {
12 symbols: Vec<FileSymbol>, 10 symbols: Vec<FileSymbol>,
@@ -47,11 +45,10 @@ impl Query {
47 Query { query, all_symbols } 45 Query { query, all_symbols }
48 } 46 }
49 47
50 pub(crate) fn process( 48 pub(crate) fn process<'a>(
51 &self, 49 &self,
52 file: &FileSymbols, 50 file: &'a FileSymbols,
53 acc: &mut FnMut(&FileSymbol) -> Search, 51 ) -> impl Iterator<Item=&'a FileSymbol> + 'a {
54 ) -> Search {
55 fn is_type(kind: SyntaxKind) -> bool { 52 fn is_type(kind: SyntaxKind) -> bool {
56 match kind { 53 match kind {
57 STRUCT | ENUM | TRAIT | TYPE_ITEM => true, 54 STRUCT | ENUM | TRAIT | TYPE_ITEM => true,
@@ -59,16 +56,15 @@ impl Query {
59 } 56 }
60 } 57 }
61 let automaton = fst::automaton::Subsequence::new(&self.query); 58 let automaton = fst::automaton::Subsequence::new(&self.query);
62 for idx in file.map.search(automaton).into_stream().into_values() { 59 let all_symbols = self.all_symbols;
63 let idx = idx as usize; 60 file.map.search(automaton).into_stream()
64 let symbol = &file.symbols[idx]; 61 .into_values()
65 if self.all_symbols || is_type(symbol.kind) { 62 .into_iter()
66 if acc(&symbol) == Search::Break { 63 .map(move |idx| {
67 return Search::Break; 64 let idx = idx as usize;
68 } 65 &file.symbols[idx]
69 } 66 })
70 } 67 .filter(move |s| all_symbols || is_type(s.kind))
71 Search::Continue
72 } 68 }
73} 69}
74 70