mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 09:27:27 +00:00
remove cancelable from symbols
This commit is contained in:
parent
11f3c8afb2
commit
fb012e5c1e
5 changed files with 12 additions and 14 deletions
|
@ -20,7 +20,7 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Cancelable
|
|||
let name_ref = ctry!(calling_node.name_ref());
|
||||
|
||||
// Resolve the function's NameRef (NOTE: this isn't entirely accurate).
|
||||
let file_symbols = db.index_resolve(name_ref)?;
|
||||
let file_symbols = db.index_resolve(name_ref);
|
||||
let symbol = ctry!(file_symbols.into_iter().find(|it| it.ptr.kind() == FN_DEF));
|
||||
let fn_file = db.source_file(symbol.file_id);
|
||||
let fn_def = symbol.ptr.resolve(&fn_file);
|
||||
|
|
|
@ -95,7 +95,7 @@ pub(crate) fn reference_definition(
|
|||
}
|
||||
// If that fails try the index based approach.
|
||||
let navs = db
|
||||
.index_resolve(name_ref)?
|
||||
.index_resolve(name_ref)
|
||||
.into_iter()
|
||||
.map(NavigationTarget::from_symbol)
|
||||
.collect();
|
||||
|
|
|
@ -258,7 +258,7 @@ impl db::RootDatabase {
|
|||
.collect::<Vec<_>>();
|
||||
Ok(res)
|
||||
}
|
||||
pub(crate) fn index_resolve(&self, name_ref: &ast::NameRef) -> Cancelable<Vec<FileSymbol>> {
|
||||
pub(crate) fn index_resolve(&self, name_ref: &ast::NameRef) -> Vec<FileSymbol> {
|
||||
let name = name_ref.text();
|
||||
let mut query = Query::new(name.to_string());
|
||||
query.exact();
|
||||
|
|
|
@ -381,12 +381,11 @@ impl Analysis {
|
|||
/// Fuzzy searches for a symbol.
|
||||
pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<NavigationTarget>> {
|
||||
self.with_db(|db| {
|
||||
let res = symbol_index::world_symbols(db, query)?
|
||||
symbol_index::world_symbols(db, query)
|
||||
.into_iter()
|
||||
.map(NavigationTarget::from_symbol)
|
||||
.collect::<Vec<_>>();
|
||||
Ok(res)
|
||||
})?
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn goto_definition(
|
||||
|
|
|
@ -37,13 +37,13 @@ use salsa::ParallelDatabase;
|
|||
use rayon::prelude::*;
|
||||
|
||||
use crate::{
|
||||
Cancelable, FileId, Query,
|
||||
FileId, Query,
|
||||
db::RootDatabase,
|
||||
};
|
||||
|
||||
salsa::query_group! {
|
||||
pub(crate) trait SymbolsDatabase: hir::db::HirDatabase {
|
||||
fn file_symbols(file_id: FileId) -> Cancelable<Arc<SymbolIndex>> {
|
||||
fn file_symbols(file_id: FileId) -> Arc<SymbolIndex> {
|
||||
type FileSymbolsQuery;
|
||||
}
|
||||
fn library_symbols(id: SourceRootId) -> Arc<SymbolIndex> {
|
||||
|
@ -53,7 +53,7 @@ salsa::query_group! {
|
|||
}
|
||||
}
|
||||
|
||||
fn file_symbols(db: &impl SymbolsDatabase, file_id: FileId) -> Cancelable<Arc<SymbolIndex>> {
|
||||
fn file_symbols(db: &impl SymbolsDatabase, file_id: FileId) -> Arc<SymbolIndex> {
|
||||
db.check_canceled();
|
||||
let source_file = db.source_file(file_id);
|
||||
let mut symbols = source_file
|
||||
|
@ -69,10 +69,10 @@ fn file_symbols(db: &impl SymbolsDatabase, file_id: FileId) -> Cancelable<Arc<Sy
|
|||
symbols.push(FileSymbol { file_id, name, ptr })
|
||||
}
|
||||
|
||||
Ok(Arc::new(SymbolIndex::new(symbols)))
|
||||
Arc::new(SymbolIndex::new(symbols))
|
||||
}
|
||||
|
||||
pub(crate) fn world_symbols(db: &RootDatabase, query: Query) -> Cancelable<Vec<FileSymbol>> {
|
||||
pub(crate) fn world_symbols(db: &RootDatabase, query: Query) -> Vec<FileSymbol> {
|
||||
/// Need to wrap Snapshot to provide `Clone` impl for `map_with`
|
||||
struct Snap(salsa::Snapshot<RootDatabase>);
|
||||
impl Clone for Snap {
|
||||
|
@ -98,10 +98,9 @@ pub(crate) fn world_symbols(db: &RootDatabase, query: Query) -> Cancelable<Vec<F
|
|||
files
|
||||
.par_iter()
|
||||
.map_with(snap, |db, &file_id| db.0.file_symbols(file_id))
|
||||
.filter_map(|it| it.ok())
|
||||
.collect()
|
||||
};
|
||||
Ok(query.search(&buf))
|
||||
query.search(&buf)
|
||||
}
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
|
|
Loading…
Reference in a new issue