aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_expand
diff options
context:
space:
mode:
authorIgor Aleksanov <[email protected]>2020-08-07 12:25:55 +0100
committerIgor Aleksanov <[email protected]>2020-08-07 12:25:55 +0100
commit90857ff8b08d73945598bac12a841559e86402b1 (patch)
tree8e98c8d7a1b50d55dbbbf788cda94b11eb3e3395 /crates/ra_hir_expand
parentc463d217a1e001abe6a812f309d93527e28a70c6 (diff)
Add an AnalysisConfig structure and use it to configure diagnostics run
Diffstat (limited to 'crates/ra_hir_expand')
-rw-r--r--crates/ra_hir_expand/src/diagnostics.rs17
1 files changed, 2 insertions, 15 deletions
diff --git a/crates/ra_hir_expand/src/diagnostics.rs b/crates/ra_hir_expand/src/diagnostics.rs
index bf9fb081a..ef1d61144 100644
--- a/crates/ra_hir_expand/src/diagnostics.rs
+++ b/crates/ra_hir_expand/src/diagnostics.rs
@@ -14,7 +14,7 @@
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
17use std::{any::Any, collections::HashSet, fmt}; 17use std::{any::Any, fmt};
18 18
19use ra_syntax::{SyntaxNode, SyntaxNodePtr}; 19use ra_syntax::{SyntaxNode, SyntaxNodePtr};
20 20
@@ -50,16 +50,10 @@ pub struct DiagnosticSink<'a> {
50 callbacks: Vec<Box<dyn FnMut(&dyn Diagnostic) -> Result<(), ()> + 'a>>, 50 callbacks: Vec<Box<dyn FnMut(&dyn Diagnostic) -> Result<(), ()> + 'a>>,
51 filters: Vec<Box<dyn FnMut(&dyn Diagnostic) -> bool + 'a>>, 51 filters: Vec<Box<dyn FnMut(&dyn Diagnostic) -> bool + 'a>>,
52 default_callback: Box<dyn FnMut(&dyn Diagnostic) + 'a>, 52 default_callback: Box<dyn FnMut(&dyn Diagnostic) + 'a>,
53 disabled_diagnostics: HashSet<String>,
54} 53}
55 54
56impl<'a> DiagnosticSink<'a> { 55impl<'a> DiagnosticSink<'a> {
57 pub fn push(&mut self, d: impl Diagnostic) { 56 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
63 let d: &dyn Diagnostic = &d; 57 let d: &dyn Diagnostic = &d;
64 self._push(d); 58 self._push(d);
65 } 59 }
@@ -83,12 +77,11 @@ impl<'a> DiagnosticSink<'a> {
83pub struct DiagnosticSinkBuilder<'a> { 77pub struct DiagnosticSinkBuilder<'a> {
84 callbacks: Vec<Box<dyn FnMut(&dyn Diagnostic) -> Result<(), ()> + 'a>>, 78 callbacks: Vec<Box<dyn FnMut(&dyn Diagnostic) -> Result<(), ()> + 'a>>,
85 filters: Vec<Box<dyn FnMut(&dyn Diagnostic) -> bool + 'a>>, 79 filters: Vec<Box<dyn FnMut(&dyn Diagnostic) -> bool + 'a>>,
86 disabled_diagnostics: HashSet<String>,
87} 80}
88 81
89impl<'a> DiagnosticSinkBuilder<'a> { 82impl<'a> DiagnosticSinkBuilder<'a> {
90 pub fn new() -> Self { 83 pub fn new() -> Self {
91 Self { callbacks: Vec::new(), filters: Vec::new(), disabled_diagnostics: HashSet::new() } 84 Self { callbacks: Vec::new(), filters: Vec::new() }
92 } 85 }
93 86
94 pub fn filter<F: FnMut(&dyn Diagnostic) -> bool + 'a>(mut self, cb: F) -> Self { 87 pub fn filter<F: FnMut(&dyn Diagnostic) -> bool + 'a>(mut self, cb: F) -> Self {
@@ -108,17 +101,11 @@ impl<'a> DiagnosticSinkBuilder<'a> {
108 self 101 self
109 } 102 }
110 103
111 pub fn disable_diagnostic(mut self, diagnostic: impl Into<String>) -> Self {
112 self.disabled_diagnostics.insert(diagnostic.into());
113 self
114 }
115
116 pub fn build<F: FnMut(&dyn Diagnostic) + 'a>(self, default_callback: F) -> DiagnosticSink<'a> { 104 pub fn build<F: FnMut(&dyn Diagnostic) + 'a>(self, default_callback: F) -> DiagnosticSink<'a> {
117 DiagnosticSink { 105 DiagnosticSink {
118 callbacks: self.callbacks, 106 callbacks: self.callbacks,
119 filters: self.filters, 107 filters: self.filters,
120 default_callback: Box::new(default_callback), 108 default_callback: Box::new(default_callback),
121 disabled_diagnostics: self.disabled_diagnostics,
122 } 109 }
123 } 110 }
124} 111}