From f41c98342476087d0a4387e7d337ce2d897e0346 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Thu, 27 May 2021 04:34:21 +0200 Subject: Don't complete non-macro item paths in impls and modules --- crates/ide_completion/src/context.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'crates/ide_completion/src/context.rs') diff --git a/crates/ide_completion/src/context.rs b/crates/ide_completion/src/context.rs index 66577df94..b7e116dba 100644 --- a/crates/ide_completion/src/context.rs +++ b/crates/ide_completion/src/context.rs @@ -127,6 +127,7 @@ pub(crate) struct CompletionContext<'a> { no_completion_required: bool, } + impl<'a> CompletionContext<'a> { pub(super) fn new( db: &'a RootDatabase, @@ -281,21 +282,25 @@ impl<'a> CompletionContext<'a> { self.previous_token.as_ref().map_or(false, |tok| tok.kind() == kind) } - pub(crate) fn has_impl_or_trait_parent(&self) -> bool { + pub(crate) fn expects_assoc_item(&self) -> bool { matches!( self.completion_location, Some(ImmediateLocation::Trait) | Some(ImmediateLocation::Impl) ) } - pub(crate) fn has_block_expr_parent(&self) -> bool { - matches!(self.completion_location, Some(ImmediateLocation::BlockExpr)) + pub(crate) fn expects_non_trait_assoc_item(&self) -> bool { + matches!(self.completion_location, Some(ImmediateLocation::Impl)) } - pub(crate) fn has_item_list_parent(&self) -> bool { + pub(crate) fn expects_item(&self) -> bool { matches!(self.completion_location, Some(ImmediateLocation::ItemList)) } + pub(crate) fn has_block_expr_parent(&self) -> bool { + matches!(self.completion_location, Some(ImmediateLocation::BlockExpr)) + } + pub(crate) fn has_ident_or_ref_pat_parent(&self) -> bool { matches!( self.completion_location, @@ -303,11 +308,7 @@ impl<'a> CompletionContext<'a> { ) } - pub(crate) fn has_impl_parent(&self) -> bool { - matches!(self.completion_location, Some(ImmediateLocation::Impl)) - } - - pub(crate) fn has_field_list_parent(&self) -> bool { + pub(crate) fn expect_record_field(&self) -> bool { matches!(self.completion_location, Some(ImmediateLocation::RecordFieldList)) } @@ -320,10 +321,10 @@ impl<'a> CompletionContext<'a> { || self.record_pat_syntax.is_some() || self.attribute_under_caret.is_some() || self.mod_declaration_under_caret.is_some() - || self.has_impl_or_trait_parent() } fn fill_keyword_patterns(&mut self, file_with_fake_ident: &SyntaxNode, offset: TextSize) { + dbg!(file_with_fake_ident); let fake_ident_token = file_with_fake_ident.token_at_offset(offset).right_biased().unwrap(); let syntax_element = NodeOrToken::Token(fake_ident_token); self.previous_token = previous_token(syntax_element.clone()); -- cgit v1.2.3