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::{ use crate::{
descriptors::{FnDescriptor, ModuleTreeDescriptor, Problem}, descriptors::{FnDescriptor, ModuleTreeDescriptor, Problem},
roots::{ReadonlySourceRoot, SourceRoot, WritableSourceRoot}, roots::{ReadonlySourceRoot, SourceRoot, WritableSourceRoot},
CrateGraph, CrateId, Diagnostic, FileId, FileResolver, FileSystemEdit, JobToken, Position, CrateGraph, CrateId, Diagnostic, FileId, FileResolver, FileSystemEdit, Position,
Query, SourceChange, SourceFileEdit, Cancelable, Query, SourceChange, SourceFileEdit, Cancelable,
}; };

View File

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

View File

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