mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-01 15:01:51 +00:00
Better limiting
This commit is contained in:
parent
8ae56fa6d0
commit
5a56ac4b72
@ -94,12 +94,12 @@ impl World {
|
||||
Ok(index.clone())
|
||||
}
|
||||
|
||||
pub fn world_symbols<'a>(&'a self, query: Query) -> impl Iterator<Item=(&'a Path, &'a FileSymbol)> + 'a {
|
||||
pub fn world_symbols<'a>(&'a self, mut query: Query) -> impl Iterator<Item=(&'a Path, &'a FileSymbol)> + 'a {
|
||||
self.data.file_map.iter()
|
||||
.flat_map(move |(path, data)| {
|
||||
let path: &'a Path = path.as_path();
|
||||
let symbols = data.symbols(path);
|
||||
query.process(symbols).map(move |s| (path, s))
|
||||
let symbols = data.symbols();
|
||||
query.process(symbols).into_iter().map(move |s| (path, s))
|
||||
})
|
||||
}
|
||||
|
||||
@ -125,7 +125,8 @@ impl World {
|
||||
|
||||
let mut query = Query::new(name.to_string());
|
||||
query.exact();
|
||||
Ok(self.world_symbols(query).take(4).collect())
|
||||
query.limit(4);
|
||||
Ok(self.world_symbols(query).collect())
|
||||
}
|
||||
|
||||
fn file_data(&self, path: &Path) -> Result<Arc<FileData>> {
|
||||
@ -178,9 +179,14 @@ impl FileData {
|
||||
})
|
||||
}
|
||||
|
||||
fn symbols(&self, path: &Path) -> &FileSymbols {
|
||||
let syntax = self.syntax(path);
|
||||
fn syntax_transient(&self) -> ast::File {
|
||||
self.syntax.get().map(|s| s.clone())
|
||||
.unwrap_or_else(|| ast::File::parse(&self.text))
|
||||
}
|
||||
|
||||
fn symbols(&self) -> &FileSymbols {
|
||||
let syntax = self.syntax_transient();
|
||||
self.symbols
|
||||
.get_or_init(|| FileSymbols::new(syntax))
|
||||
.get_or_init(|| FileSymbols::new(&syntax))
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ pub struct Query {
|
||||
lowercased: String,
|
||||
only_types: bool,
|
||||
exact: bool,
|
||||
limit: usize,
|
||||
}
|
||||
|
||||
impl Query {
|
||||
@ -45,6 +46,7 @@ impl Query {
|
||||
lowercased,
|
||||
only_types: false,
|
||||
exact: false,
|
||||
limit: usize::max_value()
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,10 +58,14 @@ impl Query {
|
||||
self.exact = true;
|
||||
}
|
||||
|
||||
pub fn limit(&mut self, limit: usize) {
|
||||
self.limit = limit
|
||||
}
|
||||
|
||||
pub(crate) fn process<'a>(
|
||||
&self,
|
||||
&mut self,
|
||||
file: &'a FileSymbols,
|
||||
) -> impl Iterator<Item=&'a FileSymbol> + 'a {
|
||||
) -> Vec<&'a FileSymbol> {
|
||||
fn is_type(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
STRUCT | ENUM | TRAIT | TYPE_ITEM => true,
|
||||
@ -70,6 +76,9 @@ impl Query {
|
||||
let mut stream = file.map.search(automaton).into_stream();
|
||||
let mut res = Vec::new();
|
||||
while let Some((_, idx)) = stream.next() {
|
||||
if self.limit == 0 {
|
||||
break;
|
||||
}
|
||||
let idx = idx as usize;
|
||||
let symbol = &file.symbols[idx];
|
||||
if self.only_types && !is_type(symbol.kind) {
|
||||
@ -78,9 +87,10 @@ impl Query {
|
||||
if self.exact && symbol.name != self.query {
|
||||
continue;
|
||||
}
|
||||
res.push(symbol)
|
||||
res.push(symbol);
|
||||
self.limit -= 1;
|
||||
}
|
||||
res.into_iter()
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,10 +110,11 @@ pub fn handle_workspace_symbol(
|
||||
if !all_symbols {
|
||||
q.only_types();
|
||||
}
|
||||
q.limit(128);
|
||||
q
|
||||
};
|
||||
|
||||
for (path, symbol) in world.world_symbols(query).take(128) {
|
||||
for (path, symbol) in world.world_symbols(query) {
|
||||
let line_index = world.file_line_index(path)?;
|
||||
let info = SymbolInformation {
|
||||
name: symbol.name.to_string(),
|
||||
|
Loading…
Reference in New Issue
Block a user