mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
fix: Fix nested macro diagnostics pointing at macro expansion files
This commit is contained in:
parent
52bc15fc1f
commit
dc8254c6ab
4 changed files with 25 additions and 19 deletions
|
@ -1,5 +1,4 @@
|
|||
use hir::db::DefDatabase;
|
||||
use syntax::NodeOrToken;
|
||||
|
||||
use crate::{Diagnostic, DiagnosticsContext, Severity};
|
||||
|
||||
|
@ -19,16 +18,7 @@ pub(crate) fn unresolved_proc_macro(
|
|||
proc_attr_macros_enabled: bool,
|
||||
) -> Diagnostic {
|
||||
// Use more accurate position if available.
|
||||
let display_range = (|| {
|
||||
let precise_location = d.precise_location?;
|
||||
let root = ctx.sema.parse_or_expand(d.node.file_id)?;
|
||||
match root.covering_element(precise_location) {
|
||||
NodeOrToken::Node(it) => Some(ctx.sema.original_range(&it)),
|
||||
NodeOrToken::Token(it) => d.node.with_value(it).original_file_range_opt(ctx.sema.db),
|
||||
}
|
||||
})()
|
||||
.unwrap_or_else(|| ctx.sema.diagnostics_display_range(d.node.clone()))
|
||||
.range;
|
||||
let display_range = ctx.resolve_precise_location(&d.node, d.precise_location);
|
||||
|
||||
let config_enabled = match d.kind {
|
||||
hir::MacroKind::Attr => proc_macros_enabled && proc_attr_macros_enabled,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue