From 14d0db0759c5b8e1d085ebab03a8b944a8921f2e Mon Sep 17 00:00:00 2001 From: Nick Spain Date: Fri, 1 Jan 2021 14:14:09 +1100 Subject: HasSource::source_old -> HasSource::source for places where proc-macros were special cased In #6901 some special case handling for proc-macros was introduced to prevent panicing as they have no AST. Now the new HasSource::source method is used that returns an option. Generally this was a pretty trivial change, the only thing of much interest is that `hir::MacroDef` now implements `TryToNav` not `ToNav` as this allows us to handle `HasSource::source` now returning an option. --- crates/ide/src/display/navigation_target.rs | 19 +++++-------------- crates/ide/src/hover.rs | 9 +-------- 2 files changed, 6 insertions(+), 22 deletions(-) (limited to 'crates/ide') diff --git a/crates/ide/src/display/navigation_target.rs b/crates/ide/src/display/navigation_target.rs index efa0418ad..5dc3f4128 100644 --- a/crates/ide/src/display/navigation_target.rs +++ b/crates/ide/src/display/navigation_target.rs @@ -210,15 +210,7 @@ impl ToNav for FileSymbol { impl TryToNav for Definition { fn try_to_nav(&self, db: &RootDatabase) -> Option { match self { - 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::Macro(it) => it.try_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)), @@ -366,10 +358,9 @@ impl ToNav for hir::Field { } } -impl ToNav for hir::MacroDef { - fn to_nav(&self, db: &RootDatabase) -> NavigationTarget { - #[allow(deprecated)] - let src = self.source_old(db); +impl TryToNav for hir::MacroDef { + fn try_to_nav(&self, db: &RootDatabase) -> Option { + let src = self.source(db)?; log::debug!("nav target {:#?}", src.value.syntax()); let mut res = NavigationTarget::from_named( db, @@ -377,7 +368,7 @@ impl ToNav for hir::MacroDef { SymbolKind::Macro, ); res.docs = self.docs(db); - res + Some(res) } } diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index c192e3ed7..a18dcdd8e 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -327,14 +327,7 @@ 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; - } - #[allow(deprecated)] - let label = macro_label(&it.source_old(db).value); + let label = macro_label(&it.source(db)?.value); from_def_source_labeled(db, it, Some(label), mod_path) } Definition::Field(def) => { -- cgit v1.2.3