diff options
author | Jonas Schievink <[email protected]> | 2020-11-26 19:09:54 +0000 |
---|---|---|
committer | Jonas Schievink <[email protected]> | 2020-11-27 12:50:22 +0000 |
commit | 0432aa0ed7be3f41d41928499abc688a956214cf (patch) | |
tree | 64df76e5182412d9a95bc5e63ef3b1db03a5d430 /crates/hir_def/src/diagnostics.rs | |
parent | 1b2652097183b0a285891c02eea8a7d2af03e4b3 (diff) |
Publish diagnostics for macro expansion errors
Diffstat (limited to 'crates/hir_def/src/diagnostics.rs')
-rw-r--r-- | crates/hir_def/src/diagnostics.rs | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/crates/hir_def/src/diagnostics.rs b/crates/hir_def/src/diagnostics.rs index b221b290c..dd06e3f20 100644 --- a/crates/hir_def/src/diagnostics.rs +++ b/crates/hir_def/src/diagnostics.rs | |||
@@ -127,3 +127,65 @@ impl Diagnostic for InactiveCode { | |||
127 | self | 127 | self |
128 | } | 128 | } |
129 | } | 129 | } |
130 | |||
131 | // Diagnostic: unresolved-proc-macro | ||
132 | // | ||
133 | // This diagnostic is shown when a procedural macro can not be found. This usually means that | ||
134 | // procedural macro support is simply disabled (and hence is only a weak hint instead of an error), | ||
135 | // but can also indicate project setup problems. | ||
136 | #[derive(Debug, Clone, Eq, PartialEq)] | ||
137 | pub struct UnresolvedProcMacro { | ||
138 | pub file: HirFileId, | ||
139 | pub node: SyntaxNodePtr, | ||
140 | pub macro_name: Option<String>, | ||
141 | } | ||
142 | |||
143 | impl Diagnostic for UnresolvedProcMacro { | ||
144 | fn code(&self) -> DiagnosticCode { | ||
145 | DiagnosticCode("unresolved-proc-macro") | ||
146 | } | ||
147 | |||
148 | fn message(&self) -> String { | ||
149 | match &self.macro_name { | ||
150 | Some(name) => format!("proc macro `{}` not expanded", name), | ||
151 | None => "proc macro not expanded".to_string(), | ||
152 | } | ||
153 | } | ||
154 | |||
155 | fn display_source(&self) -> InFile<SyntaxNodePtr> { | ||
156 | InFile::new(self.file, self.node.clone()) | ||
157 | } | ||
158 | |||
159 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | ||
160 | self | ||
161 | } | ||
162 | } | ||
163 | |||
164 | // Diagnostic: macro-error | ||
165 | // | ||
166 | // This diagnostic is shown for macro expansion errors. | ||
167 | #[derive(Debug, Clone, Eq, PartialEq)] | ||
168 | pub struct MacroError { | ||
169 | pub file: HirFileId, | ||
170 | pub node: SyntaxNodePtr, | ||
171 | pub message: String, | ||
172 | } | ||
173 | |||
174 | impl Diagnostic for MacroError { | ||
175 | fn code(&self) -> DiagnosticCode { | ||
176 | DiagnosticCode("macro-error") | ||
177 | } | ||
178 | fn message(&self) -> String { | ||
179 | self.message.clone() | ||
180 | } | ||
181 | fn display_source(&self) -> InFile<SyntaxNodePtr> { | ||
182 | InFile::new(self.file, self.node.clone()) | ||
183 | } | ||
184 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | ||
185 | self | ||
186 | } | ||
187 | fn is_experimental(&self) -> bool { | ||
188 | // Newly added and not very well-tested, might contain false positives. | ||
189 | true | ||
190 | } | ||
191 | } | ||