]> git.lizzy.rs Git - rust.git/commitdiff
remove Canceled from impl of ra_ide_api
authorAleksey Kladov <aleksey.kladov@gmail.com>
Tue, 15 Jan 2019 18:09:51 +0000 (21:09 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Tue, 15 Jan 2019 18:09:51 +0000 (21:09 +0300)
crates/ra_ide_api/src/completion.rs
crates/ra_ide_api/src/completion/complete_dot.rs
crates/ra_ide_api/src/completion/complete_path.rs
crates/ra_ide_api/src/completion/complete_scope.rs
crates/ra_ide_api/src/completion/completion_context.rs
crates/ra_ide_api/src/imp.rs
crates/ra_ide_api/src/lib.rs

index ce777a771e2e1a1c968b4a432311cca1b712d095..b03ddd74c0c29fd8cdd27434d54c89579b9f7388 100644 (file)
@@ -12,7 +12,7 @@
 
 use crate::{
     db,
-    Cancelable, FilePosition,
+    FilePosition,
     completion::{
         completion_item::{Completions, CompletionKind},
         completion_context::CompletionContext,
 /// `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<Option<Completions>> {
+pub(crate) fn completions(db: &db::RootDatabase, position: FilePosition) -> Option<Completions> {
     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);
 }
index 31a2478d13f2b1c90d13e8b2ffd09cbc43de1be3..473edc50eabe2677de4c917a6827eb5802c6b0a2 100644 (file)
@@ -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) {
index 42468681a9f15fd977f20c1e2d5a1386719c5d08..1eded7658ea9d7c45cd9482604ad211e9d2a1f76 100644 (file)
@@ -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)]
index 660c7d16e75fab0ce6f87b975ae75de5a713fb90..69968074863d8e3817f09a83ec8fdfe2a84689a6 100644 (file)
@@ -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) {
index f5b5ed689685a9da82e8f905893d6de56fa9d425..e537e0082d84ebfc413c70a78ad2c2959c6f7dd7 100644 (file)
@@ -7,7 +7,7 @@
 };
 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 @@ pub(super) fn new(
         db: &'a db::RootDatabase,
         original_file: &'a SourceFile,
         position: FilePosition,
-    ) -> Cancelable<Option<CompletionContext<'a>>> {
+    ) -> Option<CompletionContext<'a>> {
         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 @@ pub(super) fn new(
             is_call: false,
         };
         ctx.fill(original_file, position.offset);
-        Ok(Some(ctx))
+        Some(ctx)
     }
 
     fn fill(&mut self, original_file: &'a SourceFile, offset: TextUnit) {
index 391df269525ba5f041f43991fccf1790eb90d2c4..a21cae62474f907235bc47b87396ee63c486eb0a 100644 (file)
@@ -110,14 +110,11 @@ pub(crate) fn crate_for(&self, file_id: FileId) -> Vec<CrateId> {
         };
         vec![krate.crate_id()]
     }
-    pub(crate) fn find_all_refs(
-        &self,
-        position: FilePosition,
-    ) -> Cancelable<Vec<(FileId, TextRange)>> {
+    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 @@ pub(crate) fn find_all_refs(
                 .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)>> {
+        ) -> Option<(&'a ast::BindPat, hir::Function)> {
             let syntax = source_file.syntax();
             if let Some(binding) = find_node_at_offset::<ast::BindPat>(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::<ast::NameRef>(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::<ast::NameRef>(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::<ast::BindPat>(
-                syntax,
-                resolved.range().end()
-            ));
-            Ok(Some((binding, descr)))
+            let binding = find_node_at_offset::<ast::BindPat>(syntax, resolved.range().end())?;
+            Some((binding, descr))
         }
     }
 
@@ -239,13 +230,8 @@ pub(crate) fn assists(&self, frange: FileRange) -> Vec<SourceChange> {
             .collect()
     }
 
-    pub(crate) fn rename(
-        &self,
-        position: FilePosition,
-        new_name: &str,
-    ) -> Cancelable<Vec<SourceFileEdit>> {
-        let res = self
-            .find_all_refs(position)?
+    pub(crate) fn rename(&self, position: FilePosition, new_name: &str) -> Vec<SourceFileEdit> {
+        self.find_all_refs(position)
             .iter()
             .map(|(file_id, text_range)| SourceFileEdit {
                 file_id: *file_id,
@@ -255,8 +241,7 @@ pub(crate) fn rename(
                     builder.finish()
                 },
             })
-            .collect::<Vec<_>>();
-        Ok(res)
+            .collect::<Vec<_>>()
     }
     pub(crate) fn index_resolve(&self, name_ref: &ast::NameRef) -> Vec<FileSymbol> {
         let name = name_ref.text();
index f18eb09ae7d48cd625ade3216b9f5ac5d450e976..ea5267ad9e2cc1c824965807778ec6101d0b9a8d 100644 (file)
@@ -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 @@ pub fn goto_definition(
 
     /// Finds all usages of the reference at point.
     pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> {
-        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 @@ pub fn highlight(&self, file_id: FileId) -> Cancelable<Vec<HighlightedRange>> {
     pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> {
         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 @@ pub fn rename(
         position: FilePosition,
         new_name: &str,
     ) -> Cancelable<Vec<SourceFileEdit>> {
-        self.with_db(|db| db.rename(position, new_name))?
+        self.with_db(|db| db.rename(position, new_name))
     }
 
     fn with_db<F: FnOnce(&db::RootDatabase) -> T + std::panic::UnwindSafe, T>(