]> git.lizzy.rs Git - rust.git/commitdiff
Simplify
authorLukas Wirth <lukastw97@gmail.com>
Tue, 10 May 2022 12:31:28 +0000 (14:31 +0200)
committerLukas Wirth <lukastw97@gmail.com>
Tue, 10 May 2022 12:31:28 +0000 (14:31 +0200)
crates/ide-completion/src/context.rs
crates/ide-completion/src/render.rs
crates/ide-completion/src/render/macro_.rs

index 5342c481e3651a0c26ef02e8aa6ee97eacdf5142..f6b8962df631c65e23ef8f0ef8dd0500ecd2a10a 100644 (file)
@@ -326,6 +326,7 @@ pub(crate) fn expects_item(&self) -> bool {
         matches!(self.completion_location, Some(ImmediateLocation::ItemList))
     }
 
+    // FIXME: This shouldn't exist
     pub(crate) fn expects_generic_arg(&self) -> bool {
         matches!(self.completion_location, Some(ImmediateLocation::GenericArgList(_)))
     }
@@ -395,10 +396,6 @@ pub(crate) fn expects_type(&self) -> bool {
         matches!(self.path_context(), Some(PathCompletionCtx { kind: PathKind::Type, .. }))
     }
 
-    pub(crate) fn path_is_call(&self) -> bool {
-        self.path_context().map_or(false, |it| it.has_call_parens)
-    }
-
     pub(crate) fn is_non_trivial_path(&self) -> bool {
         matches!(
             self.path_context(),
@@ -417,10 +414,6 @@ pub(crate) fn path_kind(&self) -> Option<PathKind> {
         self.path_context().map(|it| it.kind)
     }
 
-    pub(crate) fn is_immediately_after_macro_bang(&self) -> bool {
-        self.token.kind() == BANG && self.token.parent().map_or(false, |it| it.kind() == MACRO_CALL)
-    }
-
     /// Checks if an item is visible and not `doc(hidden)` at the completion site.
     pub(crate) fn is_visible<I>(&self, item: &I) -> Visible
     where
index 01c9bfdb85ce37fad6303fdcb21b7dacb95749e0..8bb0bc198ae9272c6861afcae5acd29f546ac295 100644 (file)
@@ -65,6 +65,19 @@ fn completion_relevance(&self) -> CompletionRelevance {
         }
     }
 
+    fn is_immediately_after_macro_bang(&self) -> bool {
+        self.completion.token.kind() == SyntaxKind::BANG
+            && self
+                .completion
+                .token
+                .parent()
+                .map_or(false, |it| it.kind() == SyntaxKind::MACRO_CALL)
+    }
+
+    pub(crate) fn path_is_call(&self) -> bool {
+        self.completion.path_context().map_or(false, |it| it.has_call_parens)
+    }
+
     fn is_deprecated(&self, def: impl HasAttrs) -> bool {
         let attrs = def.attrs(self.db());
         attrs.by_key("deprecated").exists() || attrs.by_key("rustc_deprecated").exists()
index 9c51a6311a4dbc5a736fc59727be5acc14e6a688..5c862f013a75e99656a410ce9e6ca6bbfb3bc91c 100644 (file)
@@ -20,7 +20,7 @@ fn render(
     name: hir::Name,
     macro_: hir::Macro,
 ) -> Builder {
-    let source_range = if completion.is_immediately_after_macro_bang() {
+    let source_range = if ctx.is_immediately_after_macro_bang() {
         cov_mark::hit!(completes_macro_call_if_cursor_at_bang_token);
         completion.token.parent().map_or_else(|| ctx.source_range(), |it| it.text_range())
     } else {
@@ -52,7 +52,7 @@ fn render(
 
     let name = &*name;
     match ctx.snippet_cap() {
-        Some(cap) if needs_bang && !completion.path_is_call() => {
+        Some(cap) if needs_bang && !ctx.path_is_call() => {
             let snippet = format!("{}!{}$0{}", name, bra, ket);
             let lookup = banged_name(name);
             item.insert_snippet(cap, snippet).lookup_by(lookup);