]> git.lizzy.rs Git - rust.git/blob - crates/ide/src/diagnostics/unresolved_proc_macro.rs
internal: use cov-mark rather than bailing out diagnostic
[rust.git] / crates / ide / src / diagnostics / unresolved_proc_macro.rs
1 use crate::{
2     diagnostics::{Diagnostic, DiagnosticsContext},
3     Severity,
4 };
5
6 // Diagnostic: unresolved-proc-macro
7 //
8 // This diagnostic is shown when a procedural macro can not be found. This usually means that
9 // procedural macro support is simply disabled (and hence is only a weak hint instead of an error),
10 // but can also indicate project setup problems.
11 //
12 // If you are seeing a lot of "proc macro not expanded" warnings, you can add this option to the
13 // `rust-analyzer.diagnostics.disabled` list to prevent them from showing. Alternatively you can
14 // enable support for procedural macros (see `rust-analyzer.procMacro.enable`).
15 pub(super) fn unresolved_proc_macro(
16     ctx: &DiagnosticsContext<'_>,
17     d: &hir::UnresolvedProcMacro,
18 ) -> Diagnostic {
19     // Use more accurate position if available.
20     let display_range = d
21         .precise_location
22         .unwrap_or_else(|| ctx.sema.diagnostics_display_range(d.node.clone()).range);
23     // FIXME: it would be nice to tell the user whether proc macros are currently disabled
24     let message = match &d.macro_name {
25         Some(name) => format!("proc macro `{}` not expanded", name),
26         None => "proc macro not expanded".to_string(),
27     };
28
29     Diagnostic::new("unresolved-proc-macro", message, display_range).severity(Severity::WeakWarning)
30 }