Skip to content

Commit f4929fa

Browse files
Merge #6901
6901: Temp fixes panic caused by no ast for proc-macro r=maklad a=edwin0cheng There are some panic when hover/goto definition for proc-macro. It is because in current design, we don't have `ast-node` for proc-macro and then it trigger [this](https://github.com/rust-analyzer/rust-analyzer/blob/479d1f7eec22c3564867223e2093f14774092528/crates/hir/src/has_source.rs#L116) line to panic. This PR is a temp fix for all of these similar to https://github.com/rust-analyzer/rust-analyzer/blob/bd4c352831662762ee7a66da77ec9adf623b0a0a/crates/completion/src/render/macro_.rs#L42 Co-authored-by: Edwin Cheng <[email protected]>
2 parents 37e5f19 + 60a3785 commit f4929fa

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

crates/completion/src/render/macro_.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ impl<'a> MacroRender<'a> {
4141
fn render(&self, import_to_add: Option<ImportEdit>) -> Option<CompletionItem> {
4242
// FIXME: Currently proc-macro do not have ast-node,
4343
// such that it does not have source
44+
// more discussion: https://github.com/rust-analyzer/rust-analyzer/issues/6913
4445
if self.macro_.is_proc_macro() {
4546
return None;
4647
}

crates/hir/src/code_model.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,12 @@ impl MacroDef {
983983

984984
/// XXX: this parses the file
985985
pub fn name(self, db: &dyn HirDatabase) -> Option<Name> {
986+
// FIXME: Currently proc-macro do not have ast-node,
987+
// such that it does not have source
988+
// more discussion: https://github.com/rust-analyzer/rust-analyzer/issues/6913
989+
if self.is_proc_macro() {
990+
return None;
991+
}
986992
self.source(db).value.name().map(|it| it.as_name())
987993
}
988994

crates/ide/src/display/navigation_target.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,15 @@ impl ToNav for FileSymbol {
155155
impl TryToNav for Definition {
156156
fn try_to_nav(&self, db: &RootDatabase) -> Option<NavigationTarget> {
157157
match self {
158-
Definition::Macro(it) => Some(it.to_nav(db)),
158+
Definition::Macro(it) => {
159+
// FIXME: Currently proc-macro do not have ast-node,
160+
// such that it does not have source
161+
// more discussion: https://github.com/rust-analyzer/rust-analyzer/issues/6913
162+
if it.is_proc_macro() {
163+
return None;
164+
}
165+
Some(it.to_nav(db))
166+
}
159167
Definition::Field(it) => Some(it.to_nav(db)),
160168
Definition::ModuleDef(it) => it.try_to_nav(db),
161169
Definition::SelfType(it) => Some(it.to_nav(db)),

crates/ide/src/hover.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,12 @@ fn hover_for_definition(db: &RootDatabase, def: Definition) -> Option<Markup> {
324324
let mod_path = definition_mod_path(db, &def);
325325
return match def {
326326
Definition::Macro(it) => {
327+
// FIXME: Currently proc-macro do not have ast-node,
328+
// such that it does not have source
329+
// more discussion: https://github.com/rust-analyzer/rust-analyzer/issues/6913
330+
if it.is_proc_macro() {
331+
return None;
332+
}
327333
let label = macro_label(&it.source(db).value);
328334
from_def_source_labeled(db, it, Some(label), mod_path)
329335
}

0 commit comments

Comments
 (0)