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.rs | 22 |
1 files changed, 5 insertions, 17 deletions
diff --git a/crates/ide-diagnostics/src/handlers/unresolved_macro_call.rs b/crates/ide-diagnostics/src/handlers/unresolved_macro_call.rs index 831d082bc7..4b43124757 100644 --- a/crates/ide-diagnostics/src/handlers/unresolved_macro_call.rs +++ b/crates/ide-diagnostics/src/handlers/unresolved_macro_call.rs @@ -1,6 +1,3 @@ -use hir::{db::AstDatabase, InFile}; -use syntax::{ast, AstNode, SyntaxNodePtr}; - use crate::{Diagnostic, DiagnosticsContext}; // Diagnostic: unresolved-macro-call @@ -11,25 +8,16 @@ pub(crate) fn unresolved_macro_call( ctx: &DiagnosticsContext<'_>, d: &hir::UnresolvedMacroCall, ) -> Diagnostic { - let last_path_segment = ctx.sema.db.parse_or_expand(d.macro_call.file_id).and_then(|root| { - 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())); + // Use more accurate position if available. + let display_range = d + .precise_location + .unwrap_or_else(|| ctx.sema.diagnostics_display_range(d.macro_call.clone()).range); let bang = if d.is_bang { "!" } else { "" }; Diagnostic::new( "unresolved-macro-call", format!("unresolved macro `{}{}`", d.path, bang), - ctx.sema.diagnostics_display_range(diagnostics).range, + display_range, ) .experimental() } |