From b871062e329301683083a1a2ff5eb476e6c397c7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 15 Jan 2019 20:43:37 +0300 Subject: remove Cancelable from Ty --- crates/ra_ide_api/src/completion/complete_dot.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'crates/ra_ide_api/src/completion') diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index cb86ba9a3..30a0a3924 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs @@ -17,13 +17,13 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) -> Ca }; let receiver_ty = infer_result[expr].clone(); if !ctx.is_call { - complete_fields(acc, ctx, receiver_ty.clone())?; + complete_fields(acc, ctx, receiver_ty.clone()); } complete_methods(acc, ctx, receiver_ty)?; Ok(()) } -fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) -> Cancelable<()> { +fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { for receiver in receiver.autoderef(ctx.db) { match receiver { Ty::Adt { def_id, .. } => { @@ -35,7 +35,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) field.name().to_string(), ) .kind(CompletionItemKind::Field) - .set_detail(field.ty(ctx.db)?.map(|ty| ty.to_string())) + .set_detail(field.ty(ctx.db).map(|ty| ty.to_string())) .add_to(acc); } } @@ -53,7 +53,6 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) _ => {} }; } - Ok(()) } fn complete_methods( -- cgit v1.2.3 From 8ba9c2d4cedbcf8f1d2c644733d2b06fa1984d22 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 15 Jan 2019 20:54:18 +0300 Subject: remove Cancelable from type inference --- crates/ra_ide_api/src/completion/complete_dot.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'crates/ra_ide_api/src/completion') diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index 30a0a3924..31a2478d1 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs @@ -9,7 +9,7 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) -> Ca (Some(function), Some(receiver)) => (function, receiver), _ => return Ok(()), }; - let infer_result = function.infer(ctx.db)?; + 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, @@ -19,7 +19,7 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) -> Ca if !ctx.is_call { complete_fields(acc, ctx, receiver_ty.clone()); } - complete_methods(acc, ctx, receiver_ty)?; + complete_methods(acc, ctx, receiver_ty); Ok(()) } @@ -55,11 +55,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) } } -fn complete_methods( - acc: &mut Completions, - ctx: &CompletionContext, - receiver: Ty, -) -> Cancelable<()> { +fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { receiver.iterate_methods(ctx.db, |func| { let sig = func.signature(ctx.db); if sig.has_self_param() { @@ -68,9 +64,8 @@ fn complete_methods( .kind(CompletionItemKind::Method) .add_to(acc); } - Ok(None::<()>) - })?; - Ok(()) + None::<()> + }); } #[cfg(test)] -- cgit v1.2.3 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/complete_dot.rs | 8 +++----- crates/ra_ide_api/src/completion/complete_path.rs | 10 ++++------ crates/ra_ide_api/src/completion/complete_scope.rs | 12 ++++-------- crates/ra_ide_api/src/completion/completion_context.rs | 9 ++++----- 4 files changed, 15 insertions(+), 24 deletions(-) (limited to 'crates/ra_ide_api/src/completion') 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) { -- cgit v1.2.3