From 76fd1b316f38b59991316d5b97582c0203728738 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 2 Jun 2021 15:25:02 +0200 Subject: [PATCH] Remove obsolete is_new_item field on CompletionContext --- .../src/completions/macro_in_item_position.rs | 2 +- crates/ide_completion/src/completions/snippet.rs | 2 +- crates/ide_completion/src/context.rs | 14 +------------- crates/ide_completion/src/patterns.rs | 4 ++-- 4 files changed, 5 insertions(+), 17 deletions(-) diff --git a/crates/ide_completion/src/completions/macro_in_item_position.rs b/crates/ide_completion/src/completions/macro_in_item_position.rs index 202e71215a4..781b96ff185 100644 --- a/crates/ide_completion/src/completions/macro_in_item_position.rs +++ b/crates/ide_completion/src/completions/macro_in_item_position.rs @@ -5,7 +5,7 @@ // Ideally this should be removed and moved into `(un)qualified_path` respectively pub(crate) fn complete_macro_in_item_position(acc: &mut Completions, ctx: &CompletionContext) { // Show only macros in top level. - if !ctx.is_new_item { + if !ctx.expects_item() { return; } diff --git a/crates/ide_completion/src/completions/snippet.rs b/crates/ide_completion/src/completions/snippet.rs index defc25b0089..6e6a6eb92ef 100644 --- a/crates/ide_completion/src/completions/snippet.rs +++ b/crates/ide_completion/src/completions/snippet.rs @@ -29,7 +29,7 @@ pub(crate) fn complete_expr_snippet(acc: &mut Completions, ctx: &CompletionConte } pub(crate) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionContext) { - if !ctx.is_new_item { + if !ctx.expects_item() { return; } let cap = match ctx.config.snippet_cap { diff --git a/crates/ide_completion/src/context.rs b/crates/ide_completion/src/context.rs index eeb4333f851..6f685c02f38 100644 --- a/crates/ide_completion/src/context.rs +++ b/crates/ide_completion/src/context.rs @@ -78,8 +78,6 @@ pub(crate) struct CompletionContext<'a> { pub(super) can_be_stmt: bool, /// `true` if we expect an expression at the cursor position. pub(super) is_expr: bool, - /// Something is typed at the "top" level, in module or impl/trait. - pub(super) is_new_item: bool, /// If this is a call (method or function) in particular, i.e. the () are already there. pub(super) is_call: bool, /// Like `is_call`, but for tuple patterns. @@ -155,7 +153,6 @@ pub(super) fn new( path_qual: None, can_be_stmt: false, is_expr: false, - is_new_item: false, is_call: false, is_pattern_call: false, is_macro_call: false, @@ -552,16 +549,7 @@ fn classify_name_ref(&mut self, original_file: &SyntaxNode, name_ref: ast::NameR self.name_ref_syntax = find_node_at_offset(original_file, name_ref.syntax().text_range().start()); - let name_range = name_ref.syntax().text_range(); - let top_node = name_ref - .syntax() - .ancestors() - .take_while(|it| it.text_range() == name_range) - .last() - .unwrap(); - - if matches!(top_node.parent().map(|it| it.kind()), Some(SOURCE_FILE) | Some(ITEM_LIST)) { - self.is_new_item = true; + if matches!(self.completion_location, Some(ImmediateLocation::ItemList)) { return; } diff --git a/crates/ide_completion/src/patterns.rs b/crates/ide_completion/src/patterns.rs index bf3a3f61ebb..080898aef00 100644 --- a/crates/ide_completion/src/patterns.rs +++ b/crates/ide_completion/src/patterns.rs @@ -13,7 +13,7 @@ #[cfg(test)] use crate::test_utils::{check_pattern_is_applicable, check_pattern_is_not_applicable}; -/// Direct parent container of the cursor position +/// Immediate previous node to what we are completing. #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub(crate) enum ImmediatePrevSibling { IfExpr, @@ -21,7 +21,7 @@ pub(crate) enum ImmediatePrevSibling { ImplDefType, } -/// Direct parent container of the cursor position +/// Direct parent "thing" of what we are currently completing. #[derive(Clone, Debug, PartialEq, Eq)] pub(crate) enum ImmediateLocation { Use, -- 2.44.0