diff options
Diffstat (limited to 'crates/ra_hir_expand')
-rw-r--r-- | crates/ra_hir_expand/src/diagnostics.rs | 18 |
1 files changed, 16 insertions, 2 deletions
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 @@ | |||
14 | //! subsystem provides a separate, non-query-based API which can walk all stored | 14 | //! subsystem provides a separate, non-query-based API which can walk all stored |
15 | //! values and transform them into instances of `Diagnostic`. | 15 | //! values and transform them into instances of `Diagnostic`. |
16 | 16 | ||
17 | use std::{any::Any, fmt}; | 17 | use std::{any::Any, collections::HashSet, fmt}; |
18 | 18 | ||
19 | use ra_syntax::{SyntaxNode, SyntaxNodePtr}; | 19 | use ra_syntax::{SyntaxNode, SyntaxNodePtr}; |
20 | 20 | ||
21 | use crate::{db::AstDatabase, InFile}; | 21 | use crate::{db::AstDatabase, InFile}; |
22 | 22 | ||
23 | pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static { | 23 | pub trait Diagnostic: Any + Send + Sync + fmt::Debug + 'static { |
24 | fn name(&self) -> String; | ||
24 | fn message(&self) -> String; | 25 | fn message(&self) -> String; |
25 | fn source(&self) -> InFile<SyntaxNodePtr>; | 26 | fn source(&self) -> InFile<SyntaxNodePtr>; |
26 | fn as_any(&self) -> &(dyn Any + Send + 'static); | 27 | fn as_any(&self) -> &(dyn Any + Send + 'static); |
@@ -49,10 +50,16 @@ pub struct DiagnosticSink<'a> { | |||
49 | callbacks: Vec<Box<dyn FnMut(&dyn Diagnostic) -> Result<(), ()> + 'a>>, | 50 | callbacks: Vec<Box<dyn FnMut(&dyn Diagnostic) -> Result<(), ()> + 'a>>, |
50 | filters: Vec<Box<dyn FnMut(&dyn Diagnostic) -> bool + 'a>>, | 51 | filters: Vec<Box<dyn FnMut(&dyn Diagnostic) -> bool + 'a>>, |
51 | default_callback: Box<dyn FnMut(&dyn Diagnostic) + 'a>, | 52 | default_callback: Box<dyn FnMut(&dyn Diagnostic) + 'a>, |
53 | disabled_diagnostics: HashSet<String>, | ||
52 | } | 54 | } |
53 | 55 | ||
54 | impl<'a> DiagnosticSink<'a> { | 56 | impl<'a> DiagnosticSink<'a> { |
55 | pub fn push(&mut self, d: impl Diagnostic) { | 57 | pub fn push(&mut self, d: impl Diagnostic) { |
58 | if self.disabled_diagnostics.contains(&d.name()) { | ||
59 | // This diagnostic is disabled, ignore it completely. | ||
60 | return; | ||
61 | } | ||
62 | |||
56 | let d: &dyn Diagnostic = &d; | 63 | let d: &dyn Diagnostic = &d; |
57 | self._push(d); | 64 | self._push(d); |
58 | } | 65 | } |
@@ -76,11 +83,12 @@ impl<'a> DiagnosticSink<'a> { | |||
76 | pub struct DiagnosticSinkBuilder<'a> { | 83 | pub struct DiagnosticSinkBuilder<'a> { |
77 | callbacks: Vec<Box<dyn FnMut(&dyn Diagnostic) -> Result<(), ()> + 'a>>, | 84 | callbacks: Vec<Box<dyn FnMut(&dyn Diagnostic) -> Result<(), ()> + 'a>>, |
78 | filters: Vec<Box<dyn FnMut(&dyn Diagnostic) -> bool + 'a>>, | 85 | filters: Vec<Box<dyn FnMut(&dyn Diagnostic) -> bool + 'a>>, |
86 | disabled_diagnostics: HashSet<String>, | ||
79 | } | 87 | } |
80 | 88 | ||
81 | impl<'a> DiagnosticSinkBuilder<'a> { | 89 | impl<'a> DiagnosticSinkBuilder<'a> { |
82 | pub fn new() -> Self { | 90 | pub fn new() -> Self { |
83 | Self { callbacks: Vec::new(), filters: Vec::new() } | 91 | Self { callbacks: Vec::new(), filters: Vec::new(), disabled_diagnostics: HashSet::new() } |
84 | } | 92 | } |
85 | 93 | ||
86 | pub fn filter<F: FnMut(&dyn Diagnostic) -> bool + 'a>(mut self, cb: F) -> Self { | 94 | pub fn filter<F: FnMut(&dyn Diagnostic) -> bool + 'a>(mut self, cb: F) -> Self { |
@@ -100,11 +108,17 @@ impl<'a> DiagnosticSinkBuilder<'a> { | |||
100 | self | 108 | self |
101 | } | 109 | } |
102 | 110 | ||
111 | pub fn disable_diagnostic(mut self, diagnostic: impl Into<String>) -> Self { | ||
112 | self.disabled_diagnostics.insert(diagnostic.into()); | ||
113 | self | ||
114 | } | ||
115 | |||
103 | pub fn build<F: FnMut(&dyn Diagnostic) + 'a>(self, default_callback: F) -> DiagnosticSink<'a> { | 116 | pub fn build<F: FnMut(&dyn Diagnostic) + 'a>(self, default_callback: F) -> DiagnosticSink<'a> { |
104 | DiagnosticSink { | 117 | DiagnosticSink { |
105 | callbacks: self.callbacks, | 118 | callbacks: self.callbacks, |
106 | filters: self.filters, | 119 | filters: self.filters, |
107 | default_callback: Box::new(default_callback), | 120 | default_callback: Box::new(default_callback), |
121 | disabled_diagnostics: self.disabled_diagnostics, | ||
108 | } | 122 | } |
109 | } | 123 | } |
110 | } | 124 | } |