diff options
author | Aleksey Kladov <[email protected]> | 2021-06-13 15:51:44 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-06-13 15:51:44 +0100 |
commit | 1e4aaee7bbc1d56698e70158aa35f578422623d9 (patch) | |
tree | 0d7a63a204895fb6c9f3425bb6fce9d6a46b1de5 /crates/hir/src/diagnostics.rs | |
parent | f85e383b94376d55bb5ee6be375ef3dc0006590f (diff) |
internal: refactor unresolved proc macro diagnostic
Diffstat (limited to 'crates/hir/src/diagnostics.rs')
-rw-r--r-- | crates/hir/src/diagnostics.rs | 34 |
1 files changed, 2 insertions, 32 deletions
diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs index 03e7f5e84..2039d2b43 100644 --- a/crates/hir/src/diagnostics.rs +++ b/crates/hir/src/diagnostics.rs | |||
@@ -36,6 +36,7 @@ diagnostics![ | |||
36 | UnresolvedExternCrate, | 36 | UnresolvedExternCrate, |
37 | UnresolvedImport, | 37 | UnresolvedImport, |
38 | UnresolvedMacroCall, | 38 | UnresolvedMacroCall, |
39 | UnresolvedProcMacro, | ||
39 | MissingFields, | 40 | MissingFields, |
40 | InactiveCode, | 41 | InactiveCode, |
41 | ]; | 42 | ]; |
@@ -69,46 +70,15 @@ pub struct InactiveCode { | |||
69 | pub opts: CfgOptions, | 70 | pub opts: CfgOptions, |
70 | } | 71 | } |
71 | 72 | ||
72 | // Diagnostic: unresolved-proc-macro | ||
73 | // | ||
74 | // This diagnostic is shown when a procedural macro can not be found. This usually means that | ||
75 | // procedural macro support is simply disabled (and hence is only a weak hint instead of an error), | ||
76 | // but can also indicate project setup problems. | ||
77 | // | ||
78 | // If you are seeing a lot of "proc macro not expanded" warnings, you can add this option to the | ||
79 | // `rust-analyzer.diagnostics.disabled` list to prevent them from showing. Alternatively you can | ||
80 | // enable support for procedural macros (see `rust-analyzer.procMacro.enable`). | ||
81 | #[derive(Debug, Clone, Eq, PartialEq)] | 73 | #[derive(Debug, Clone, Eq, PartialEq)] |
82 | pub struct UnresolvedProcMacro { | 74 | pub struct UnresolvedProcMacro { |
83 | pub file: HirFileId, | 75 | pub node: InFile<SyntaxNodePtr>, |
84 | pub node: SyntaxNodePtr, | ||
85 | /// If the diagnostic can be pinpointed more accurately than via `node`, this is the `TextRange` | 76 | /// If the diagnostic can be pinpointed more accurately than via `node`, this is the `TextRange` |
86 | /// to use instead. | 77 | /// to use instead. |
87 | pub precise_location: Option<TextRange>, | 78 | pub precise_location: Option<TextRange>, |
88 | pub macro_name: Option<String>, | 79 | pub macro_name: Option<String>, |
89 | } | 80 | } |
90 | 81 | ||
91 | impl Diagnostic for UnresolvedProcMacro { | ||
92 | fn code(&self) -> DiagnosticCode { | ||
93 | DiagnosticCode("unresolved-proc-macro") | ||
94 | } | ||
95 | |||
96 | fn message(&self) -> String { | ||
97 | match &self.macro_name { | ||
98 | Some(name) => format!("proc macro `{}` not expanded", name), | ||
99 | None => "proc macro not expanded".to_string(), | ||
100 | } | ||
101 | } | ||
102 | |||
103 | fn display_source(&self) -> InFile<SyntaxNodePtr> { | ||
104 | InFile::new(self.file, self.node.clone()) | ||
105 | } | ||
106 | |||
107 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | ||
108 | self | ||
109 | } | ||
110 | } | ||
111 | |||
112 | // Diagnostic: macro-error | 82 | // Diagnostic: macro-error |
113 | // | 83 | // |
114 | // This diagnostic is shown for macro expansion errors. | 84 | // This diagnostic is shown for macro expansion errors. |