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.rs18
1 files changed, 14 insertions, 4 deletions
diff --git a/crates/libanalysis/src/symbol_index.rs b/crates/libanalysis/src/symbol_index.rs
index 88d5c4995..a7ae197e0 100644
--- a/crates/libanalysis/src/symbol_index.rs
+++ b/crates/libanalysis/src/symbol_index.rs
@@ -35,6 +35,7 @@ pub struct Query {
35 lowercased: String, 35 lowercased: String,
36 only_types: bool, 36 only_types: bool,
37 exact: bool, 37 exact: bool,
38 limit: usize,
38} 39}
39 40
40impl Query { 41impl Query {
@@ -45,6 +46,7 @@ impl Query {
45 lowercased, 46 lowercased,
46 only_types: false, 47 only_types: false,
47 exact: false, 48 exact: false,
49 limit: usize::max_value()
48 } 50 }
49 } 51 }
50 52
@@ -56,10 +58,14 @@ impl Query {
56 self.exact = true; 58 self.exact = true;
57 } 59 }
58 60
61 pub fn limit(&mut self, limit: usize) {
62 self.limit = limit
63 }
64
59 pub(crate) fn process<'a>( 65 pub(crate) fn process<'a>(
60 &self, 66 &mut self,
61 file: &'a FileSymbols, 67 file: &'a FileSymbols,
62 ) -> impl Iterator<Item=&'a FileSymbol> + 'a { 68 ) -> Vec<&'a FileSymbol> {
63 fn is_type(kind: SyntaxKind) -> bool { 69 fn is_type(kind: SyntaxKind) -> bool {
64 match kind { 70 match kind {
65 STRUCT | ENUM | TRAIT | TYPE_ITEM => true, 71 STRUCT | ENUM | TRAIT | TYPE_ITEM => true,
@@ -70,6 +76,9 @@ impl Query {
70 let mut stream = file.map.search(automaton).into_stream(); 76 let mut stream = file.map.search(automaton).into_stream();
71 let mut res = Vec::new(); 77 let mut res = Vec::new();
72 while let Some((_, idx)) = stream.next() { 78 while let Some((_, idx)) = stream.next() {
79 if self.limit == 0 {
80 break;
81 }
73 let idx = idx as usize; 82 let idx = idx as usize;
74 let symbol = &file.symbols[idx]; 83 let symbol = &file.symbols[idx];
75 if self.only_types && !is_type(symbol.kind) { 84 if self.only_types && !is_type(symbol.kind) {
@@ -78,9 +87,10 @@ impl Query {
78 if self.exact && symbol.name != self.query { 87 if self.exact && symbol.name != self.query {
79 continue; 88 continue;
80 } 89 }
81 res.push(symbol) 90 res.push(symbol);
91 self.limit -= 1;
82 } 92 }
83 res.into_iter() 93 res
84 } 94 }
85} 95}
86 96