Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide_diagnostics/src/handlers/unresolved_macro_call.rs')
-rw-r--r--crates/ide_diagnostics/src/handlers/unresolved_macro_call.rs22
1 files changed, 13 insertions, 9 deletions
diff --git a/crates/ide_diagnostics/src/handlers/unresolved_macro_call.rs b/crates/ide_diagnostics/src/handlers/unresolved_macro_call.rs
index ea0f35501b..831d082bc7 100644
--- a/crates/ide_diagnostics/src/handlers/unresolved_macro_call.rs
+++ b/crates/ide_diagnostics/src/handlers/unresolved_macro_call.rs
@@ -1,5 +1,5 @@
use hir::{db::AstDatabase, InFile};
-use syntax::{AstNode, SyntaxNodePtr};
+use syntax::{ast, AstNode, SyntaxNodePtr};
use crate::{Diagnostic, DiagnosticsContext};
@@ -12,19 +12,23 @@ pub(crate) fn unresolved_macro_call(
d: &hir::UnresolvedMacroCall,
) -> Diagnostic {
let last_path_segment = ctx.sema.db.parse_or_expand(d.macro_call.file_id).and_then(|root| {
- d.macro_call
- .value
- .to_node(&root)
- .path()
- .and_then(|it| it.segment())
- .and_then(|it| it.name_ref())
- .map(|it| InFile::new(d.macro_call.file_id, SyntaxNodePtr::new(it.syntax())))
+ let node = d.macro_call.value.to_node(&root);
+ if let Some(macro_call) = ast::MacroCall::cast(node) {
+ macro_call
+ .path()
+ .and_then(|it| it.segment())
+ .and_then(|it| it.name_ref())
+ .map(|it| InFile::new(d.macro_call.file_id, SyntaxNodePtr::new(it.syntax())))
+ } else {
+ None
+ }
});
let diagnostics = last_path_segment.unwrap_or_else(|| d.macro_call.clone().map(|it| it.into()));
+ let bang = if d.is_bang { "!" } else { "" };
Diagnostic::new(
"unresolved-macro-call",
- format!("unresolved macro `{}!`", d.path),
+ format!("unresolved macro `{}{}`", d.path, bang),
ctx.sema.diagnostics_display_range(diagnostics).range,
)
.experimental()