aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/diagnostics.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src/diagnostics.rs')
-rw-r--r--crates/ide/src/diagnostics.rs30
1 files changed, 13 insertions, 17 deletions
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs
index 1a4800832..634e6a043 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 inactive_code;
11mod missing_fields; 12mod missing_fields;
12 13
13mod fixes; 14mod fixes;
@@ -164,22 +165,6 @@ pub(crate) fn diagnostics(
164 .on::<hir::diagnostics::ReplaceFilterMapNextWithFindMap, _>(|d| { 165 .on::<hir::diagnostics::ReplaceFilterMapNextWithFindMap, _>(|d| {
165 res.borrow_mut().push(warning_with_fix(d, &sema, resolve)); 166 res.borrow_mut().push(warning_with_fix(d, &sema, resolve));
166 }) 167 })
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| { 168 .on::<UnlinkedFile, _>(|d| {
184 // Limit diagnostic to the first few characters in the file. This matches how VS Code 169 // 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. 170 // renders it with the full span, but on other editors, and is less invasive.
@@ -247,6 +232,11 @@ pub(crate) fn diagnostics(
247 AnyDiagnostic::UnresolvedImport(d) => unresolved_import::unresolved_import(&ctx, &d), 232 AnyDiagnostic::UnresolvedImport(d) => unresolved_import::unresolved_import(&ctx, &d),
248 AnyDiagnostic::UnresolvedMacroCall(d) => unresolved_macro_call::unresolved_macro_call(&ctx, &d), 233 AnyDiagnostic::UnresolvedMacroCall(d) => unresolved_macro_call::unresolved_macro_call(&ctx, &d),
249 AnyDiagnostic::MissingFields(d) => missing_fields::missing_fields(&ctx, &d), 234 AnyDiagnostic::MissingFields(d) => missing_fields::missing_fields(&ctx, &d),
235
236 AnyDiagnostic::InactiveCode(d) => match inactive_code::inactive_code(&ctx, &d) {
237 Some(it) => it,
238 None => continue,
239 }
250 }; 240 };
251 if let Some(code) = d.code { 241 if let Some(code) = d.code {
252 if ctx.config.disabled.contains(code.as_str()) { 242 if ctx.config.disabled.contains(code.as_str()) {
@@ -451,7 +441,13 @@ mod tests {
451 expect.assert_debug_eq(&diagnostics) 441 expect.assert_debug_eq(&diagnostics)
452 } 442 }
453 443
444 #[track_caller]
454 pub(crate) fn check_diagnostics(ra_fixture: &str) { 445 pub(crate) fn check_diagnostics(ra_fixture: &str) {
446 check_diagnostics_with_inactive_code(ra_fixture, false)
447 }
448
449 #[track_caller]
450 pub(crate) fn check_diagnostics_with_inactive_code(ra_fixture: &str, with_inactive_code: bool) {
455 let (analysis, file_id) = fixture::file(ra_fixture); 451 let (analysis, file_id) = fixture::file(ra_fixture);
456 let diagnostics = analysis 452 let diagnostics = analysis
457 .diagnostics(&DiagnosticsConfig::default(), AssistResolveStrategy::All, file_id) 453 .diagnostics(&DiagnosticsConfig::default(), AssistResolveStrategy::All, file_id)
@@ -460,7 +456,7 @@ mod tests {
460 let expected = extract_annotations(&*analysis.file_text(file_id).unwrap()); 456 let expected = extract_annotations(&*analysis.file_text(file_id).unwrap());
461 let mut actual = diagnostics 457 let mut actual = diagnostics
462 .into_iter() 458 .into_iter()
463 .filter(|d| d.code != Some(DiagnosticCode("inactive-code"))) 459 .filter(|d| d.code != Some(DiagnosticCode("inactive-code")) || with_inactive_code)
464 .map(|d| (d.range, d.message)) 460 .map(|d| (d.range, d.message))
465 .collect::<Vec<_>>(); 461 .collect::<Vec<_>>();
466 actual.sort_by_key(|(range, _)| range.start()); 462 actual.sort_by_key(|(range, _)| range.start());