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 | |
parent | 05ba45c667454028c3e65769d6f63fb0f27c1ca8 (diff) |
remove Canceled from impl of ra_ide_api
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r-- | crates/ra_ide_api/src/completion.rs | 19 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_dot.rs | 8 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_path.rs | 10 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_scope.rs | 12 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/completion_context.rs | 9 | ||||
-rw-r--r-- | crates/ra_ide_api/src/imp.rs | 49 | ||||
-rw-r--r-- | crates/ra_ide_api/src/lib.rs | 15 |
7 files changed, 43 insertions, 79 deletions
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; | |||
12 | 12 | ||
13 | use crate::{ | 13 | use crate::{ |
14 | db, | 14 | db, |
15 | Cancelable, FilePosition, | 15 | FilePosition, |
16 | completion::{ | 16 | completion::{ |
17 | completion_item::{Completions, CompletionKind}, | 17 | completion_item::{Completions, CompletionKind}, |
18 | completion_context::CompletionContext, | 18 | completion_context::CompletionContext, |
@@ -43,12 +43,9 @@ pub use crate::completion::completion_item::{CompletionItem, InsertText, Complet | |||
43 | /// `foo` *should* be present among the completion variants. Filtering by | 43 | /// `foo` *should* be present among the completion variants. Filtering by |
44 | /// identifier prefix/fuzzy match should be done higher in the stack, together | 44 | /// identifier prefix/fuzzy match should be done higher in the stack, together |
45 | /// with ordering of completions (currently this is done by the client). | 45 | /// with ordering of completions (currently this is done by the client). |
46 | pub(crate) fn completions( | 46 | pub(crate) fn completions(db: &db::RootDatabase, position: FilePosition) -> Option<Completions> { |
47 | db: &db::RootDatabase, | ||
48 | position: FilePosition, | ||
49 | ) -> Cancelable<Option<Completions>> { | ||
50 | let original_file = db.source_file(position.file_id); | 47 | let original_file = db.source_file(position.file_id); |
51 | let ctx = ctry!(CompletionContext::new(db, &original_file, position)?); | 48 | let ctx = CompletionContext::new(db, &original_file, position)?; |
52 | 49 | ||
53 | let mut acc = Completions::default(); | 50 | let mut acc = Completions::default(); |
54 | 51 | ||
@@ -57,11 +54,11 @@ pub(crate) fn completions( | |||
57 | complete_keyword::complete_use_tree_keyword(&mut acc, &ctx); | 54 | complete_keyword::complete_use_tree_keyword(&mut acc, &ctx); |
58 | complete_snippet::complete_expr_snippet(&mut acc, &ctx); | 55 | complete_snippet::complete_expr_snippet(&mut acc, &ctx); |
59 | complete_snippet::complete_item_snippet(&mut acc, &ctx); | 56 | complete_snippet::complete_item_snippet(&mut acc, &ctx); |
60 | complete_path::complete_path(&mut acc, &ctx)?; | 57 | complete_path::complete_path(&mut acc, &ctx); |
61 | complete_scope::complete_scope(&mut acc, &ctx)?; | 58 | complete_scope::complete_scope(&mut acc, &ctx); |
62 | complete_dot::complete_dot(&mut acc, &ctx)?; | 59 | complete_dot::complete_dot(&mut acc, &ctx); |
63 | 60 | ||
64 | Ok(Some(acc)) | 61 | Some(acc) |
65 | } | 62 | } |
66 | 63 | ||
67 | #[cfg(test)] | 64 | #[cfg(test)] |
@@ -72,6 +69,6 @@ fn check_completion(code: &str, expected_completions: &str, kind: CompletionKind | |||
72 | } else { | 69 | } else { |
73 | single_file_with_position(code) | 70 | single_file_with_position(code) |
74 | }; | 71 | }; |
75 | let completions = completions(&analysis.db, position).unwrap().unwrap(); | 72 | let completions = completions(&analysis.db, position).unwrap(); |
76 | completions.assert_match(expected_completions, kind); | 73 | completions.assert_match(expected_completions, kind); |
77 | } | 74 | } |
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) { |
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 { | |||
110 | }; | 110 | }; |
111 | vec![krate.crate_id()] | 111 | vec![krate.crate_id()] |
112 | } | 112 | } |
113 | pub(crate) fn find_all_refs( | 113 | pub(crate) fn find_all_refs(&self, position: FilePosition) -> Vec<(FileId, TextRange)> { |
114 | &self, | ||
115 | position: FilePosition, | ||
116 | ) -> Cancelable<Vec<(FileId, TextRange)>> { | ||
117 | let file = self.source_file(position.file_id); | 114 | let file = self.source_file(position.file_id); |
118 | // Find the binding associated with the offset | 115 | // Find the binding associated with the offset |
119 | let (binding, descr) = match find_binding(self, &file, position)? { | 116 | let (binding, descr) = match find_binding(self, &file, position) { |
120 | None => return Ok(Vec::new()), | 117 | None => return Vec::new(), |
121 | Some(it) => it, | 118 | Some(it) => it, |
122 | }; | 119 | }; |
123 | 120 | ||
@@ -134,36 +131,30 @@ impl db::RootDatabase { | |||
134 | .map(|ref_desc| (position.file_id, ref_desc.range)), | 131 | .map(|ref_desc| (position.file_id, ref_desc.range)), |
135 | ); | 132 | ); |
136 | 133 | ||
137 | return Ok(ret); | 134 | return ret; |
138 | 135 | ||
139 | fn find_binding<'a>( | 136 | fn find_binding<'a>( |
140 | db: &db::RootDatabase, | 137 | db: &db::RootDatabase, |
141 | source_file: &'a SourceFile, | 138 | source_file: &'a SourceFile, |
142 | position: FilePosition, | 139 | position: FilePosition, |
143 | ) -> Cancelable<Option<(&'a ast::BindPat, hir::Function)>> { | 140 | ) -> Option<(&'a ast::BindPat, hir::Function)> { |
144 | let syntax = source_file.syntax(); | 141 | let syntax = source_file.syntax(); |
145 | if let Some(binding) = find_node_at_offset::<ast::BindPat>(syntax, position.offset) { | 142 | if let Some(binding) = find_node_at_offset::<ast::BindPat>(syntax, position.offset) { |
146 | let descr = ctry!(source_binder::function_from_child_node( | 143 | let descr = source_binder::function_from_child_node( |
147 | db, | 144 | db, |
148 | position.file_id, | 145 | position.file_id, |
149 | binding.syntax(), | 146 | binding.syntax(), |
150 | )); | 147 | )?; |
151 | return Ok(Some((binding, descr))); | 148 | return Some((binding, descr)); |
152 | }; | 149 | }; |
153 | let name_ref = ctry!(find_node_at_offset::<ast::NameRef>(syntax, position.offset)); | 150 | let name_ref = find_node_at_offset::<ast::NameRef>(syntax, position.offset)?; |
154 | let descr = ctry!(source_binder::function_from_child_node( | 151 | let descr = |
155 | db, | 152 | source_binder::function_from_child_node(db, position.file_id, name_ref.syntax())?; |
156 | position.file_id, | ||
157 | name_ref.syntax(), | ||
158 | )); | ||
159 | let scope = descr.scopes(db); | 153 | let scope = descr.scopes(db); |
160 | let resolved = ctry!(scope.resolve_local_name(name_ref)); | 154 | let resolved = scope.resolve_local_name(name_ref)?; |
161 | let resolved = resolved.ptr().resolve(source_file); | 155 | let resolved = resolved.ptr().resolve(source_file); |
162 | let binding = ctry!(find_node_at_offset::<ast::BindPat>( | 156 | let binding = find_node_at_offset::<ast::BindPat>(syntax, resolved.range().end())?; |
163 | syntax, | 157 | Some((binding, descr)) |
164 | resolved.range().end() | ||
165 | )); | ||
166 | Ok(Some((binding, descr))) | ||
167 | } | 158 | } |
168 | } | 159 | } |
169 | 160 | ||
@@ -239,13 +230,8 @@ impl db::RootDatabase { | |||
239 | .collect() | 230 | .collect() |
240 | } | 231 | } |
241 | 232 | ||
242 | pub(crate) fn rename( | 233 | pub(crate) fn rename(&self, position: FilePosition, new_name: &str) -> Vec<SourceFileEdit> { |
243 | &self, | 234 | self.find_all_refs(position) |
244 | position: FilePosition, | ||
245 | new_name: &str, | ||
246 | ) -> Cancelable<Vec<SourceFileEdit>> { | ||
247 | let res = self | ||
248 | .find_all_refs(position)? | ||
249 | .iter() | 235 | .iter() |
250 | .map(|(file_id, text_range)| SourceFileEdit { | 236 | .map(|(file_id, text_range)| SourceFileEdit { |
251 | file_id: *file_id, | 237 | file_id: *file_id, |
@@ -255,8 +241,7 @@ impl db::RootDatabase { | |||
255 | builder.finish() | 241 | builder.finish() |
256 | }, | 242 | }, |
257 | }) | 243 | }) |
258 | .collect::<Vec<_>>(); | 244 | .collect::<Vec<_>>() |
259 | Ok(res) | ||
260 | } | 245 | } |
261 | pub(crate) fn index_resolve(&self, name_ref: &ast::NameRef) -> Vec<FileSymbol> { | 246 | pub(crate) fn index_resolve(&self, name_ref: &ast::NameRef) -> Vec<FileSymbol> { |
262 | let name = name_ref.text(); | 247 | 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 @@ | |||
9 | //! | 9 | //! |
10 | //! The sibling `ra_ide_api_light` handles thouse bits of IDE functionality | 10 | //! The sibling `ra_ide_api_light` handles thouse bits of IDE functionality |
11 | //! which are restricted to a single file and need only syntax. | 11 | //! which are restricted to a single file and need only syntax. |
12 | macro_rules! ctry { | ||
13 | ($expr:expr) => { | ||
14 | match $expr { | ||
15 | None => return Ok(None), | ||
16 | Some(it) => it, | ||
17 | } | ||
18 | }; | ||
19 | } | ||
20 | |||
21 | mod db; | 12 | mod db; |
22 | mod imp; | 13 | mod imp; |
23 | pub mod mock_analysis; | 14 | pub mod mock_analysis; |
@@ -400,7 +391,7 @@ impl Analysis { | |||
400 | 391 | ||
401 | /// Finds all usages of the reference at point. | 392 | /// Finds all usages of the reference at point. |
402 | pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> { | 393 | pub fn find_all_refs(&self, position: FilePosition) -> Cancelable<Vec<(FileId, TextRange)>> { |
403 | self.with_db(|db| db.find_all_refs(position))? | 394 | self.with_db(|db| db.find_all_refs(position)) |
404 | } | 395 | } |
405 | 396 | ||
406 | /// Returns a short text descrbing element at position. | 397 | /// Returns a short text descrbing element at position. |
@@ -445,7 +436,7 @@ impl Analysis { | |||
445 | pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> { | 436 | pub fn completions(&self, position: FilePosition) -> Cancelable<Option<Vec<CompletionItem>>> { |
446 | let completions = self | 437 | let completions = self |
447 | .db | 438 | .db |
448 | .catch_canceled(|db| completion::completions(db, position))??; | 439 | .catch_canceled(|db| completion::completions(db, position))?; |
449 | Ok(completions.map(|it| it.into())) | 440 | Ok(completions.map(|it| it.into())) |
450 | } | 441 | } |
451 | 442 | ||
@@ -472,7 +463,7 @@ impl Analysis { | |||
472 | position: FilePosition, | 463 | position: FilePosition, |
473 | new_name: &str, | 464 | new_name: &str, |
474 | ) -> Cancelable<Vec<SourceFileEdit>> { | 465 | ) -> Cancelable<Vec<SourceFileEdit>> { |
475 | self.with_db(|db| db.rename(position, new_name))? | 466 | self.with_db(|db| db.rename(position, new_name)) |
476 | } | 467 | } |
477 | 468 | ||
478 | fn with_db<F: FnOnce(&db::RootDatabase) -> T + std::panic::UnwindSafe, T>( | 469 | fn with_db<F: FnOnce(&db::RootDatabase) -> T + std::panic::UnwindSafe, T>( |