diff options
author | Aleksey Kladov <[email protected]> | 2019-01-15 18:09:51 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-01-15 18:09:51 +0000 |
commit | 0bb170a277582f5f17c21cddd27a11f19750fa36 (patch) | |
tree | b97ae214a8616def416b64fb07287ac66554ed3a /crates/ra_ide_api/src/completion | |
parent | 05ba45c667454028c3e65769d6f63fb0f27c1ca8 (diff) |
remove Canceled from impl of ra_ide_api
Diffstat (limited to 'crates/ra_ide_api/src/completion')
4 files changed, 15 insertions, 24 deletions
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 @@ | |||
1 | use hir::{Ty, Def}; | 1 | use hir::{Ty, Def}; |
2 | 2 | ||
3 | use crate::Cancelable; | ||
4 | use crate::completion::{CompletionContext, Completions, CompletionKind, CompletionItem, CompletionItemKind}; | 3 | use crate::completion::{CompletionContext, Completions, CompletionKind, CompletionItem, CompletionItemKind}; |
5 | 4 | ||
6 | /// Complete dot accesses, i.e. fields or methods (currently only fields). | 5 | /// Complete dot accesses, i.e. fields or methods (currently only fields). |
7 | pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) -> Cancelable<()> { | 6 | pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) { |
8 | let (function, receiver) = match (&ctx.function, ctx.dot_receiver) { | 7 | let (function, receiver) = match (&ctx.function, ctx.dot_receiver) { |
9 | (Some(function), Some(receiver)) => (function, receiver), | 8 | (Some(function), Some(receiver)) => (function, receiver), |
10 | _ => return Ok(()), | 9 | _ => return, |
11 | }; | 10 | }; |
12 | let infer_result = function.infer(ctx.db); | 11 | let infer_result = function.infer(ctx.db); |
13 | let syntax_mapping = function.body_syntax_mapping(ctx.db); | 12 | let syntax_mapping = function.body_syntax_mapping(ctx.db); |
14 | let expr = match syntax_mapping.node_expr(receiver) { | 13 | let expr = match syntax_mapping.node_expr(receiver) { |
15 | Some(expr) => expr, | 14 | Some(expr) => expr, |
16 | None => return Ok(()), | 15 | None => return, |
17 | }; | 16 | }; |
18 | let receiver_ty = infer_result[expr].clone(); | 17 | let receiver_ty = infer_result[expr].clone(); |
19 | if !ctx.is_call { | 18 | if !ctx.is_call { |
20 | complete_fields(acc, ctx, receiver_ty.clone()); | 19 | complete_fields(acc, ctx, receiver_ty.clone()); |
21 | } | 20 | } |
22 | complete_methods(acc, ctx, receiver_ty); | 21 | complete_methods(acc, ctx, receiver_ty); |
23 | Ok(()) | ||
24 | } | 22 | } |
25 | 23 | ||
26 | fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { | 24 | 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 @@ | |||
1 | use crate::{ | 1 | use crate::{ |
2 | Cancelable, | ||
3 | completion::{CompletionItem, CompletionItemKind, Completions, CompletionKind, CompletionContext}, | 2 | completion::{CompletionItem, CompletionItemKind, Completions, CompletionKind, CompletionContext}, |
4 | }; | 3 | }; |
5 | 4 | ||
6 | pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) -> Cancelable<()> { | 5 | pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) { |
7 | let (path, module) = match (&ctx.path_prefix, &ctx.module) { | 6 | let (path, module) = match (&ctx.path_prefix, &ctx.module) { |
8 | (Some(path), Some(module)) => (path.clone(), module), | 7 | (Some(path), Some(module)) => (path.clone(), module), |
9 | _ => return Ok(()), | 8 | _ => return, |
10 | }; | 9 | }; |
11 | let def_id = match module.resolve_path(ctx.db, &path).take_types() { | 10 | let def_id = match module.resolve_path(ctx.db, &path).take_types() { |
12 | Some(it) => it, | 11 | Some(it) => it, |
13 | None => return Ok(()), | 12 | None => return, |
14 | }; | 13 | }; |
15 | match def_id.resolve(ctx.db) { | 14 | match def_id.resolve(ctx.db) { |
16 | hir::Def::Module(module) => { | 15 | hir::Def::Module(module) => { |
@@ -30,9 +29,8 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) -> C | |||
30 | .add_to(acc) | 29 | .add_to(acc) |
31 | }); | 30 | }); |
32 | } | 31 | } |
33 | _ => return Ok(()), | 32 | _ => return, |
34 | }; | 33 | }; |
35 | Ok(()) | ||
36 | } | 34 | } |
37 | 35 | ||
38 | #[cfg(test)] | 36 | #[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 @@ | |||
1 | use rustc_hash::FxHashSet; | 1 | use rustc_hash::FxHashSet; |
2 | use ra_syntax::TextUnit; | 2 | use ra_syntax::TextUnit; |
3 | 3 | ||
4 | use crate::{ | 4 | use crate::completion::{CompletionItem, CompletionItemKind, Completions, CompletionKind, CompletionContext}; |
5 | Cancelable, | ||
6 | completion::{CompletionItem, CompletionItemKind, Completions, CompletionKind, CompletionContext}, | ||
7 | }; | ||
8 | 5 | ||
9 | pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) -> Cancelable<()> { | 6 | pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) { |
10 | if !ctx.is_trivial_path { | 7 | if !ctx.is_trivial_path { |
11 | return Ok(()); | 8 | return; |
12 | } | 9 | } |
13 | let module = match &ctx.module { | 10 | let module = match &ctx.module { |
14 | Some(it) => it, | 11 | Some(it) => it, |
15 | None => return Ok(()), | 12 | None => return, |
16 | }; | 13 | }; |
17 | if let Some(function) = &ctx.function { | 14 | if let Some(function) = &ctx.function { |
18 | let scopes = function.scopes(ctx.db); | 15 | let scopes = function.scopes(ctx.db); |
@@ -40,7 +37,6 @@ pub(super) fn complete_scope(acc: &mut Completions, ctx: &CompletionContext) -> | |||
40 | .from_resolution(ctx, res) | 37 | .from_resolution(ctx, res) |
41 | .add_to(acc) | 38 | .add_to(acc) |
42 | }); | 39 | }); |
43 | Ok(()) | ||
44 | } | 40 | } |
45 | 41 | ||
46 | fn complete_fn(acc: &mut Completions, scopes: &hir::ScopesWithSyntaxMapping, offset: TextUnit) { | 42 | 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::{ | |||
7 | }; | 7 | }; |
8 | use hir::source_binder; | 8 | use hir::source_binder; |
9 | 9 | ||
10 | use crate::{db, FilePosition, Cancelable}; | 10 | use crate::{db, FilePosition}; |
11 | 11 | ||
12 | /// `CompletionContext` is created early during completion to figure out, where | 12 | /// `CompletionContext` is created early during completion to figure out, where |
13 | /// exactly is the cursor, syntax-wise. | 13 | /// exactly is the cursor, syntax-wise. |
@@ -41,10 +41,9 @@ impl<'a> CompletionContext<'a> { | |||
41 | db: &'a db::RootDatabase, | 41 | db: &'a db::RootDatabase, |
42 | original_file: &'a SourceFile, | 42 | original_file: &'a SourceFile, |
43 | position: FilePosition, | 43 | position: FilePosition, |
44 | ) -> Cancelable<Option<CompletionContext<'a>>> { | 44 | ) -> Option<CompletionContext<'a>> { |
45 | let module = source_binder::module_from_position(db, position); | 45 | let module = source_binder::module_from_position(db, position); |
46 | let leaf = | 46 | let leaf = find_leaf_at_offset(original_file.syntax(), position.offset).left_biased()?; |
47 | ctry!(find_leaf_at_offset(original_file.syntax(), position.offset).left_biased()); | ||
48 | let mut ctx = CompletionContext { | 47 | let mut ctx = CompletionContext { |
49 | db, | 48 | db, |
50 | leaf, | 49 | leaf, |
@@ -63,7 +62,7 @@ impl<'a> CompletionContext<'a> { | |||
63 | is_call: false, | 62 | is_call: false, |
64 | }; | 63 | }; |
65 | ctx.fill(original_file, position.offset); | 64 | ctx.fill(original_file, position.offset); |
66 | Ok(Some(ctx)) | 65 | Some(ctx) |
67 | } | 66 | } |
68 | 67 | ||
69 | fn fill(&mut self, original_file: &'a SourceFile, offset: TextUnit) { | 68 | fn fill(&mut self, original_file: &'a SourceFile, offset: TextUnit) { |