mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
More precise proc-macro errors
This commit is contained in:
parent
4f2a67b26f
commit
0e4eb647f6
4 changed files with 31 additions and 15 deletions
|
@ -8,20 +8,25 @@ use crate::{Diagnostic, DiagnosticsContext, Severity};
|
|||
//
|
||||
// If you are seeing a lot of "proc macro not expanded" warnings, you can add this option to the
|
||||
// `rust-analyzer.diagnostics.disabled` list to prevent them from showing. Alternatively you can
|
||||
// enable support for procedural macros (see `rust-analyzer.procMacro.enable`).
|
||||
// enable support for procedural macros (see `rust-analyzer.procMacro.attributes.enable`).
|
||||
pub(crate) fn unresolved_proc_macro(
|
||||
ctx: &DiagnosticsContext<'_>,
|
||||
d: &hir::UnresolvedProcMacro,
|
||||
attr_proc_macros_enabled: bool,
|
||||
) -> Diagnostic {
|
||||
// Use more accurate position if available.
|
||||
let display_range = d
|
||||
.precise_location
|
||||
.unwrap_or_else(|| ctx.sema.diagnostics_display_range(d.node.clone()).range);
|
||||
// FIXME: it would be nice to tell the user whether proc macros are currently disabled
|
||||
let message = match &d.macro_name {
|
||||
Some(name) => format!("proc macro `{}` not expanded", name),
|
||||
None => "proc macro not expanded".to_string(),
|
||||
};
|
||||
let message = format!(
|
||||
"{message}{}",
|
||||
if attr_proc_macros_enabled { "" } else { " (attribute macro expansion is disabled)" }
|
||||
);
|
||||
|
||||
Diagnostic::new("unresolved-proc-macro", message, display_range).severity(Severity::WeakWarning)
|
||||
Diagnostic::new("unresolved-proc-macro", message, display_range)
|
||||
.severity(if attr_proc_macros_enabled { Severity::Error } else { Severity::WeakWarning })
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue