From 0bb170a277582f5f17c21cddd27a11f19750fa36 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 15 Jan 2019 21:09:51 +0300 Subject: remove Canceled from impl of ra_ide_api --- crates/ra_ide_api/src/completion.rs | 19 ++++----- crates/ra_ide_api/src/completion/complete_dot.rs | 8 ++-- crates/ra_ide_api/src/completion/complete_path.rs | 10 ++--- crates/ra_ide_api/src/completion/complete_scope.rs | 12 ++---- .../src/completion/completion_context.rs | 9 ++-- crates/ra_ide_api/src/imp.rs | 49 ++++++++-------------- crates/ra_ide_api/src/lib.rs | 15 ++----- 7 files changed, 43 insertions(+), 79 deletions(-) (limited to 'crates') diff --git a/crates/ra_ide_api/src/completion.rs b/crates/ra_ide_api/src/completion.rs index ce777a771..b03ddd74c 100644 --- a/crates/ra_ide_api/src/completion.rs +++ b/crates/ra_ide_api/src/completion.rs @@ -12,7 +12,7 @@ use ra_db::SyntaxDatabase; use crate::{ db, - Cancelable, FilePosition, + FilePosition, completion::{ completion_item::{Completions, CompletionKind}, completion_context::CompletionContext, @@ -43,12 +43,9 @@ pub use crate::completion::completion_item::{CompletionItem, InsertText, Complet /// `foo` *should* be present among the completion variants. Filtering by /// identifier prefix/fuzzy match should be done higher in the stack, together /// with ordering of completions (currently this is done by the client). -pub(crate) fn completions( - db: &db::RootDatabase, - position: FilePosition, -) -> Cancelable> { +pub(crate) fn completions(db: &db::RootDatabase, position: FilePosition) -> Option { let original_file = db.source_file(position.file_id); - let ctx = ctry!(CompletionContext::new(db, &original_file, position)?); + let ctx = CompletionContext::new(db, &original_file, position)?; let mut acc = Completions::default(); @@ -57,11 +54,11 @@ pub(crate) fn completions( complete_keyword::complete_use_tree_keyword(&mut acc, &ctx); complete_snippet::complete_expr_snippet(&mut acc, &ctx); complete_snippet::complete_item_snippet(&mut acc, &ctx); - complete_path::complete_path(&mut acc, &ctx)?; - complete_scope::complete_scope(&mut acc, &ctx)?; - complete_dot::complete_dot(&mut acc, &ctx)?; + complete_path::complete_path(&mut acc, &ctx); + complete_scope::complete_scope(&mut acc, &ctx); + complete_dot::complete_dot(&mut acc, &ctx); - Ok(Some(acc)) + Some(acc) } #[cfg(test)] @@ -72,6 +69,6 @@ fn check_completion(code: &str, expected_completions: &str, kind: CompletionKind } else { single_file_with_position(code) }; - let completions = completions(&analysis.db, position).unwrap().unwrap(); + let completions = completions(&analysis.db, position).unwrap(); completions.assert_match(expected_completions, kind); } diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index 31a2478d1..473edc50e 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs @@ -1,26 +1,24 @@ use hir::{Ty, Def}; -use crate::Cancelable; use crate::completion::{CompletionContext, Completions, CompletionKind, CompletionItem, CompletionItemKind}; /// Complete dot accesses, i.e. fields or methods (currently only fields). -pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) -> Cancelable<()> { +pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) { let (function, receiver) = match (&ctx.function, ctx.dot_receiver) { (Some(function), Some(receiver)) => (function, receiver), - _ => return Ok(()), + _ => return, }; let infer_result = function.infer(ctx.db); let syntax_mapping = function.body_syntax_mapping(ctx.db); let expr = match syntax_mapping.node_expr(receiver) { Some(expr) => expr, - None => return Ok(()), + None => return, }; let receiver_ty = infer_result[expr].clone(); if !ctx.is_call { complete_fields(acc, ctx, receiver_ty.clone()); } complete_methods(acc, ctx, receiver_ty); - Ok(()) } fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index 42468681a..1eded7658 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs @@ -1,16 +1,15 @@ use crate::{ - Cancelable, completion::{CompletionItem, CompletionItemKind, Completions, CompletionKind, CompletionContext}, }; -pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) -> Cancelable<()> { +pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { let (path, module) = match (&ctx.path_prefix, &ctx.module) { (Some(path), Some(module)) => (path.clone(), module), - _ => return Ok(()), + _ => return, }; let def_id = match module.resolve_path(ctx.db, &path).take_types() { Some(it) => it, - None => return Ok(()), + None => return, }; match def_id.resolve(ctx.db) { hir::Def::Module(module) => { @@ -30,9 +29,8 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) -> C .add_to(acc) }); } - _ => return Ok(()), + _ => return, }; - Ok(()) } #[cfg(test)] diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs index 660c7d16e..699680748 100644 --- a/crates/ra_ide_api/src/completion/complete_scope.rs +++ b/crates/ra_ide_api/src/completion/complete_scope.rs @@ -1,18 +1,15 @@ use rustc_hash::FxHashSet; use ra_syntax::TextUnit; -use crate::{ - Cancelable, - completion::{CompletionItem, CompletionItemKind, Completions, CompletionKind, CompletionContext}, -}; +use crate::completion::{CompletionItem, CompletionItemKind, Completions, CompletionKind, CompletionContext}; -pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) -> Cancelable<()> { +pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) { if !ctx.is_trivial_path { - return Ok(()); + return; } let module = match &ctx.module { Some(it) => it, - None => return Ok(()), + None => return, }; if let Some(function) = &ctx.function { let scopes = function.scopes(ctx.db); @@ -40,7 +37,6 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) -> .from_resolution(ctx, res) .add_to(acc) }); - Ok(()) } fn complete_fn(acc: &mut Completions, scopes: &hir::ScopesWithSyntaxMapping, offset: TextUnit) { diff --git a/crates/ra_ide_api/src/completion/completion_context.rs b/crates/ra_ide_api/src/completion/completion_context.rs index f5b5ed689..e537e0082 100644 --- a/crates/ra_ide_api/src/completion/completion_context.rs +++ b/crates/ra_ide_api/src/completion/completion_context.rs @@ -7,7 +7,7 @@ use ra_syntax::{ }; use hir::source_binder; -use crate::{db, FilePosition, Cancelable}; +use crate::{db, FilePosition}; /// `CompletionContext` is created early during completion to figure out, where /// exactly is the cursor, syntax-wise. @@ -41,10 +41,9 @@ impl<'a> CompletionContext<'a> { db: &'a db::RootDatabase, original_file: &'a SourceFile, position: FilePosition, - ) -> Cancelable>> { + ) -> Option> { let module = source_binder::module_from_position(db, position); - let leaf = - ctry!(find_leaf_at_offset(original_file.syntax(), position.offset).left_biased()); + let leaf = find_leaf_at_offset(original_file.syntax(), position.offset).left_biased()?; let mut ctx = CompletionContext { db, leaf, @@ -63,7 +62,7 @@ impl<'a> CompletionContext<'a> { is_call: false, }; ctx.fill(original_file, position.offset); - Ok(Some(ctx)) + Some(ctx) } fn fill(&mut self, original_file: &'a SourceFile, offset: TextUnit) { diff --git a/crates/ra_ide_api/src/imp.rs b/crates/ra_ide_api/src/imp.rs index 391df2695..a21cae624 100644 --- a/crates/ra_ide_api/src/imp.rs +++ b/crates/ra_ide_api/src/imp.rs @@ -110,14 +110,11 @@ impl db::RootDatabase { }; vec![krate.crate_id()] } - pub(crate) fn find_all_refs( - &self, - position: FilePosition, - ) -> Cancelable> { + pub(crate) fn find_all_refs(&self, position: FilePosition) -> Vec<(FileId, TextRange)> { let file = self.source_file(position.file_id); // Find the binding associated with the offset - let (binding, descr) = match find_binding(self, &file, position)? { - None => return Ok(Vec::new()), + let (binding, descr) = match find_binding(self, &file, position) { + None => return Vec::new(), Some(it) => it, }; @@ -134,36 +131,30 @@ impl db::RootDatabase { .map(|ref_desc| (position.file_id, ref_desc.range)), ); - return Ok(ret); + return ret; fn find_binding<'a>( db: &db::RootDatabase, source_file: &'a SourceFile, position: FilePosition, - ) -> Cancelable> { + ) -> Option<(&'a ast::BindPat, hir::Function)> { let syntax = source_file.syntax(); if let Some(binding) = find_node_at_offset::(syntax, position.offset) { - let descr = ctry!(source_binder::function_from_child_node( + let descr = source_binder::function_from_child_node( db, position.file_id, binding.syntax(), - )); - return Ok(Some((binding, descr))); + )?; + return Some((binding, descr)); }; - let name_ref = ctry!(find_node_at_offset::(syntax, position.offset)); - let descr = ctry!(source_binder::function_from_child_node( - db, - position.file_id, - name_ref.syntax(), - )); + let name_ref = find_node_at_offset::(syntax, position.offset)?; + let descr = + source_binder::function_from_child_node(db, position.file_id, name_ref.syntax())?; let scope = descr.scopes(db); - let resolved = ctry!(scope.resolve_local_name(name_ref)); + let resolved = scope.resolve_local_name(name_ref)?; let resolved = resolved.ptr().resolve(source_file); - let binding = ctry!(find_node_at_offset::( - syntax, - resolved.range().end() - )); - Ok(Some((binding, descr))) + let binding = find_node_at_offset::(syntax, resolved.range().end())?; + Some((binding, descr)) } } @@ -239,13 +230,8 @@ impl db::RootDatabase { .collect() } - pub(crate) fn rename( - &self, - position: FilePosition, - new_name: &str, - ) -> Cancelable> { - let res = self - .find_all_refs(position)? + pub(crate) fn rename(&self, position: FilePosition, new_name: &str) -> Vec { + self.find_all_refs(position) .iter() .map(|(file_id, text_range)| SourceFileEdit { file_id: *file_id, @@ -255,8 +241,7 @@ impl db::RootDatabase { builder.finish() }, }) - .collect::>(); - Ok(res) + .collect::>() } pub(crate) fn index_resolve(&self, name_ref: &ast::NameRef) -> Vec { let name = name_ref.text(); diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index f18eb09ae..ea5267ad9 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -9,15 +9,6 @@ //! //! The sibling `ra_ide_api_light` handles thouse bits of IDE functionality //! which are restricted to a single file and need only syntax. -macro_rules! ctry { - ($expr:expr) => { - match $expr { - None => return Ok(None), - Some(it) => it, - } - }; -} - mod db; mod imp; pub mod mock_analysis; @@ -400,7 +391,7 @@ impl Analysis { /// Finds all usages of the reference at point. pub fn find_all_refs(&self, position: FilePosition) -> Cancelable> { - self.with_db(|db| db.find_all_refs(position))? + self.with_db(|db| db.find_all_refs(position)) } /// Returns a short text descrbing element at position. @@ -445,7 +436,7 @@ impl Analysis { pub fn completions(&self, position: FilePosition) -> Cancelable>> { let completions = self .db - .catch_canceled(|db| completion::completions(db, position))??; + .catch_canceled(|db| completion::completions(db, position))?; Ok(completions.map(|it| it.into())) } @@ -472,7 +463,7 @@ impl Analysis { position: FilePosition, new_name: &str, ) -> Cancelable> { - self.with_db(|db| db.rename(position, new_name))? + self.with_db(|db| db.rename(position, new_name)) } fn with_db T + std::panic::UnwindSafe, T>( -- cgit v1.2.3