From ff52167c9a8dd6f99a56a35eae8d634d0ddf1286 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 13 Jun 2021 22:05:47 +0300 Subject: internal: kill diagnostic sink --- crates/ide/src/diagnostics.rs | 48 ++++++++++++------------------------------- 1 file changed, 13 insertions(+), 35 deletions(-) (limited to 'crates/ide') diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs index fe6236e44..c024e3e1e 100644 --- a/crates/ide/src/diagnostics.rs +++ b/crates/ide/src/diagnostics.rs @@ -26,12 +26,7 @@ mod unresolved_proc_macro; mod field_shorthand; -use std::cell::RefCell; - -use hir::{ - diagnostics::{AnyDiagnostic, DiagnosticCode, DiagnosticSinkBuilder}, - Semantics, -}; +use hir::{diagnostics::AnyDiagnostic, Semantics}; use ide_assists::AssistResolveStrategy; use ide_db::{base_db::SourceDatabase, RootDatabase}; use itertools::Itertools; @@ -45,6 +40,15 @@ use unlinked_file::UnlinkedFile; use crate::{Assist, AssistId, AssistKind, FileId, Label, SourceChange}; +#[derive(Copy, Clone, Debug, PartialEq)] +pub struct DiagnosticCode(pub &'static str); + +impl DiagnosticCode { + pub fn as_str(&self) -> &str { + self.0 + } +} + #[derive(Debug)] pub struct Diagnostic { // pub name: Option, @@ -113,10 +117,6 @@ impl Diagnostic { fn with_unused(self, unused: bool) -> Self { Self { unused, ..self } } - - fn with_code(self, code: Option) -> Self { - Self { code, ..self } - } } #[derive(Debug, Copy, Clone)] @@ -161,35 +161,13 @@ pub(crate) fn diagnostics( check_unnecessary_braces_in_use_statement(&mut res, file_id, &node); field_shorthand::check(&mut res, file_id, &node); } - let res = RefCell::new(res); - let sink_builder = DiagnosticSinkBuilder::new() - // Only collect experimental diagnostics when they're enabled. - .filter(|diag| !(diag.is_experimental() && config.disable_experimental)) - .filter(|diag| !config.disabled.contains(diag.code().as_str())); - - // Finalize the `DiagnosticSink` building process. - let mut sink = sink_builder - // Diagnostics not handled above get no fix and default treatment. - .build(|d| { - res.borrow_mut().push( - Diagnostic::error( - sema.diagnostics_display_range(d.display_source()).range, - d.message(), - ) - .with_code(Some(d.code())), - ); - }); let mut diags = Vec::new(); let module = sema.to_module_def(file_id); if let Some(m) = module { - diags = m.diagnostics(db, &mut sink) + m.diagnostics(db, &mut diags) } - drop(sink); - - let mut res = res.into_inner(); - let ctx = DiagnosticsContext { config, sema, resolve }; if module.is_none() { let d = UnlinkedFile { file: file_id }; @@ -350,8 +328,8 @@ mod tests { ) .unwrap() .pop() - .unwrap(); - let fix = &diagnostic.fixes.unwrap()[nth]; + .expect("no diagnostics"); + let fix = &diagnostic.fixes.expect("diagnostic misses fixes")[nth]; let actual = { let source_change = fix.source_change.as_ref().unwrap(); let file_id = *source_change.source_file_edits.keys().next().unwrap(); -- cgit v1.2.3