mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
fix: Check for the correct proc-macro settings in missing proc-macro diagnostics
This commit is contained in:
parent
7db73875ac
commit
325ceaef19
6 changed files with 40 additions and 17 deletions
|
@ -12,21 +12,36 @@ use crate::{Diagnostic, DiagnosticsContext, Severity};
|
|||
pub(crate) fn unresolved_proc_macro(
|
||||
ctx: &DiagnosticsContext<'_>,
|
||||
d: &hir::UnresolvedProcMacro,
|
||||
attr_proc_macros_enabled: bool,
|
||||
proc_macros_enabled: bool,
|
||||
proc_attr_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);
|
||||
|
||||
let config_enabled = match d.kind {
|
||||
hir::MacroKind::Attr => proc_macros_enabled && proc_attr_macros_enabled,
|
||||
_ => proc_macros_enabled,
|
||||
};
|
||||
|
||||
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)" }
|
||||
);
|
||||
let (message, severity) = if config_enabled {
|
||||
(message, Severity::Error)
|
||||
} else {
|
||||
let message = match d.kind {
|
||||
hir::MacroKind::Attr if proc_macros_enabled => {
|
||||
format!("{message}{}", " (attribute macro expansion is disabled)")
|
||||
}
|
||||
_ => {
|
||||
format!("{message}{}", " (proc-macro expansion is disabled)")
|
||||
}
|
||||
};
|
||||
(message, Severity::WeakWarning)
|
||||
};
|
||||
|
||||
Diagnostic::new("unresolved-proc-macro", message, display_range)
|
||||
.severity(if attr_proc_macros_enabled { Severity::Error } else { Severity::WeakWarning })
|
||||
Diagnostic::new("unresolved-proc-macro", message, display_range).severity(severity)
|
||||
}
|
||||
|
|
|
@ -139,7 +139,8 @@ impl Default for ExprFillDefaultMode {
|
|||
|
||||
#[derive(Default, Debug, Clone)]
|
||||
pub struct DiagnosticsConfig {
|
||||
pub attr_proc_macros_enabled: bool,
|
||||
pub proc_macros_enabled: bool,
|
||||
pub proc_attr_macros_enabled: bool,
|
||||
pub disable_experimental: bool,
|
||||
pub disabled: FxHashSet<String>,
|
||||
pub expr_fill_default: ExprFillDefaultMode,
|
||||
|
@ -205,7 +206,7 @@ pub fn diagnostics(
|
|||
AnyDiagnostic::UnresolvedImport(d) => handlers::unresolved_import::unresolved_import(&ctx, &d),
|
||||
AnyDiagnostic::UnresolvedMacroCall(d) => handlers::unresolved_macro_call::unresolved_macro_call(&ctx, &d),
|
||||
AnyDiagnostic::UnresolvedModule(d) => handlers::unresolved_module::unresolved_module(&ctx, &d),
|
||||
AnyDiagnostic::UnresolvedProcMacro(d) => handlers::unresolved_proc_macro::unresolved_proc_macro(&ctx, &d, config.attr_proc_macros_enabled),
|
||||
AnyDiagnostic::UnresolvedProcMacro(d) => handlers::unresolved_proc_macro::unresolved_proc_macro(&ctx, &d, config.proc_macros_enabled, config.proc_attr_macros_enabled),
|
||||
AnyDiagnostic::InvalidDeriveTarget(d) => handlers::invalid_derive_target::invalid_derive_target(&ctx, &d),
|
||||
|
||||
AnyDiagnostic::InactiveCode(d) => match handlers::inactive_code::inactive_code(&ctx, &d) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue