diff options
author | Aleksey Kladov <[email protected]> | 2021-06-13 17:35:30 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-06-13 17:35:30 +0100 |
commit | d3621eeb02652038a8185f60d78fb4791a732dc6 (patch) | |
tree | 0e200e563949977ffd0a857555d4ff874ab758dd | |
parent | dec207f56a7b16075f68dcb89138d93a7eecdf43 (diff) |
internal: refactor unimplemented builtin macro diagnostic
-rw-r--r-- | crates/hir/src/diagnostics.rs | 30 | ||||
-rw-r--r-- | crates/hir/src/lib.rs | 8 | ||||
-rw-r--r-- | crates/ide/src/diagnostics.rs | 7 | ||||
-rw-r--r-- | crates/ide/src/diagnostics/unimplemented_builtin_macro.rs | 19 |
4 files changed, 33 insertions, 31 deletions
diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs index 28580eeb4..3908e67a2 100644 --- a/crates/hir/src/diagnostics.rs +++ b/crates/hir/src/diagnostics.rs | |||
@@ -32,14 +32,15 @@ macro_rules! diagnostics { | |||
32 | } | 32 | } |
33 | 33 | ||
34 | diagnostics![ | 34 | diagnostics![ |
35 | UnresolvedModule, | 35 | InactiveCode, |
36 | MacroError, | ||
37 | MissingFields, | ||
38 | UnimplementedBuiltinMacro, | ||
36 | UnresolvedExternCrate, | 39 | UnresolvedExternCrate, |
37 | UnresolvedImport, | 40 | UnresolvedImport, |
38 | UnresolvedMacroCall, | 41 | UnresolvedMacroCall, |
42 | UnresolvedModule, | ||
39 | UnresolvedProcMacro, | 43 | UnresolvedProcMacro, |
40 | MacroError, | ||
41 | MissingFields, | ||
42 | InactiveCode, | ||
43 | ]; | 44 | ]; |
44 | 45 | ||
45 | #[derive(Debug)] | 46 | #[derive(Debug)] |
@@ -88,26 +89,7 @@ pub struct MacroError { | |||
88 | 89 | ||
89 | #[derive(Debug)] | 90 | #[derive(Debug)] |
90 | pub struct UnimplementedBuiltinMacro { | 91 | pub struct UnimplementedBuiltinMacro { |
91 | pub file: HirFileId, | 92 | pub node: InFile<SyntaxNodePtr>, |
92 | pub node: SyntaxNodePtr, | ||
93 | } | ||
94 | |||
95 | impl Diagnostic for UnimplementedBuiltinMacro { | ||
96 | fn code(&self) -> DiagnosticCode { | ||
97 | DiagnosticCode("unimplemented-builtin-macro") | ||
98 | } | ||
99 | |||
100 | fn message(&self) -> String { | ||
101 | "unimplemented built-in macro".to_string() | ||
102 | } | ||
103 | |||
104 | fn display_source(&self) -> InFile<SyntaxNodePtr> { | ||
105 | InFile::new(self.file, self.node.clone()) | ||
106 | } | ||
107 | |||
108 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | ||
109 | self | ||
110 | } | ||
111 | } | 93 | } |
112 | 94 | ||
113 | // Diagnostic: no-such-field | 95 | // Diagnostic: no-such-field |
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index d891d0ec1..a361158e0 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs | |||
@@ -606,8 +606,12 @@ impl Module { | |||
606 | let node = ast.to_node(db.upcast()); | 606 | let node = ast.to_node(db.upcast()); |
607 | // Must have a name, otherwise we wouldn't emit it. | 607 | // Must have a name, otherwise we wouldn't emit it. |
608 | let name = node.name().expect("unimplemented builtin macro with no name"); | 608 | let name = node.name().expect("unimplemented builtin macro with no name"); |
609 | let ptr = SyntaxNodePtr::from(AstPtr::new(&name)); | 609 | acc.push( |
610 | sink.push(UnimplementedBuiltinMacro { file: ast.file_id, node: ptr }); | 610 | UnimplementedBuiltinMacro { |
611 | node: ast.with_value(SyntaxNodePtr::from(AstPtr::new(&name))), | ||
612 | } | ||
613 | .into(), | ||
614 | ); | ||
611 | } | 615 | } |
612 | } | 616 | } |
613 | } | 617 | } |
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs index aeccf1164..3fbd21c30 100644 --- a/crates/ide/src/diagnostics.rs +++ b/crates/ide/src/diagnostics.rs | |||
@@ -9,6 +9,7 @@ mod unresolved_extern_crate; | |||
9 | mod unresolved_import; | 9 | mod unresolved_import; |
10 | mod unresolved_macro_call; | 10 | mod unresolved_macro_call; |
11 | mod unresolved_proc_macro; | 11 | mod unresolved_proc_macro; |
12 | mod unimplemented_builtin_macro; | ||
12 | mod macro_error; | 13 | mod macro_error; |
13 | mod inactive_code; | 14 | mod inactive_code; |
14 | mod missing_fields; | 15 | mod missing_fields; |
@@ -185,11 +186,6 @@ pub(crate) fn diagnostics( | |||
185 | .with_code(Some(d.code())), | 186 | .with_code(Some(d.code())), |
186 | ); | 187 | ); |
187 | }) | 188 | }) |
188 | .on::<hir::diagnostics::UnimplementedBuiltinMacro, _>(|d| { | ||
189 | let display_range = sema.diagnostics_display_range(d.display_source()).range; | ||
190 | res.borrow_mut() | ||
191 | .push(Diagnostic::hint(display_range, d.message()).with_code(Some(d.code()))); | ||
192 | }) | ||
193 | // Only collect experimental diagnostics when they're enabled. | 189 | // Only collect experimental diagnostics when they're enabled. |
194 | .filter(|diag| !(diag.is_experimental() && config.disable_experimental)) | 190 | .filter(|diag| !(diag.is_experimental() && config.disable_experimental)) |
195 | .filter(|diag| !config.disabled.contains(diag.code().as_str())); | 191 | .filter(|diag| !config.disabled.contains(diag.code().as_str())); |
@@ -229,6 +225,7 @@ pub(crate) fn diagnostics( | |||
229 | AnyDiagnostic::UnresolvedImport(d) => unresolved_import::unresolved_import(&ctx, &d), | 225 | AnyDiagnostic::UnresolvedImport(d) => unresolved_import::unresolved_import(&ctx, &d), |
230 | AnyDiagnostic::UnresolvedMacroCall(d) => unresolved_macro_call::unresolved_macro_call(&ctx, &d), | 226 | AnyDiagnostic::UnresolvedMacroCall(d) => unresolved_macro_call::unresolved_macro_call(&ctx, &d), |
231 | AnyDiagnostic::UnresolvedProcMacro(d) => unresolved_proc_macro::unresolved_proc_macro(&ctx, &d), | 227 | AnyDiagnostic::UnresolvedProcMacro(d) => unresolved_proc_macro::unresolved_proc_macro(&ctx, &d), |
228 | AnyDiagnostic::UnimplementedBuiltinMacro(d) => unimplemented_builtin_macro::unimplemented_builtin_macro(&ctx, &d), | ||
232 | AnyDiagnostic::MissingFields(d) => missing_fields::missing_fields(&ctx, &d), | 229 | AnyDiagnostic::MissingFields(d) => missing_fields::missing_fields(&ctx, &d), |
233 | AnyDiagnostic::MacroError(d) => macro_error::macro_error(&ctx, &d), | 230 | AnyDiagnostic::MacroError(d) => macro_error::macro_error(&ctx, &d), |
234 | 231 | ||
diff --git a/crates/ide/src/diagnostics/unimplemented_builtin_macro.rs b/crates/ide/src/diagnostics/unimplemented_builtin_macro.rs new file mode 100644 index 000000000..09faa3bbc --- /dev/null +++ b/crates/ide/src/diagnostics/unimplemented_builtin_macro.rs | |||
@@ -0,0 +1,19 @@ | |||
1 | use crate::{ | ||
2 | diagnostics::{Diagnostic, DiagnosticsContext}, | ||
3 | Severity, | ||
4 | }; | ||
5 | |||
6 | // Diagnostic: unimplemented-builtin-macro | ||
7 | // | ||
8 | // This diagnostic is shown for builtin macros which are not yet implemented by rust-analyzer | ||
9 | pub(super) fn unimplemented_builtin_macro( | ||
10 | ctx: &DiagnosticsContext<'_>, | ||
11 | d: &hir::UnimplementedBuiltinMacro, | ||
12 | ) -> Diagnostic { | ||
13 | Diagnostic::new( | ||
14 | "unimplemented-builtin-macro", | ||
15 | "unimplemented built-in macro".to_string(), | ||
16 | ctx.sema.diagnostics_display_range(d.node.clone()).range, | ||
17 | ) | ||
18 | .severity(Severity::WeakWarning) | ||
19 | } | ||