remove job tokens

This commit is contained in:
Aleksey Kladov 2018-10-20 22:02:41 +03:00
parent c4b0d3cd56
commit 998f2ae762
4 changed files with 61 additions and 66 deletions

View File

@ -148,14 +148,14 @@ impl AnalysisImpl {
pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> {
self.root(file_id).lines(file_id)
}
pub fn world_symbols(&self, query: Query, token: &JobToken) -> Vec<(FileId, FileSymbol)> {
pub fn world_symbols(&self, query: Query) -> Vec<(FileId, FileSymbol)> {
let mut buf = Vec::new();
if query.libs {
self.data.libs.iter().for_each(|it| it.symbols(&mut buf));
} else {
self.data.root.symbols(&mut buf);
}
query.search(&buf, token)
query.search(&buf)
}
pub fn parent_module(&self, file_id: FileId) -> Cancelable<Vec<(FileId, FileSymbol)>> {
let root = self.root(file_id);
@ -205,7 +205,6 @@ impl AnalysisImpl {
&self,
file_id: FileId,
offset: TextUnit,
token: &JobToken,
) -> Vec<(FileId, FileSymbol)> {
let root = self.root(file_id);
let module_tree = root.module_tree();
@ -227,7 +226,7 @@ impl AnalysisImpl {
return vec;
} else {
// If that fails try the index based approach.
return self.index_resolve(name_ref, token);
return self.index_resolve(name_ref);
}
}
if let Some(name) = find_node_at_offset::<ast::Name>(syntax, offset) {
@ -258,7 +257,7 @@ impl AnalysisImpl {
vec![]
}
pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit, _token: &JobToken) -> Vec<(FileId, TextRange)> {
pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit) -> Vec<(FileId, TextRange)> {
let root = self.root(file_id);
let file = root.syntax(file_id);
let syntax = file.syntax();
@ -380,7 +379,6 @@ impl AnalysisImpl {
&self,
file_id: FileId,
offset: TextUnit,
token: &JobToken,
) -> Option<(FnDescriptor, Option<usize>)> {
let root = self.root(file_id);
let file = root.syntax(file_id);
@ -391,7 +389,7 @@ impl AnalysisImpl {
let name_ref = calling_node.name_ref()?;
// Resolve the function's NameRef (NOTE: this isn't entirely accurate).
let file_symbols = self.index_resolve(name_ref, token);
let file_symbols = self.index_resolve(name_ref);
for (_, fs) in file_symbols {
if fs.kind == FN_DEF {
if let Some(fn_def) = find_node_at_offset(syntax, fs.node_range.start()) {
@ -442,12 +440,12 @@ impl AnalysisImpl {
None
}
fn index_resolve(&self, name_ref: ast::NameRef, token: &JobToken) -> Vec<(FileId, FileSymbol)> {
fn index_resolve(&self, name_ref: ast::NameRef) -> Vec<(FileId, FileSymbol)> {
let name = name_ref.text();
let mut query = Query::new(name.to_string());
query.exact();
query.limit(4);
self.world_symbols(query, token)
self.world_symbols(query)
}
fn resolve_module(

View File

@ -219,47 +219,46 @@ impl Analysis {
let file = self.imp.file_syntax(file_id);
ra_editor::file_structure(&file)
}
pub fn symbol_search(&self, query: Query, token: &JobToken) -> Vec<(FileId, FileSymbol)> {
self.imp.world_symbols(query, token)
pub fn symbol_search(&self, query: Query) -> Vec<(FileId, FileSymbol)> {
self.imp.world_symbols(query)
}
pub fn approximately_resolve_symbol(
&self,
file_id: FileId,
offset: TextUnit,
token: &JobToken,
offset: TextUnit
) -> Vec<(FileId, FileSymbol)> {
self.imp
.approximately_resolve_symbol(file_id, offset, token)
.approximately_resolve_symbol(file_id, offset)
}
pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit, token: &JobToken) -> Vec<(FileId, TextRange)> {
self.imp.find_all_refs(file_id, offset, token)
pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit, ) -> Vec<(FileId, TextRange)> {
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)
}
pub fn crate_for(&self, file_id: FileId) -> Vec<CrateId> {
self.imp.crate_for(file_id)
pub fn crate_for(&self, file_id: FileId) -> Cancelable<Vec<CrateId>> {
Ok(self.imp.crate_for(file_id))
}
pub fn crate_root(&self, crate_id: CrateId) -> FileId {
self.imp.crate_root(crate_id)
pub fn crate_root(&self, crate_id: CrateId) -> Cancelable<FileId> {
Ok(self.imp.crate_root(crate_id))
}
pub fn runnables(&self, file_id: FileId) -> Vec<Runnable> {
pub fn runnables(&self, file_id: FileId) -> Cancelable<Vec<Runnable>> {
let file = self.imp.file_syntax(file_id);
ra_editor::runnables(&file)
Ok(ra_editor::runnables(&file))
}
pub fn highlight(&self, file_id: FileId) -> Vec<HighlightedRange> {
pub fn highlight(&self, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> {
let file = self.imp.file_syntax(file_id);
ra_editor::highlight(&file)
Ok(ra_editor::highlight(&file))
}
pub fn completions(&self, file_id: FileId, offset: TextUnit) -> Option<Vec<CompletionItem>> {
pub fn completions(&self, file_id: FileId, offset: TextUnit) -> Cancelable<Option<Vec<CompletionItem>>> {
let file = self.imp.file_syntax(file_id);
ra_editor::scope_completion(&file, offset)
Ok(ra_editor::scope_completion(&file, offset))
}
pub fn assists(&self, file_id: FileId, range: TextRange) -> Vec<SourceChange> {
self.imp.assists(file_id, range)
pub fn assists(&self, file_id: FileId, range: TextRange) -> Cancelable<Vec<SourceChange>> {
Ok(self.imp.assists(file_id, range))
}
pub fn diagnostics(&self, file_id: FileId) -> Vec<Diagnostic> {
self.imp.diagnostics(file_id)
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);
@ -270,9 +269,8 @@ impl Analysis {
&self,
file_id: FileId,
offset: TextUnit,
token: &JobToken,
) -> Option<(FnDescriptor, Option<usize>)> {
self.imp.resolve_callable(file_id, offset, token)
self.imp.resolve_callable(file_id, offset)
}
}

View File

@ -1,4 +1,4 @@
use crate::{FileId, JobToken, Query};
use crate::{FileId, Query};
use fst::{self, Streamer};
use ra_editor::{file_symbols, FileSymbol};
use ra_syntax::{
@ -59,7 +59,6 @@ impl Query {
pub(crate) fn search(
self,
indices: &[Arc<SymbolIndex>],
token: &JobToken,
) -> Vec<(FileId, FileSymbol)> {
let mut op = fst::map::OpBuilder::new();
for file_symbols in indices.iter() {
@ -69,7 +68,7 @@ impl Query {
let mut stream = op.union();
let mut res = Vec::new();
while let Some((_, indexed_values)) = stream.next() {
if res.len() >= self.limit || token.is_canceled() {
if res.len() >= self.limit {
break;
}
for indexed_value in indexed_values {

View File

@ -161,7 +161,7 @@ pub fn handle_document_symbol(
pub fn handle_workspace_symbol(
world: ServerWorld,
params: req::WorkspaceSymbolParams,
token: JobToken,
_token: JobToken,
) -> Result<Option<Vec<SymbolInformation>>> {
let all_symbols = params.query.contains("#");
let libs = params.query.contains("*");
@ -181,11 +181,11 @@ pub fn handle_workspace_symbol(
q.limit(128);
q
};
let mut res = exec_query(&world, query, &token)?;
let mut res = exec_query(&world, query)?;
if res.is_empty() && !all_symbols {
let mut query = Query::new(params.query);
query.limit(128);
res = exec_query(&world, query, &token)?;
res = exec_query(&world, query)?;
}
return Ok(Some(res));
@ -193,10 +193,9 @@ pub fn handle_workspace_symbol(
fn exec_query(
world: &ServerWorld,
query: Query,
token: &JobToken,
) -> Result<Vec<SymbolInformation>> {
let mut res = Vec::new();
for (file_id, symbol) in world.analysis().symbol_search(query, token) {
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(),
@ -214,7 +213,7 @@ pub fn handle_workspace_symbol(
pub fn handle_goto_definition(
world: ServerWorld,
params: req::TextDocumentPositionParams,
token: JobToken,
_token: JobToken,
) -> Result<Option<req::GotoDefinitionResponse>> {
let file_id = params.text_document.try_conv_with(&world)?;
let line_index = world.analysis().file_line_index(file_id);
@ -222,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, &token)
.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)?;
@ -255,14 +254,14 @@ pub fn handle_runnables(
let line_index = world.analysis().file_line_index(file_id);
let offset = params.position.map(|it| it.conv_with(&line_index));
let mut res = Vec::new();
for runnable in world.analysis().runnables(file_id) {
for runnable in world.analysis().runnables(file_id)? {
if let Some(offset) = offset {
if !contains_offset_nonstrict(runnable.range, offset) {
continue;
}
}
let args = runnable_args(&world, file_id, &runnable.kind);
let args = runnable_args(&world, file_id, &runnable.kind)?;
let r = req::Runnable {
range: runnable.range.conv_with(&line_index),
@ -282,9 +281,9 @@ pub fn handle_runnables(
}
return Ok(res);
fn runnable_args(world: &ServerWorld, file_id: FileId, kind: &RunnableKind) -> Vec<String> {
let spec = if let Some(&crate_id) = world.analysis().crate_for(file_id).first() {
let file_id = world.analysis().crate_root(crate_id);
fn runnable_args(world: &ServerWorld, file_id: FileId, kind: &RunnableKind) -> Result<Vec<String>> {
let spec = if let Some(&crate_id) = world.analysis().crate_for(file_id)?.first() {
let file_id = world.analysis().crate_root(crate_id)?;
let path = world.path_map.get_path(file_id);
world
.workspaces
@ -319,7 +318,7 @@ pub fn handle_runnables(
}
}
}
res
Ok(res)
}
fn spec_args(pkg_name: &str, tgt_name: &str, tgt_kind: TargetKind, buf: &mut Vec<String>) {
@ -356,7 +355,7 @@ pub fn handle_decorations(
_token: JobToken,
) -> Result<Vec<Decoration>> {
let file_id = params.try_conv_with(&world)?;
Ok(highlight(&world, file_id))
highlight(&world, file_id)
}
pub fn handle_completion(
@ -367,7 +366,7 @@ pub fn handle_completion(
let file_id = params.text_document.try_conv_with(&world)?;
let line_index = world.analysis().file_line_index(file_id);
let offset = params.position.conv_with(&line_index);
let items = match world.analysis().completions(file_id, offset) {
let items = match world.analysis().completions(file_id, offset)? {
None => return Ok(None),
Some(items) => items,
};
@ -427,7 +426,7 @@ pub fn handle_folding_range(
pub fn handle_signature_help(
world: ServerWorld,
params: req::TextDocumentPositionParams,
token: JobToken,
_token: JobToken,
) -> Result<Option<req::SignatureHelp>> {
use languageserver_types::{ParameterInformation, SignatureInformation};
@ -436,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, &token)
world.analysis().resolve_callable(file_id, offset)
{
let parameters: Vec<ParameterInformation> = descriptor
.params
@ -466,7 +465,7 @@ pub fn handle_signature_help(
pub fn handle_prepare_rename(
world: ServerWorld,
params: req::TextDocumentPositionParams,
token: JobToken,
_token: JobToken,
) -> Result<Option<PrepareRenameResponse>> {
let file_id = params.text_document.try_conv_with(&world)?;
let line_index = world.analysis().file_line_index(file_id);
@ -474,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, &token);
let refs = world.analysis().find_all_refs(file_id, offset);
if refs.is_empty() {
return Ok(None);
}
@ -488,7 +487,7 @@ pub fn handle_prepare_rename(
pub fn handle_rename(
world: ServerWorld,
params: RenameParams,
token: JobToken,
_token: JobToken,
) -> Result<Option<WorkspaceEdit>> {
let file_id = params.text_document.try_conv_with(&world)?;
let line_index = world.analysis().file_line_index(file_id);
@ -498,7 +497,7 @@ pub fn handle_rename(
return Ok(None);
}
let refs = world.analysis().find_all_refs(file_id, offset, &token);
let refs = world.analysis().find_all_refs(file_id, offset);
if refs.is_empty() {
return Ok(None);
}
@ -525,13 +524,13 @@ pub fn handle_rename(
pub fn handle_references(
world: ServerWorld,
params: req::ReferenceParams,
token: JobToken,
_token: JobToken,
) -> Result<Option<Vec<Location>>> {
let file_id = params.text_document.try_conv_with(&world)?;
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, &token);
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())
@ -547,10 +546,10 @@ pub fn handle_code_action(
let line_index = world.analysis().file_line_index(file_id);
let range = params.range.conv_with(&line_index);
let assists = world.analysis().assists(file_id, range).into_iter();
let assists = world.analysis().assists(file_id, range)?.into_iter();
let fixes = world
.analysis()
.diagnostics(file_id)
.diagnostics(file_id)?
.into_iter()
.filter_map(|d| Some((d.range, d.fix?)))
.filter(|(range, _fix)| contains_offset_nonstrict(*range, range.start()))
@ -579,7 +578,7 @@ pub fn publish_diagnostics(
let line_index = world.analysis().file_line_index(file_id);
let diagnostics = world
.analysis()
.diagnostics(file_id)
.diagnostics(file_id)?
.into_iter()
.map(|d| Diagnostic {
range: d.range.conv_with(&line_index),
@ -600,19 +599,20 @@ pub fn publish_decorations(
let uri = world.file_id_to_uri(file_id)?;
Ok(req::PublishDecorationsParams {
uri,
decorations: highlight(&world, file_id),
decorations: highlight(&world, file_id)?,
})
}
fn highlight(world: &ServerWorld, file_id: FileId) -> Vec<Decoration> {
fn highlight(world: &ServerWorld, file_id: FileId) -> Result<Vec<Decoration>> {
let line_index = world.analysis().file_line_index(file_id);
world
let res = world
.analysis()
.highlight(file_id)
.highlight(file_id)?
.into_iter()
.map(|h| Decoration {
range: h.range.conv_with(&line_index),
tag: h.tag,
})
.collect()
.collect();
Ok(res)
}