diff options
Diffstat (limited to 'crates/ide/src/diagnostics.rs')
-rw-r--r-- | crates/ide/src/diagnostics.rs | 49 |
1 files changed, 22 insertions, 27 deletions
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs index 1a4800832..c257ea8e7 100644 --- a/crates/ide/src/diagnostics.rs +++ b/crates/ide/src/diagnostics.rs | |||
@@ -8,6 +8,9 @@ mod unresolved_module; | |||
8 | mod unresolved_extern_crate; | 8 | 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; | ||
12 | mod macro_error; | ||
13 | mod inactive_code; | ||
11 | mod missing_fields; | 14 | mod missing_fields; |
12 | 15 | ||
13 | mod fixes; | 16 | mod fixes; |
@@ -67,6 +70,11 @@ impl Diagnostic { | |||
67 | self | 70 | self |
68 | } | 71 | } |
69 | 72 | ||
73 | fn severity(mut self, severity: Severity) -> Diagnostic { | ||
74 | self.severity = severity; | ||
75 | self | ||
76 | } | ||
77 | |||
70 | fn error(range: TextRange, message: String) -> Self { | 78 | fn error(range: TextRange, message: String) -> Self { |
71 | Self { | 79 | Self { |
72 | message, | 80 | message, |
@@ -164,22 +172,6 @@ pub(crate) fn diagnostics( | |||
164 | .on::<hir::diagnostics::ReplaceFilterMapNextWithFindMap, _>(|d| { | 172 | .on::<hir::diagnostics::ReplaceFilterMapNextWithFindMap, _>(|d| { |
165 | res.borrow_mut().push(warning_with_fix(d, &sema, resolve)); | 173 | res.borrow_mut().push(warning_with_fix(d, &sema, resolve)); |
166 | }) | 174 | }) |
167 | .on::<hir::diagnostics::InactiveCode, _>(|d| { | ||
168 | // If there's inactive code somewhere in a macro, don't propagate to the call-site. | ||
169 | if d.display_source().file_id.expansion_info(db).is_some() { | ||
170 | return; | ||
171 | } | ||
172 | |||
173 | // Override severity and mark as unused. | ||
174 | res.borrow_mut().push( | ||
175 | Diagnostic::hint( | ||
176 | sema.diagnostics_display_range(d.display_source()).range, | ||
177 | d.message(), | ||
178 | ) | ||
179 | .with_unused(true) | ||
180 | .with_code(Some(d.code())), | ||
181 | ); | ||
182 | }) | ||
183 | .on::<UnlinkedFile, _>(|d| { | 175 | .on::<UnlinkedFile, _>(|d| { |
184 | // Limit diagnostic to the first few characters in the file. This matches how VS Code | 176 | // Limit diagnostic to the first few characters in the file. This matches how VS Code |
185 | // renders it with the full span, but on other editors, and is less invasive. | 177 | // renders it with the full span, but on other editors, and is less invasive. |
@@ -193,16 +185,6 @@ pub(crate) fn diagnostics( | |||
193 | .with_code(Some(d.code())), | 185 | .with_code(Some(d.code())), |
194 | ); | 186 | ); |
195 | }) | 187 | }) |
196 | .on::<hir::diagnostics::UnresolvedProcMacro, _>(|d| { | ||
197 | // Use more accurate position if available. | ||
198 | let display_range = d | ||
199 | .precise_location | ||
200 | .unwrap_or_else(|| sema.diagnostics_display_range(d.display_source()).range); | ||
201 | |||
202 | // FIXME: it would be nice to tell the user whether proc macros are currently disabled | ||
203 | res.borrow_mut() | ||
204 | .push(Diagnostic::hint(display_range, d.message()).with_code(Some(d.code()))); | ||
205 | }) | ||
206 | .on::<hir::diagnostics::UnimplementedBuiltinMacro, _>(|d| { | 188 | .on::<hir::diagnostics::UnimplementedBuiltinMacro, _>(|d| { |
207 | let display_range = sema.diagnostics_display_range(d.display_source()).range; | 189 | let display_range = sema.diagnostics_display_range(d.display_source()).range; |
208 | res.borrow_mut() | 190 | res.borrow_mut() |
@@ -246,7 +228,14 @@ pub(crate) fn diagnostics( | |||
246 | AnyDiagnostic::UnresolvedExternCrate(d) => unresolved_extern_crate::unresolved_extern_crate(&ctx, &d), | 228 | AnyDiagnostic::UnresolvedExternCrate(d) => unresolved_extern_crate::unresolved_extern_crate(&ctx, &d), |
247 | AnyDiagnostic::UnresolvedImport(d) => unresolved_import::unresolved_import(&ctx, &d), | 229 | AnyDiagnostic::UnresolvedImport(d) => unresolved_import::unresolved_import(&ctx, &d), |
248 | AnyDiagnostic::UnresolvedMacroCall(d) => unresolved_macro_call::unresolved_macro_call(&ctx, &d), | 230 | AnyDiagnostic::UnresolvedMacroCall(d) => unresolved_macro_call::unresolved_macro_call(&ctx, &d), |
231 | AnyDiagnostic::UnresolvedProcMacro(d) => unresolved_proc_macro::unresolved_proc_macro(&ctx, &d), | ||
249 | AnyDiagnostic::MissingFields(d) => missing_fields::missing_fields(&ctx, &d), | 232 | AnyDiagnostic::MissingFields(d) => missing_fields::missing_fields(&ctx, &d), |
233 | AnyDiagnostic::MacroError(d) => macro_error::macro_error(&ctx, &d), | ||
234 | |||
235 | AnyDiagnostic::InactiveCode(d) => match inactive_code::inactive_code(&ctx, &d) { | ||
236 | Some(it) => it, | ||
237 | None => continue, | ||
238 | } | ||
250 | }; | 239 | }; |
251 | if let Some(code) = d.code { | 240 | if let Some(code) = d.code { |
252 | if ctx.config.disabled.contains(code.as_str()) { | 241 | if ctx.config.disabled.contains(code.as_str()) { |
@@ -451,7 +440,13 @@ mod tests { | |||
451 | expect.assert_debug_eq(&diagnostics) | 440 | expect.assert_debug_eq(&diagnostics) |
452 | } | 441 | } |
453 | 442 | ||
443 | #[track_caller] | ||
454 | pub(crate) fn check_diagnostics(ra_fixture: &str) { | 444 | pub(crate) fn check_diagnostics(ra_fixture: &str) { |
445 | check_diagnostics_with_inactive_code(ra_fixture, false) | ||
446 | } | ||
447 | |||
448 | #[track_caller] | ||
449 | pub(crate) fn check_diagnostics_with_inactive_code(ra_fixture: &str, with_inactive_code: bool) { | ||
455 | let (analysis, file_id) = fixture::file(ra_fixture); | 450 | let (analysis, file_id) = fixture::file(ra_fixture); |
456 | let diagnostics = analysis | 451 | let diagnostics = analysis |
457 | .diagnostics(&DiagnosticsConfig::default(), AssistResolveStrategy::All, file_id) | 452 | .diagnostics(&DiagnosticsConfig::default(), AssistResolveStrategy::All, file_id) |
@@ -460,7 +455,7 @@ mod tests { | |||
460 | let expected = extract_annotations(&*analysis.file_text(file_id).unwrap()); | 455 | let expected = extract_annotations(&*analysis.file_text(file_id).unwrap()); |
461 | let mut actual = diagnostics | 456 | let mut actual = diagnostics |
462 | .into_iter() | 457 | .into_iter() |
463 | .filter(|d| d.code != Some(DiagnosticCode("inactive-code"))) | 458 | .filter(|d| d.code != Some(DiagnosticCode("inactive-code")) || with_inactive_code) |
464 | .map(|d| (d.range, d.message)) | 459 | .map(|d| (d.range, d.message)) |
465 | .collect::<Vec<_>>(); | 460 | .collect::<Vec<_>>(); |
466 | actual.sort_by_key(|(range, _)| range.start()); | 461 | actual.sort_by_key(|(range, _)| range.start()); |