]> git.lizzy.rs Git - rust.git/commitdiff
Remove obsolete is_new_item field on CompletionContext
authorLukas Wirth <lukastw97@gmail.com>
Wed, 2 Jun 2021 13:25:02 +0000 (15:25 +0200)
committerLukas Wirth <lukastw97@gmail.com>
Wed, 2 Jun 2021 15:12:36 +0000 (17:12 +0200)
crates/ide_completion/src/completions/macro_in_item_position.rs
crates/ide_completion/src/completions/snippet.rs
crates/ide_completion/src/context.rs
crates/ide_completion/src/patterns.rs

index 202e71215a460f6d0570adf3c81616f3923eb307..781b96ff185a17aa35714a02bcdab8b32d0ab0d5 100644 (file)
@@ -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;
     }
 
index defc25b00892b039407a650f832efac72ca9e901..6e6a6eb92ef4dc7d7c6484aa476e73cc57db763e 100644 (file)
@@ -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 {
index eeb4333f851e7dc25e2dd0116487638d179612fe..6f685c02f3857514c089f09e9fc88ce8bc5f3d33 100644 (file)
@@ -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;
         }
 
index bf3a3f61ebbb8578ea5807270667d6eadb5c19cc..080898aef00467c550bbabefa9eeabe0fedb02ad 100644 (file)
@@ -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,