From f78de3bb95acb996102a74b5b12d33054ba6d4c4 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Sat, 18 Apr 2020 19:26:35 +0800 Subject: [PATCH] Ignore proc-macro in completion --- crates/ra_hir/src/code_model.rs | 11 +++++++++++ crates/ra_ide/src/completion/presentation.rs | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 3801fce23a..6e0d89466b 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -759,6 +759,17 @@ impl MacroDef { pub fn name(self, db: &dyn HirDatabase) -> Option { self.source(db).value.name().map(|it| it.as_name()) } + + /// Indicate it is a proc-macro + pub fn is_proc_macro(&self) -> bool { + match self.id.kind { + hir_expand::MacroDefKind::Declarative => false, + hir_expand::MacroDefKind::BuiltIn(_) => false, + hir_expand::MacroDefKind::BuiltInDerive(_) => false, + hir_expand::MacroDefKind::BuiltInEager(_) => false, + hir_expand::MacroDefKind::CustomDerive(_) => true, + } + } } /// Invariant: `inner.as_assoc_item(db).is_some()` diff --git a/crates/ra_ide/src/completion/presentation.rs b/crates/ra_ide/src/completion/presentation.rs index 55f75b15aa..2189cef658 100644 --- a/crates/ra_ide/src/completion/presentation.rs +++ b/crates/ra_ide/src/completion/presentation.rs @@ -156,6 +156,12 @@ impl Completions { name: Option, macro_: hir::MacroDef, ) { + // FIXME: Currently proc-macro do not have ast-node, + // such that it does not have source + if macro_.is_proc_macro() { + return; + } + let name = match name { Some(it) => it, None => return,