From 76fd1b316f38b59991316d5b97582c0203728738 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 2 Jun 2021 15:25:02 +0200 Subject: 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(-) (limited to 'crates') 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 202e71215..781b96ff1 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 @@ use crate::{CompletionContext, Completions}; // 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 defc25b00..6e6a6eb92 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 eeb4333f8..6f685c02f 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 @@ impl<'a> CompletionContext<'a> { 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 @@ impl<'a> CompletionContext<'a> { 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 bf3a3f61e..080898aef 100644 --- a/crates/ide_completion/src/patterns.rs +++ b/crates/ide_completion/src/patterns.rs @@ -13,7 +13,7 @@ use syntax::{ #[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, -- cgit v1.2.3