make more things cancelable

This commit is contained in:
Aleksey Kladov 2018-10-20 22:09:12 +03:00
parent 998f2ae762
commit 9fb41716de
3 changed files with 20 additions and 21 deletions

View file

@ -19,7 +19,7 @@ use rustc_hash::FxHashSet;
use crate::{
descriptors::{FnDescriptor, ModuleTreeDescriptor, Problem},
roots::{ReadonlySourceRoot, SourceRoot, WritableSourceRoot},
CrateGraph, CrateId, Diagnostic, FileId, FileResolver, FileSystemEdit, JobToken, Position,
CrateGraph, CrateId, Diagnostic, FileId, FileResolver, FileSystemEdit, Position,
Query, SourceChange, SourceFileEdit, Cancelable,
};

View file

@ -219,19 +219,23 @@ impl Analysis {
let file = self.imp.file_syntax(file_id);
ra_editor::file_structure(&file)
}
pub fn symbol_search(&self, query: Query) -> Vec<(FileId, FileSymbol)> {
self.imp.world_symbols(query)
pub fn folding_ranges(&self, file_id: FileId) -> Vec<Fold> {
let file = self.imp.file_syntax(file_id);
ra_editor::folding_ranges(&file)
}
pub fn symbol_search(&self, query: Query) -> Cancelable<Vec<(FileId, FileSymbol)>> {
Ok(self.imp.world_symbols(query))
}
pub fn approximately_resolve_symbol(
&self,
file_id: FileId,
offset: TextUnit
) -> Vec<(FileId, FileSymbol)> {
self.imp
.approximately_resolve_symbol(file_id, offset)
) -> Cancelable<Vec<(FileId, FileSymbol)>> {
Ok(self.imp
.approximately_resolve_symbol(file_id, offset))
}
pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit, ) -> Vec<(FileId, TextRange)> {
self.imp.find_all_refs(file_id, offset)
pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit, ) -> Cancelable<Vec<(FileId, TextRange)>> {
Ok(self.imp.find_all_refs(file_id, offset))
}
pub fn parent_module(&self, file_id: FileId) -> Cancelable<Vec<(FileId, FileSymbol)>> {
self.imp.parent_module(file_id)
@ -260,17 +264,12 @@ impl Analysis {
pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> {
Ok(self.imp.diagnostics(file_id))
}
pub fn folding_ranges(&self, file_id: FileId) -> Vec<Fold> {
let file = self.imp.file_syntax(file_id);
ra_editor::folding_ranges(&file)
}
pub fn resolve_callable(
&self,
file_id: FileId,
offset: TextUnit,
) -> Option<(FnDescriptor, Option<usize>)> {
self.imp.resolve_callable(file_id, offset)
) -> Cancelable<Option<(FnDescriptor, Option<usize>)>> {
Ok(self.imp.resolve_callable(file_id, offset))
}
}

View file

@ -195,7 +195,7 @@ pub fn handle_workspace_symbol(
query: Query,
) -> Result<Vec<SymbolInformation>> {
let mut res = Vec::new();
for (file_id, symbol) in world.analysis().symbol_search(query) {
for (file_id, symbol) in world.analysis().symbol_search(query)? {
let line_index = world.analysis().file_line_index(file_id);
let info = SymbolInformation {
name: symbol.name.to_string(),
@ -221,7 +221,7 @@ pub fn handle_goto_definition(
let mut res = Vec::new();
for (file_id, symbol) in world
.analysis()
.approximately_resolve_symbol(file_id, offset)
.approximately_resolve_symbol(file_id, offset)?
{
let line_index = world.analysis().file_line_index(file_id);
let location = to_location(file_id, symbol.node_range, &world, &line_index)?;
@ -435,7 +435,7 @@ pub fn handle_signature_help(
let offset = params.position.conv_with(&line_index);
if let Some((descriptor, active_param)) =
world.analysis().resolve_callable(file_id, offset)
world.analysis().resolve_callable(file_id, offset)?
{
let parameters: Vec<ParameterInformation> = descriptor
.params
@ -473,7 +473,7 @@ pub fn handle_prepare_rename(
// We support renaming references like handle_rename does.
// In the future we may want to reject the renaming of things like keywords here too.
let refs = world.analysis().find_all_refs(file_id, offset);
let refs = world.analysis().find_all_refs(file_id, offset)?;
if refs.is_empty() {
return Ok(None);
}
@ -497,7 +497,7 @@ pub fn handle_rename(
return Ok(None);
}
let refs = world.analysis().find_all_refs(file_id, offset);
let refs = world.analysis().find_all_refs(file_id, offset)?;
if refs.is_empty() {
return Ok(None);
}
@ -530,7 +530,7 @@ pub fn handle_references(
let line_index = world.analysis().file_line_index(file_id);
let offset = params.position.conv_with(&line_index);
let refs = world.analysis().find_all_refs(file_id, offset);
let refs = world.analysis().find_all_refs(file_id, offset)?;
Ok(Some(refs.into_iter()
.filter_map(|r| to_location(r.0, r.1, &world, &line_index).ok())