aboutsummaryrefslogtreecommitdiff
path: root/crates/ide
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-06-13 15:51:44 +0100
committerAleksey Kladov <[email protected]>2021-06-13 15:51:44 +0100
commit1e4aaee7bbc1d56698e70158aa35f578422623d9 (patch)
tree0d7a63a204895fb6c9f3425bb6fce9d6a46b1de5 /crates/ide
parentf85e383b94376d55bb5ee6be375ef3dc0006590f (diff)
internal: refactor unresolved proc macro diagnostic
Diffstat (limited to 'crates/ide')
-rw-r--r--crates/ide/src/diagnostics.rs17
-rw-r--r--crates/ide/src/diagnostics/inactive_code.rs6
-rw-r--r--crates/ide/src/diagnostics/unresolved_proc_macro.rs30
3 files changed, 42 insertions, 11 deletions
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs
index 634e6a043..f7965326d 100644
--- a/crates/ide/src/diagnostics.rs
+++ b/crates/ide/src/diagnostics.rs
@@ -8,6 +8,7 @@ mod unresolved_module;
8mod unresolved_extern_crate; 8mod unresolved_extern_crate;
9mod unresolved_import; 9mod unresolved_import;
10mod unresolved_macro_call; 10mod unresolved_macro_call;
11mod unresolved_proc_macro;
11mod inactive_code; 12mod inactive_code;
12mod missing_fields; 13mod missing_fields;
13 14
@@ -68,6 +69,11 @@ impl Diagnostic {
68 self 69 self
69 } 70 }
70 71
72 fn severity(mut self, severity: Severity) -> Diagnostic {
73 self.severity = severity;
74 self
75 }
76
71 fn error(range: TextRange, message: String) -> Self { 77 fn error(range: TextRange, message: String) -> Self {
72 Self { 78 Self {
73 message, 79 message,
@@ -178,16 +184,6 @@ pub(crate) fn diagnostics(
178 .with_code(Some(d.code())), 184 .with_code(Some(d.code())),
179 ); 185 );
180 }) 186 })
181 .on::<hir::diagnostics::UnresolvedProcMacro, _>(|d| {
182 // Use more accurate position if available.
183 let display_range = d
184 .precise_location
185 .unwrap_or_else(|| sema.diagnostics_display_range(d.display_source()).range);
186
187 // FIXME: it would be nice to tell the user whether proc macros are currently disabled
188 res.borrow_mut()
189 .push(Diagnostic::hint(display_range, d.message()).with_code(Some(d.code())));
190 })
191 .on::<hir::diagnostics::UnimplementedBuiltinMacro, _>(|d| { 187 .on::<hir::diagnostics::UnimplementedBuiltinMacro, _>(|d| {
192 let display_range = sema.diagnostics_display_range(d.display_source()).range; 188 let display_range = sema.diagnostics_display_range(d.display_source()).range;
193 res.borrow_mut() 189 res.borrow_mut()
@@ -231,6 +227,7 @@ pub(crate) fn diagnostics(
231 AnyDiagnostic::UnresolvedExternCrate(d) => unresolved_extern_crate::unresolved_extern_crate(&ctx, &d), 227 AnyDiagnostic::UnresolvedExternCrate(d) => unresolved_extern_crate::unresolved_extern_crate(&ctx, &d),
232 AnyDiagnostic::UnresolvedImport(d) => unresolved_import::unresolved_import(&ctx, &d), 228 AnyDiagnostic::UnresolvedImport(d) => unresolved_import::unresolved_import(&ctx, &d),
233 AnyDiagnostic::UnresolvedMacroCall(d) => unresolved_macro_call::unresolved_macro_call(&ctx, &d), 229 AnyDiagnostic::UnresolvedMacroCall(d) => unresolved_macro_call::unresolved_macro_call(&ctx, &d),
230 AnyDiagnostic::UnresolvedProcMacro(d) => unresolved_proc_macro::unresolved_proc_macro(&ctx, &d),
234 AnyDiagnostic::MissingFields(d) => missing_fields::missing_fields(&ctx, &d), 231 AnyDiagnostic::MissingFields(d) => missing_fields::missing_fields(&ctx, &d),
235 232
236 AnyDiagnostic::InactiveCode(d) => match inactive_code::inactive_code(&ctx, &d) { 233 AnyDiagnostic::InactiveCode(d) => match inactive_code::inactive_code(&ctx, &d) {
diff --git a/crates/ide/src/diagnostics/inactive_code.rs b/crates/ide/src/diagnostics/inactive_code.rs
index 52f97cb4c..afe333204 100644
--- a/crates/ide/src/diagnostics/inactive_code.rs
+++ b/crates/ide/src/diagnostics/inactive_code.rs
@@ -1,7 +1,10 @@
1use cfg::DnfExpr; 1use cfg::DnfExpr;
2use stdx::format_to; 2use stdx::format_to;
3 3
4use crate::diagnostics::{Diagnostic, DiagnosticsContext}; 4use crate::{
5 diagnostics::{Diagnostic, DiagnosticsContext},
6 Severity,
7};
5 8
6// Diagnostic: inactive-code 9// Diagnostic: inactive-code
7// 10//
@@ -27,6 +30,7 @@ pub(super) fn inactive_code(
27 message, 30 message,
28 ctx.sema.diagnostics_display_range(d.node.clone()).range, 31 ctx.sema.diagnostics_display_range(d.node.clone()).range,
29 ) 32 )
33 .severity(Severity::WeakWarning)
30 .with_unused(true); 34 .with_unused(true);
31 Some(res) 35 Some(res)
32} 36}
diff --git a/crates/ide/src/diagnostics/unresolved_proc_macro.rs b/crates/ide/src/diagnostics/unresolved_proc_macro.rs
new file mode 100644
index 000000000..3dc6ab451
--- /dev/null
+++ b/crates/ide/src/diagnostics/unresolved_proc_macro.rs
@@ -0,0 +1,30 @@
1use 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`).
15pub(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}