diff options
Diffstat (limited to 'crates/ide_completion/src/context.rs')
-rw-r--r-- | crates/ide_completion/src/context.rs | 44 |
1 files changed, 8 insertions, 36 deletions
diff --git a/crates/ide_completion/src/context.rs b/crates/ide_completion/src/context.rs index b7e116dba..fbef54408 100644 --- a/crates/ide_completion/src/context.rs +++ b/crates/ide_completion/src/context.rs | |||
@@ -17,9 +17,8 @@ use text_edit::Indel; | |||
17 | 17 | ||
18 | use crate::{ | 18 | use crate::{ |
19 | patterns::{ | 19 | patterns::{ |
20 | for_is_prev2, has_bind_pat_parent, has_block_expr_parent, has_field_list_parent, | 20 | determine_location, for_is_prev2, has_prev_sibling, inside_impl_trait_block, |
21 | has_impl_parent, has_item_list_or_source_file_parent, has_prev_sibling, has_ref_parent, | 21 | is_in_loop_body, is_match_arm, previous_token, ImmediateLocation, |
22 | has_trait_parent, inside_impl_trait_block, is_in_loop_body, is_match_arm, previous_token, | ||
23 | }, | 22 | }, |
24 | CompletionConfig, | 23 | CompletionConfig, |
25 | }; | 24 | }; |
@@ -30,18 +29,6 @@ pub(crate) enum PatternRefutability { | |||
30 | Irrefutable, | 29 | Irrefutable, |
31 | } | 30 | } |
32 | 31 | ||
33 | /// Direct parent container of the cursor position | ||
34 | #[derive(Copy, Clone, Debug, PartialEq, Eq)] | ||
35 | pub(crate) enum ImmediateLocation { | ||
36 | Impl, | ||
37 | Trait, | ||
38 | RecordFieldList, | ||
39 | RefPatOrExpr, | ||
40 | IdentPat, | ||
41 | BlockExpr, | ||
42 | ItemList, | ||
43 | } | ||
44 | |||
45 | #[derive(Copy, Clone, Debug, PartialEq, Eq)] | 32 | #[derive(Copy, Clone, Debug, PartialEq, Eq)] |
46 | pub(crate) enum PrevSibling { | 33 | pub(crate) enum PrevSibling { |
47 | Trait, | 34 | Trait, |
@@ -301,15 +288,15 @@ impl<'a> CompletionContext<'a> { | |||
301 | matches!(self.completion_location, Some(ImmediateLocation::BlockExpr)) | 288 | matches!(self.completion_location, Some(ImmediateLocation::BlockExpr)) |
302 | } | 289 | } |
303 | 290 | ||
304 | pub(crate) fn has_ident_or_ref_pat_parent(&self) -> bool { | 291 | pub(crate) fn expects_ident_pat_or_ref_expr(&self) -> bool { |
305 | matches!( | 292 | matches!( |
306 | self.completion_location, | 293 | self.completion_location, |
307 | Some(ImmediateLocation::IdentPat) | Some(ImmediateLocation::RefPatOrExpr) | 294 | Some(ImmediateLocation::IdentPat) | Some(ImmediateLocation::RefExpr) |
308 | ) | 295 | ) |
309 | } | 296 | } |
310 | 297 | ||
311 | pub(crate) fn expect_record_field(&self) -> bool { | 298 | pub(crate) fn expect_record_field(&self) -> bool { |
312 | matches!(self.completion_location, Some(ImmediateLocation::RecordFieldList)) | 299 | matches!(self.completion_location, Some(ImmediateLocation::RecordField)) |
313 | } | 300 | } |
314 | 301 | ||
315 | pub(crate) fn has_impl_or_trait_prev_sibling(&self) -> bool { | 302 | pub(crate) fn has_impl_or_trait_prev_sibling(&self) -> bool { |
@@ -324,9 +311,8 @@ impl<'a> CompletionContext<'a> { | |||
324 | } | 311 | } |
325 | 312 | ||
326 | fn fill_keyword_patterns(&mut self, file_with_fake_ident: &SyntaxNode, offset: TextSize) { | 313 | fn fill_keyword_patterns(&mut self, file_with_fake_ident: &SyntaxNode, offset: TextSize) { |
327 | dbg!(file_with_fake_ident); | ||
328 | let fake_ident_token = file_with_fake_ident.token_at_offset(offset).right_biased().unwrap(); | 314 | let fake_ident_token = file_with_fake_ident.token_at_offset(offset).right_biased().unwrap(); |
329 | let syntax_element = NodeOrToken::Token(fake_ident_token); | 315 | let syntax_element = NodeOrToken::Token(fake_ident_token.clone()); |
330 | self.previous_token = previous_token(syntax_element.clone()); | 316 | self.previous_token = previous_token(syntax_element.clone()); |
331 | self.in_loop_body = is_in_loop_body(syntax_element.clone()); | 317 | self.in_loop_body = is_in_loop_body(syntax_element.clone()); |
332 | self.is_match_arm = is_match_arm(syntax_element.clone()); | 318 | self.is_match_arm = is_match_arm(syntax_element.clone()); |
@@ -336,22 +322,6 @@ impl<'a> CompletionContext<'a> { | |||
336 | self.prev_sibling = Some(PrevSibling::Trait) | 322 | self.prev_sibling = Some(PrevSibling::Trait) |
337 | } | 323 | } |
338 | 324 | ||
339 | if has_block_expr_parent(syntax_element.clone()) { | ||
340 | self.completion_location = Some(ImmediateLocation::BlockExpr); | ||
341 | } else if has_bind_pat_parent(syntax_element.clone()) { | ||
342 | self.completion_location = Some(ImmediateLocation::IdentPat); | ||
343 | } else if has_ref_parent(syntax_element.clone()) { | ||
344 | self.completion_location = Some(ImmediateLocation::RefPatOrExpr); | ||
345 | } else if has_impl_parent(syntax_element.clone()) { | ||
346 | self.completion_location = Some(ImmediateLocation::Impl); | ||
347 | } else if has_field_list_parent(syntax_element.clone()) { | ||
348 | self.completion_location = Some(ImmediateLocation::RecordFieldList); | ||
349 | } else if has_trait_parent(syntax_element.clone()) { | ||
350 | self.completion_location = Some(ImmediateLocation::Trait); | ||
351 | } else if has_item_list_or_source_file_parent(syntax_element.clone()) { | ||
352 | self.completion_location = Some(ImmediateLocation::ItemList); | ||
353 | } | ||
354 | |||
355 | self.mod_declaration_under_caret = | 325 | self.mod_declaration_under_caret = |
356 | find_node_at_offset::<ast::Module>(&file_with_fake_ident, offset) | 326 | find_node_at_offset::<ast::Module>(&file_with_fake_ident, offset) |
357 | .filter(|module| module.item_list().is_none()); | 327 | .filter(|module| module.item_list().is_none()); |
@@ -364,6 +334,8 @@ impl<'a> CompletionContext<'a> { | |||
364 | let fn_is_prev = self.previous_token_is(T![fn]); | 334 | let fn_is_prev = self.previous_token_is(T![fn]); |
365 | let for_is_prev2 = for_is_prev2(syntax_element.clone()); | 335 | let for_is_prev2 = for_is_prev2(syntax_element.clone()); |
366 | self.no_completion_required = (fn_is_prev && !inside_impl_trait_block) || for_is_prev2; | 336 | self.no_completion_required = (fn_is_prev && !inside_impl_trait_block) || for_is_prev2; |
337 | |||
338 | self.completion_location = determine_location(fake_ident_token); | ||
367 | } | 339 | } |
368 | 340 | ||
369 | fn fill_impl_def(&mut self) { | 341 | fn fill_impl_def(&mut self) { |