From 70157f07d9a33e4b8ed71e162218a793f44a7691 Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Mon, 12 Oct 2020 10:59:15 +0300 Subject: Remove redundant completions --- crates/ide/src/completion/completion_context.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'crates/ide/src/completion/completion_context.rs') diff --git a/crates/ide/src/completion/completion_context.rs b/crates/ide/src/completion/completion_context.rs index 8dea8a4bf..c9473cca6 100644 --- a/crates/ide/src/completion/completion_context.rs +++ b/crates/ide/src/completion/completion_context.rs @@ -16,10 +16,10 @@ use crate::{ call_info::ActiveParameter, completion::{ patterns::{ - has_bind_pat_parent, has_block_expr_parent, has_field_list_parent, - has_impl_as_prev_sibling, has_impl_parent, has_item_list_or_source_file_parent, - has_ref_parent, has_trait_as_prev_sibling, has_trait_parent, if_is_prev, - is_in_loop_body, is_match_arm, unsafe_is_prev, + fn_is_prev, for_is_prev2, has_bind_pat_parent, has_block_expr_parent, + has_field_list_parent, has_impl_as_prev_sibling, has_impl_parent, + has_item_list_or_source_file_parent, has_ref_parent, has_trait_as_prev_sibling, + has_trait_parent, if_is_prev, is_in_loop_body, is_match_arm, unsafe_is_prev, }, CompletionConfig, }, @@ -91,6 +91,8 @@ pub(crate) struct CompletionContext<'a> { pub(super) impl_as_prev_sibling: bool, pub(super) is_match_arm: bool, pub(super) has_item_list_or_source_file_parent: bool, + pub(super) for_is_prev2: bool, + pub(super) fn_is_prev: bool, pub(super) locals: Vec<(String, Local)>, } @@ -174,6 +176,8 @@ impl<'a> CompletionContext<'a> { if_is_prev: false, is_match_arm: false, has_item_list_or_source_file_parent: false, + for_is_prev2: false, + fn_is_prev: false, locals, }; @@ -221,6 +225,14 @@ impl<'a> CompletionContext<'a> { Some(ctx) } + /// Checks whether completions in that particular case don't make much sense. + /// Examples: + /// - `fn <|>` -- we expect function name, it's unlikely that "hint" will be helpful. + /// - `for _ i<|>` -- obviously, it'll be "in" keyword. + pub(crate) fn no_completion_required(&self) -> bool { + self.fn_is_prev || self.for_is_prev2 + } + /// The range of the identifier that is being completed. pub(crate) fn source_range(&self) -> TextRange { // check kind of macro-expanded token, but use range of original token @@ -253,6 +265,8 @@ impl<'a> CompletionContext<'a> { self.mod_declaration_under_caret = find_node_at_offset::(&file_with_fake_ident, offset) .filter(|module| module.item_list().is_none()); + self.for_is_prev2 = for_is_prev2(syntax_element.clone()); + self.fn_is_prev = fn_is_prev(syntax_element.clone()); } fn fill( -- cgit v1.2.3