From c463d217a1e001abe6a812f309d93527e28a70c6 Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Fri, 7 Aug 2020 13:18:47 +0300 Subject: Add names for diagnostics and add a possibility to disable them --- crates/ra_hir_expand/src/diagnostics.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'crates/ra_hir_expand') diff --git a/crates/ra_hir_expand/src/diagnostics.rs b/crates/ra_hir_expand/src/diagnostics.rs index 84ba97b14..bf9fb081a 100644 --- a/crates/ra_hir_expand/src/diagnostics.rs +++ b/crates/ra_hir_expand/src/diagnostics.rs @@ -14,13 +14,14 @@ //! subsystem provides a separate, non-query-based API which can walk all stored //! values and transform them into instances of `Diagnostic`. -use std::{any::Any, fmt}; +use std::{any::Any, collections::HashSet, fmt}; use ra_syntax::{SyntaxNode, SyntaxNodePtr}; use crate::{db::AstDatabase, InFile}; pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static { + fn name(&self) -> String; fn message(&self) -> String; fn source(&self) -> InFile; fn as_any(&self) -> &(dyn Any + Send + 'static); @@ -49,10 +50,16 @@ pub struct DiagnosticSink<'a> { callbacks: Vec Result<(), ()> + 'a>>, filters: Vec bool + 'a>>, default_callback: Box, + disabled_diagnostics: HashSet, } impl<'a> DiagnosticSink<'a> { pub fn push(&mut self, d: impl Diagnostic) { + if self.disabled_diagnostics.contains(&d.name()) { + // This diagnostic is disabled, ignore it completely. + return; + } + let d: &dyn Diagnostic = &d; self._push(d); } @@ -76,11 +83,12 @@ impl<'a> DiagnosticSink<'a> { pub struct DiagnosticSinkBuilder<'a> { callbacks: Vec Result<(), ()> + 'a>>, filters: Vec bool + 'a>>, + disabled_diagnostics: HashSet, } impl<'a> DiagnosticSinkBuilder<'a> { pub fn new() -> Self { - Self { callbacks: Vec::new(), filters: Vec::new() } + Self { callbacks: Vec::new(), filters: Vec::new(), disabled_diagnostics: HashSet::new() } } pub fn filter bool + 'a>(mut self, cb: F) -> Self { @@ -100,11 +108,17 @@ impl<'a> DiagnosticSinkBuilder<'a> { self } + pub fn disable_diagnostic(mut self, diagnostic: impl Into) -> Self { + self.disabled_diagnostics.insert(diagnostic.into()); + self + } + pub fn build(self, default_callback: F) -> DiagnosticSink<'a> { DiagnosticSink { callbacks: self.callbacks, filters: self.filters, default_callback: Box::new(default_callback), + disabled_diagnostics: self.disabled_diagnostics, } } } -- cgit v1.2.3