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/completion/src/render/macro_.rs | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'crates/completion/src') diff --git a/crates/completion/src/render/macro_.rs b/crates/completion/src/render/macro_.rs index 95408ff9a..0612591fd 100644 --- a/crates/completion/src/render/macro_.rs +++ b/crates/completion/src/render/macro_.rs @@ -39,20 +39,13 @@ 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; - } - let mut builder = CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), &self.label()) .kind(CompletionItemKind::Macro) .set_documentation(self.docs.clone()) .set_deprecated(self.ctx.is_deprecated(self.macro_)) .add_import(import_to_add) - .detail(self.detail()); + .detail(self.detail()?); let needs_bang = self.needs_bang(); builder = match self.ctx.snippet_cap() { @@ -95,10 +88,9 @@ impl<'a> MacroRender<'a> { format!("{}!", self.name) } - fn detail(&self) -> String { - #[allow(deprecated)] - let ast_node = self.macro_.source_old(self.ctx.db()).value; - macro_label(&ast_node) + fn detail(&self) -> Option { + let ast_node = self.macro_.source(self.ctx.db())?.value; + Some(macro_label(&ast_node)) } } -- cgit v1.2.3