From e74bf6e56e45a26002ef2a77fb3ac27f523277fb Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 20 Oct 2018 22:15:03 +0300 Subject: mark module queries as cacelable --- crates/ra_analysis/src/imp.rs | 26 +++++++++++++------------- crates/ra_analysis/src/lib.rs | 10 +++++----- crates/ra_analysis/src/module_map.rs | 15 ++++++++------- crates/ra_analysis/src/roots.rs | 9 +++++---- 4 files changed, 31 insertions(+), 29 deletions(-) (limited to 'crates') diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs index d60fb8278..df5aacb2d 100644 --- a/crates/ra_analysis/src/imp.rs +++ b/crates/ra_analysis/src/imp.rs @@ -159,7 +159,7 @@ impl AnalysisImpl { } pub fn parent_module(&self, file_id: FileId) -> Cancelable> { let root = self.root(file_id); - let module_tree = root.module_tree(); + let module_tree = root.module_tree()?; let res = module_tree .parent_modules(file_id) .iter() @@ -177,8 +177,8 @@ impl AnalysisImpl { .collect(); Ok(res) } - pub fn crate_for(&self, file_id: FileId) -> Vec { - let module_tree = self.root(file_id).module_tree(); + pub fn crate_for(&self, file_id: FileId) -> Cancelable> { + let module_tree = self.root(file_id).module_tree()?; let crate_graph = &self.data.crate_graph; let mut res = Vec::new(); let mut work = VecDeque::new(); @@ -196,7 +196,7 @@ impl AnalysisImpl { .filter(|&id| visited.insert(id)); work.extend(parents); } - res + Ok(res) } pub fn crate_root(&self, crate_id: CrateId) -> FileId { self.data.crate_graph.crate_roots[&crate_id] @@ -205,9 +205,9 @@ impl AnalysisImpl { &self, file_id: FileId, offset: TextUnit, - ) -> Vec<(FileId, FileSymbol)> { + ) -> Cancelable> { let root = self.root(file_id); - let module_tree = root.module_tree(); + let module_tree = root.module_tree()?; let file = root.syntax(file_id); let syntax = file.syntax(); if let Some(name_ref) = find_node_at_offset::(syntax, offset) { @@ -223,10 +223,10 @@ impl AnalysisImpl { }, )); - return vec; + return Ok(vec); } else { // If that fails try the index based approach. - return self.index_resolve(name_ref); + return Ok(self.index_resolve(name_ref)); } } if let Some(name) = find_node_at_offset::(syntax, offset) { @@ -250,11 +250,11 @@ impl AnalysisImpl { }) .collect(); - return res; + return Ok(res); } } } - vec![] + Ok(vec![]) } pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit) -> Vec<(FileId, TextRange)> { @@ -289,9 +289,9 @@ impl AnalysisImpl { ret } - pub fn diagnostics(&self, file_id: FileId) -> Vec { + pub fn diagnostics(&self, file_id: FileId) -> Cancelable> { let root = self.root(file_id); - let module_tree = root.module_tree(); + let module_tree = root.module_tree()?; let syntax = root.syntax(file_id); let mut res = ra_editor::diagnostics(&syntax) @@ -346,7 +346,7 @@ impl AnalysisImpl { }; res.push(diag) } - res + Ok(res) } pub fn assists(&self, file_id: FileId, range: TextRange) -> Vec { diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs index 8595d7e03..6ce32894a 100644 --- a/crates/ra_analysis/src/lib.rs +++ b/crates/ra_analysis/src/lib.rs @@ -37,7 +37,7 @@ pub use ra_editor::{ RunnableKind, StructureNode, }; -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct Cancel; pub type Cancelable = Result; @@ -231,8 +231,8 @@ impl Analysis { file_id: FileId, offset: TextUnit ) -> Cancelable> { - Ok(self.imp - .approximately_resolve_symbol(file_id, offset)) + self.imp + .approximately_resolve_symbol(file_id, offset) } pub fn find_all_refs(&self, file_id: FileId, offset: TextUnit, ) -> Cancelable> { Ok(self.imp.find_all_refs(file_id, offset)) @@ -241,7 +241,7 @@ impl Analysis { self.imp.parent_module(file_id) } pub fn crate_for(&self, file_id: FileId) -> Cancelable> { - Ok(self.imp.crate_for(file_id)) + self.imp.crate_for(file_id) } pub fn crate_root(&self, crate_id: CrateId) -> Cancelable { Ok(self.imp.crate_root(crate_id)) @@ -262,7 +262,7 @@ impl Analysis { Ok(self.imp.assists(file_id, range)) } pub fn diagnostics(&self, file_id: FileId) -> Cancelable> { - Ok(self.imp.diagnostics(file_id)) + self.imp.diagnostics(file_id) } pub fn resolve_callable( &self, diff --git a/crates/ra_analysis/src/module_map.rs b/crates/ra_analysis/src/module_map.rs index b15432498..0c413becd 100644 --- a/crates/ra_analysis/src/module_map.rs +++ b/crates/ra_analysis/src/module_map.rs @@ -1,4 +1,5 @@ use crate::{ + Cancelable, db::SyntaxDatabase, descriptors::{ModuleDescriptor, ModuleTreeDescriptor}, FileId, @@ -8,30 +9,30 @@ use std::sync::Arc; salsa::query_group! { pub(crate) trait ModulesDatabase: SyntaxDatabase { - fn module_tree() -> Arc { + fn module_tree() -> Cancelable> { type ModuleTreeQuery; } - fn module_descriptor(file_id: FileId) -> Arc { + fn module_descriptor(file_id: FileId) -> Cancelable> { type ModuleDescriptorQuery; } } } -fn module_descriptor(db: &impl ModulesDatabase, file_id: FileId) -> Arc { +fn module_descriptor(db: &impl ModulesDatabase, file_id: FileId) -> Cancelable> { let file = db.file_syntax(file_id); - Arc::new(ModuleDescriptor::new(file.ast())) + Ok(Arc::new(ModuleDescriptor::new(file.ast()))) } -fn module_tree(db: &impl ModulesDatabase) -> Arc { +fn module_tree(db: &impl ModulesDatabase) -> Cancelable> { let file_set = db.file_set(); let mut files = Vec::new(); for &file_id in file_set.files.iter() { - let module_descr = db.module_descriptor(file_id); + let module_descr = db.module_descriptor(file_id)?; files.push((file_id, module_descr)); } let res = ModuleTreeDescriptor::new( files.iter().map(|(file_id, descr)| (*file_id, &**descr)), &file_set.resolver, ); - Arc::new(res) + Ok(Arc::new(res)) } diff --git a/crates/ra_analysis/src/roots.rs b/crates/ra_analysis/src/roots.rs index 19c84df65..e950a75e2 100644 --- a/crates/ra_analysis/src/roots.rs +++ b/crates/ra_analysis/src/roots.rs @@ -8,6 +8,7 @@ use rustc_hash::{FxHashMap, FxHashSet}; use salsa::Database; use crate::{ + Cancelable, db::{self, FilesDatabase, SyntaxDatabase}, descriptors::{ModuleDescriptor, ModuleTreeDescriptor}, imp::FileResolverImp, @@ -18,7 +19,7 @@ use crate::{ pub(crate) trait SourceRoot { fn contains(&self, file_id: FileId) -> bool; - fn module_tree(&self) -> Arc; + fn module_tree(&self) -> Cancelable>; fn lines(&self, file_id: FileId) -> Arc; fn syntax(&self, file_id: FileId) -> File; fn symbols(&self, acc: &mut Vec>); @@ -64,7 +65,7 @@ impl WritableSourceRoot { } impl SourceRoot for WritableSourceRoot { - fn module_tree(&self) -> Arc { + fn module_tree(&self) -> Cancelable> { self.db.module_tree() } fn contains(&self, file_id: FileId) -> bool { @@ -167,8 +168,8 @@ impl ReadonlySourceRoot { } impl SourceRoot for ReadonlySourceRoot { - fn module_tree(&self) -> Arc { - Arc::clone(&self.module_tree) + fn module_tree(&self) -> Cancelable> { + Ok(Arc::clone(&self.module_tree)) } fn contains(&self, file_id: FileId) -> bool { self.file_map.contains_key(&file_id) -- cgit v1.2.3