From 60a3785ac27d7361617977bd53e11f2859e97c7c Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 18 Dec 2020 10:26:17 +0800 Subject: Temp fixes panic caused by no ast for proc-macro --- crates/completion/src/render/macro_.rs | 1 + crates/hir/src/code_model.rs | 6 ++++++ crates/ide/src/display/navigation_target.rs | 10 +++++++++- crates/ide/src/hover.rs | 6 ++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/crates/completion/src/render/macro_.rs b/crates/completion/src/render/macro_.rs index 6cfbd6c9b..dac79592f 100644 --- a/crates/completion/src/render/macro_.rs +++ b/crates/completion/src/render/macro_.rs @@ -41,6 +41,7 @@ impl<'a> MacroRender<'a> { fn render(&self, import_to_add: Option) -> Option { // FIXME: Currently proc-macro do not have ast-node, // such that it does not have source + // more discussion: https://github.com/rust-analyzer/rust-analyzer/issues/6913 if self.macro_.is_proc_macro() { return None; } diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 42dc35b76..7ffa79996 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs @@ -977,6 +977,12 @@ impl MacroDef { /// XXX: this parses the file pub fn name(self, db: &dyn HirDatabase) -> Option { + // FIXME: Currently proc-macro do not have ast-node, + // such that it does not have source + // more discussion: https://github.com/rust-analyzer/rust-analyzer/issues/6913 + if self.is_proc_macro() { + return None; + } self.source(db).value.name().map(|it| it.as_name()) } diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs index 234f80a3a..73fc73619 100644 --- a/crates/ide/src/display/navigation_target.rs +++ b/crates/ide/src/display/navigation_target.rs @@ -176,7 +176,15 @@ impl ToNav for FileSymbol { impl TryToNav for Definition { fn try_to_nav(&self, db: &RootDatabase) -> Option { match self { - Definition::Macro(it) => Some(it.to_nav(db)), + Definition::Macro(it) => { + // FIXME: Currently proc-macro do not have ast-node, + // such that it does not have source + // more discussion: https://github.com/rust-analyzer/rust-analyzer/issues/6913 + if it.is_proc_macro() { + return None; + } + Some(it.to_nav(db)) + } Definition::Field(it) => Some(it.to_nav(db)), Definition::ModuleDef(it) => it.try_to_nav(db), Definition::SelfType(it) => Some(it.to_nav(db)), diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index ab017d2ad..c03dd74e4 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -324,6 +324,12 @@ fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option { let mod_path = definition_mod_path(db, &def); return match def { Definition::Macro(it) => { + // FIXME: Currently proc-macro do not have ast-node, + // such that it does not have source + // more discussion: https://github.com/rust-analyzer/rust-analyzer/issues/6913 + if it.is_proc_macro() { + return None; + } let label = macro_label(&it.source(db).value); from_def_source_labeled(db, it, Some(label), mod_path) } -- cgit v1.2.3