aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ide_completion/src/completions/macro_in_item_position.rs2
-rw-r--r--crates/ide_completion/src/completions/snippet.rs2
-rw-r--r--crates/ide_completion/src/context.rs14
-rw-r--r--crates/ide_completion/src/patterns.rs4
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 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};
5// Ideally this should be removed and moved into `(un)qualified_path` respectively 5// Ideally this should be removed and moved into `(un)qualified_path` respectively
6pub(crate) fn complete_macro_in_item_position(acc: &mut Completions, ctx: &CompletionContext) { 6pub(crate) fn complete_macro_in_item_position(acc: &mut Completions, ctx: &CompletionContext) {
7 // Show only macros in top level. 7 // Show only macros in top level.
8 if !ctx.is_new_item { 8 if !ctx.expects_item() {
9 return; 9 return;
10 } 10 }
11 11
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
29} 29}
30 30
31pub(crate) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionContext) { 31pub(crate) fn complete_item_snippet(acc: &mut Completions, ctx: &CompletionContext) {
32 if !ctx.is_new_item { 32 if !ctx.expects_item() {
33 return; 33 return;
34 } 34 }
35 let cap = match ctx.config.snippet_cap { 35 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> {
78 pub(super) can_be_stmt: bool, 78 pub(super) can_be_stmt: bool,
79 /// `true` if we expect an expression at the cursor position. 79 /// `true` if we expect an expression at the cursor position.
80 pub(super) is_expr: bool, 80 pub(super) is_expr: bool,
81 /// Something is typed at the "top" level, in module or impl/trait.
82 pub(super) is_new_item: bool,
83 /// If this is a call (method or function) in particular, i.e. the () are already there. 81 /// If this is a call (method or function) in particular, i.e. the () are already there.
84 pub(super) is_call: bool, 82 pub(super) is_call: bool,
85 /// Like `is_call`, but for tuple patterns. 83 /// Like `is_call`, but for tuple patterns.
@@ -155,7 +153,6 @@ impl<'a> CompletionContext<'a> {
155 path_qual: None, 153 path_qual: None,
156 can_be_stmt: false, 154 can_be_stmt: false,
157 is_expr: false, 155 is_expr: false,
158 is_new_item: false,
159 is_call: false, 156 is_call: false,
160 is_pattern_call: false, 157 is_pattern_call: false,
161 is_macro_call: false, 158 is_macro_call: false,
@@ -552,16 +549,7 @@ impl<'a> CompletionContext<'a> {
552 self.name_ref_syntax = 549 self.name_ref_syntax =
553 find_node_at_offset(original_file, name_ref.syntax().text_range().start()); 550 find_node_at_offset(original_file, name_ref.syntax().text_range().start());
554 551
555 let name_range = name_ref.syntax().text_range(); 552 if matches!(self.completion_location, Some(ImmediateLocation::ItemList)) {
556 let top_node = name_ref
557 .syntax()
558 .ancestors()
559 .take_while(|it| it.text_range() == name_range)
560 .last()
561 .unwrap();
562
563 if matches!(top_node.parent().map(|it| it.kind()), Some(SOURCE_FILE) | Some(ITEM_LIST)) {
564 self.is_new_item = true;
565 return; 553 return;
566 } 554 }
567 555
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::{
13#[cfg(test)] 13#[cfg(test)]
14use crate::test_utils::{check_pattern_is_applicable, check_pattern_is_not_applicable}; 14use crate::test_utils::{check_pattern_is_applicable, check_pattern_is_not_applicable};
15 15
16/// Direct parent container of the cursor position 16/// Immediate previous node to what we are completing.
17#[derive(Copy, Clone, Debug, PartialEq, Eq)] 17#[derive(Copy, Clone, Debug, PartialEq, Eq)]
18pub(crate) enum ImmediatePrevSibling { 18pub(crate) enum ImmediatePrevSibling {
19 IfExpr, 19 IfExpr,
@@ -21,7 +21,7 @@ pub(crate) enum ImmediatePrevSibling {
21 ImplDefType, 21 ImplDefType,
22} 22}
23 23
24/// Direct parent container of the cursor position 24/// Direct parent "thing" of what we are currently completing.
25#[derive(Clone, Debug, PartialEq, Eq)] 25#[derive(Clone, Debug, PartialEq, Eq)]
26pub(crate) enum ImmediateLocation { 26pub(crate) enum ImmediateLocation {
27 Use, 27 Use,