mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +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());
|
let name_ref = ctry!(calling_node.name_ref());
|
||||||
|
|
||||||
// Resolve the function's NameRef (NOTE: this isn't entirely accurate).
|
// 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 symbol = ctry!(file_symbols.into_iter().find(|it| it.ptr.kind() == FN_DEF));
|
||||||
let fn_file = db.source_file(symbol.file_id);
|
let fn_file = db.source_file(symbol.file_id);
|
||||||
let fn_def = symbol.ptr.resolve(&fn_file);
|
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.
|
// If that fails try the index based approach.
|
||||||
let navs = db
|
let navs = db
|
||||||
.index_resolve(name_ref)?
|
.index_resolve(name_ref)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(NavigationTarget::from_symbol)
|
.map(NavigationTarget::from_symbol)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
|
@ -258,7 +258,7 @@ impl db::RootDatabase {
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
Ok(res)
|
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 name = name_ref.text();
|
||||||
let mut query = Query::new(name.to_string());
|
let mut query = Query::new(name.to_string());
|
||||||
query.exact();
|
query.exact();
|
||||||
|
|
|
@ -381,12 +381,11 @@ impl Analysis {
|
||||||
/// Fuzzy searches for a symbol.
|
/// Fuzzy searches for a symbol.
|
||||||
pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<NavigationTarget>> {
|
pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<NavigationTarget>> {
|
||||||
self.with_db(|db| {
|
self.with_db(|db| {
|
||||||
let res = symbol_index::world_symbols(db, query)?
|
symbol_index::world_symbols(db, query)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(NavigationTarget::from_symbol)
|
.map(NavigationTarget::from_symbol)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>()
|
||||||
Ok(res)
|
})
|
||||||
})?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn goto_definition(
|
pub fn goto_definition(
|
||||||
|
|
|
@ -37,13 +37,13 @@ use salsa::ParallelDatabase;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Cancelable, FileId, Query,
|
FileId, Query,
|
||||||
db::RootDatabase,
|
db::RootDatabase,
|
||||||
};
|
};
|
||||||
|
|
||||||
salsa::query_group! {
|
salsa::query_group! {
|
||||||
pub(crate) trait SymbolsDatabase: hir::db::HirDatabase {
|
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;
|
type FileSymbolsQuery;
|
||||||
}
|
}
|
||||||
fn library_symbols(id: SourceRootId) -> Arc<SymbolIndex> {
|
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();
|
db.check_canceled();
|
||||||
let source_file = db.source_file(file_id);
|
let source_file = db.source_file(file_id);
|
||||||
let mut symbols = source_file
|
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 })
|
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`
|
/// Need to wrap Snapshot to provide `Clone` impl for `map_with`
|
||||||
struct Snap(salsa::Snapshot<RootDatabase>);
|
struct Snap(salsa::Snapshot<RootDatabase>);
|
||||||
impl Clone for Snap {
|
impl Clone for Snap {
|
||||||
|
@ -98,10 +98,9 @@ pub(crate) fn world_symbols(db: &RootDatabase, query: Query) -> Cancelable<Vec<F
|
||||||
files
|
files
|
||||||
.par_iter()
|
.par_iter()
|
||||||
.map_with(snap, |db, &file_id| db.0.file_symbols(file_id))
|
.map_with(snap, |db, &file_id| db.0.file_symbols(file_id))
|
||||||
.filter_map(|it| it.ok())
|
|
||||||
.collect()
|
.collect()
|
||||||
};
|
};
|
||||||
Ok(query.search(&buf))
|
query.search(&buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue