diff options
-rw-r--r-- | crates/ra_hir_def/src/diagnostics.rs | 3 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/diagnostics.rs | 1 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/diagnostics.rs | 25 | ||||
-rw-r--r-- | crates/ra_ide/src/diagnostics.rs | 80 | ||||
-rw-r--r-- | crates/ra_ide/src/lib.rs | 28 | ||||
-rw-r--r-- | crates/rust-analyzer/src/config.rs | 12 | ||||
-rw-r--r-- | crates/rust-analyzer/src/global_state.rs | 2 | ||||
-rw-r--r-- | editors/code/package.json | 11 |
8 files changed, 149 insertions, 13 deletions
diff --git a/crates/ra_hir_def/src/diagnostics.rs b/crates/ra_hir_def/src/diagnostics.rs index 71d177070..5b7f05bf4 100644 --- a/crates/ra_hir_def/src/diagnostics.rs +++ b/crates/ra_hir_def/src/diagnostics.rs | |||
@@ -15,6 +15,9 @@ pub struct UnresolvedModule { | |||
15 | } | 15 | } |
16 | 16 | ||
17 | impl Diagnostic for UnresolvedModule { | 17 | impl Diagnostic for UnresolvedModule { |
18 | fn name(&self) -> &'static str { | ||
19 | "unresolved-module" | ||
20 | } | ||
18 | fn message(&self) -> String { | 21 | fn message(&self) -> String { |
19 | "unresolved module".to_string() | 22 | "unresolved module".to_string() |
20 | } | 23 | } |
diff --git a/crates/ra_hir_expand/src/diagnostics.rs b/crates/ra_hir_expand/src/diagnostics.rs index b138500e7..a618934c9 100644 --- a/crates/ra_hir_expand/src/diagnostics.rs +++ b/crates/ra_hir_expand/src/diagnostics.rs | |||
@@ -21,6 +21,7 @@ use ra_syntax::SyntaxNodePtr; | |||
21 | use crate::InFile; | 21 | use crate::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) -> &'static str; | ||
24 | fn message(&self) -> String; | 25 | fn message(&self) -> String; |
25 | /// Used in highlighting and related purposes | 26 | /// Used in highlighting and related purposes |
26 | fn display_source(&self) -> InFile<SyntaxNodePtr>; | 27 | fn display_source(&self) -> InFile<SyntaxNodePtr>; |
diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs index 7ab7f79db..45e31033e 100644 --- a/crates/ra_hir_ty/src/diagnostics.rs +++ b/crates/ra_hir_ty/src/diagnostics.rs | |||
@@ -33,6 +33,10 @@ pub struct NoSuchField { | |||
33 | } | 33 | } |
34 | 34 | ||
35 | impl Diagnostic for NoSuchField { | 35 | impl Diagnostic for NoSuchField { |
36 | fn name(&self) -> &'static str { | ||
37 | "no-such-field" | ||
38 | } | ||
39 | |||
36 | fn message(&self) -> String { | 40 | fn message(&self) -> String { |
37 | "no such field".to_string() | 41 | "no such field".to_string() |
38 | } | 42 | } |
@@ -55,6 +59,9 @@ pub struct MissingFields { | |||
55 | } | 59 | } |
56 | 60 | ||
57 | impl Diagnostic for MissingFields { | 61 | impl Diagnostic for MissingFields { |
62 | fn name(&self) -> &'static str { | ||
63 | "missing-structure-fields" | ||
64 | } | ||
58 | fn message(&self) -> String { | 65 | fn message(&self) -> String { |
59 | let mut buf = String::from("Missing structure fields:\n"); | 66 | let mut buf = String::from("Missing structure fields:\n"); |
60 | for field in &self.missed_fields { | 67 | for field in &self.missed_fields { |
@@ -88,6 +95,9 @@ pub struct MissingPatFields { | |||
88 | } | 95 | } |
89 | 96 | ||
90 | impl Diagnostic for MissingPatFields { | 97 | impl Diagnostic for MissingPatFields { |
98 | fn name(&self) -> &'static str { | ||
99 | "missing-pat-fields" | ||
100 | } | ||
91 | fn message(&self) -> String { | 101 | fn message(&self) -> String { |
92 | let mut buf = String::from("Missing structure fields:\n"); | 102 | let mut buf = String::from("Missing structure fields:\n"); |
93 | for field in &self.missed_fields { | 103 | for field in &self.missed_fields { |
@@ -118,6 +128,9 @@ pub struct MissingMatchArms { | |||
118 | } | 128 | } |
119 | 129 | ||
120 | impl Diagnostic for MissingMatchArms { | 130 | impl Diagnostic for MissingMatchArms { |
131 | fn name(&self) -> &'static str { | ||
132 | "missing-match-arm" | ||
133 | } | ||
121 | fn message(&self) -> String { | 134 | fn message(&self) -> String { |
122 | String::from("Missing match arm") | 135 | String::from("Missing match arm") |
123 | } | 136 | } |
@@ -136,6 +149,9 @@ pub struct MissingOkInTailExpr { | |||
136 | } | 149 | } |
137 | 150 | ||
138 | impl Diagnostic for MissingOkInTailExpr { | 151 | impl Diagnostic for MissingOkInTailExpr { |
152 | fn name(&self) -> &'static str { | ||
153 | "missing-ok-in-tail-expr" | ||
154 | } | ||
139 | fn message(&self) -> String { | 155 | fn message(&self) -> String { |
140 | "wrap return expression in Ok".to_string() | 156 | "wrap return expression in Ok".to_string() |
141 | } | 157 | } |
@@ -154,6 +170,9 @@ pub struct BreakOutsideOfLoop { | |||
154 | } | 170 | } |
155 | 171 | ||
156 | impl Diagnostic for BreakOutsideOfLoop { | 172 | impl Diagnostic for BreakOutsideOfLoop { |
173 | fn name(&self) -> &'static str { | ||
174 | "break-outside-of-loop" | ||
175 | } | ||
157 | fn message(&self) -> String { | 176 | fn message(&self) -> String { |
158 | "break outside of loop".to_string() | 177 | "break outside of loop".to_string() |
159 | } | 178 | } |
@@ -172,6 +191,9 @@ pub struct MissingUnsafe { | |||
172 | } | 191 | } |
173 | 192 | ||
174 | impl Diagnostic for MissingUnsafe { | 193 | impl Diagnostic for MissingUnsafe { |
194 | fn name(&self) -> &'static str { | ||
195 | "missing-unsafe" | ||
196 | } | ||
175 | fn message(&self) -> String { | 197 | fn message(&self) -> String { |
176 | format!("This operation is unsafe and requires an unsafe function or block") | 198 | format!("This operation is unsafe and requires an unsafe function or block") |
177 | } | 199 | } |
@@ -192,6 +214,9 @@ pub struct MismatchedArgCount { | |||
192 | } | 214 | } |
193 | 215 | ||
194 | impl Diagnostic for MismatchedArgCount { | 216 | impl Diagnostic for MismatchedArgCount { |
217 | fn name(&self) -> &'static str { | ||
218 | "mismatched-arg-count" | ||
219 | } | ||
195 | fn message(&self) -> String { | 220 | fn message(&self) -> String { |
196 | let s = if self.expected == 1 { "" } else { "s" }; | 221 | let s = if self.expected == 1 { "" } else { "s" }; |
197 | format!("Expected {} argument{}, found {}", self.expected, s, self.found) | 222 | format!("Expected {} argument{}, found {}", self.expected, s, self.found) |
diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs index 1046d7ab3..79dbb0865 100644 --- a/crates/ra_ide/src/diagnostics.rs +++ b/crates/ra_ide/src/diagnostics.rs | |||
@@ -17,7 +17,7 @@ use ra_syntax::{ | |||
17 | }; | 17 | }; |
18 | use ra_text_edit::{TextEdit, TextEditBuilder}; | 18 | use ra_text_edit::{TextEdit, TextEditBuilder}; |
19 | 19 | ||
20 | use crate::{Diagnostic, FileId, Fix, SourceFileEdit}; | 20 | use crate::{AnalysisConfig, Diagnostic, FileId, Fix, SourceFileEdit}; |
21 | 21 | ||
22 | mod diagnostics_with_fix; | 22 | mod diagnostics_with_fix; |
23 | use diagnostics_with_fix::DiagnosticWithFix; | 23 | use diagnostics_with_fix::DiagnosticWithFix; |
@@ -32,6 +32,7 @@ pub(crate) fn diagnostics( | |||
32 | db: &RootDatabase, | 32 | db: &RootDatabase, |
33 | file_id: FileId, | 33 | file_id: FileId, |
34 | enable_experimental: bool, | 34 | enable_experimental: bool, |
35 | analysis_config: &AnalysisConfig, | ||
35 | ) -> Vec<Diagnostic> { | 36 | ) -> Vec<Diagnostic> { |
36 | let _p = profile("diagnostics"); | 37 | let _p = profile("diagnostics"); |
37 | let sema = Semantics::new(db); | 38 | let sema = Semantics::new(db); |
@@ -40,6 +41,7 @@ pub(crate) fn diagnostics( | |||
40 | 41 | ||
41 | // [#34344] Only take first 128 errors to prevent slowing down editor/ide, the number 128 is chosen arbitrarily. | 42 | // [#34344] Only take first 128 errors to prevent slowing down editor/ide, the number 128 is chosen arbitrarily. |
42 | res.extend(parse.errors().iter().take(128).map(|err| Diagnostic { | 43 | res.extend(parse.errors().iter().take(128).map(|err| Diagnostic { |
44 | name: None, | ||
43 | range: err.range(), | 45 | range: err.range(), |
44 | message: format!("Syntax Error: {}", err), | 46 | message: format!("Syntax Error: {}", err), |
45 | severity: Severity::Error, | 47 | severity: Severity::Error, |
@@ -51,7 +53,7 @@ pub(crate) fn diagnostics( | |||
51 | check_struct_shorthand_initialization(&mut res, file_id, &node); | 53 | check_struct_shorthand_initialization(&mut res, file_id, &node); |
52 | } | 54 | } |
53 | let res = RefCell::new(res); | 55 | let res = RefCell::new(res); |
54 | let mut sink = DiagnosticSinkBuilder::new() | 56 | let mut sink_builder = DiagnosticSinkBuilder::new() |
55 | .on::<hir::diagnostics::UnresolvedModule, _>(|d| { | 57 | .on::<hir::diagnostics::UnresolvedModule, _>(|d| { |
56 | res.borrow_mut().push(diagnostic_with_fix(d, &sema)); | 58 | res.borrow_mut().push(diagnostic_with_fix(d, &sema)); |
57 | }) | 59 | }) |
@@ -65,10 +67,20 @@ pub(crate) fn diagnostics( | |||
65 | res.borrow_mut().push(diagnostic_with_fix(d, &sema)); | 67 | res.borrow_mut().push(diagnostic_with_fix(d, &sema)); |
66 | }) | 68 | }) |
67 | // Only collect experimental diagnostics when they're enabled. | 69 | // Only collect experimental diagnostics when they're enabled. |
68 | .filter(|diag| !diag.is_experimental() || enable_experimental) | 70 | .filter(|diag| !diag.is_experimental() || enable_experimental); |
71 | |||
72 | if !analysis_config.disabled_diagnostics.is_empty() { | ||
73 | // Do not collect disabled diagnostics. | ||
74 | sink_builder = | ||
75 | sink_builder.filter(|diag| !analysis_config.disabled_diagnostics.contains(diag.name())); | ||
76 | } | ||
77 | |||
78 | // Finalize the `DiagnosticSink` building process. | ||
79 | let mut sink = sink_builder | ||
69 | // Diagnostics not handled above get no fix and default treatment. | 80 | // Diagnostics not handled above get no fix and default treatment. |
70 | .build(|d| { | 81 | .build(|d| { |
71 | res.borrow_mut().push(Diagnostic { | 82 | res.borrow_mut().push(Diagnostic { |
83 | name: Some(d.name().into()), | ||
72 | message: d.message(), | 84 | message: d.message(), |
73 | range: sema.diagnostics_display_range(d).range, | 85 | range: sema.diagnostics_display_range(d).range, |
74 | severity: Severity::Error, | 86 | severity: Severity::Error, |
@@ -85,6 +97,7 @@ pub(crate) fn diagnostics( | |||
85 | 97 | ||
86 | fn diagnostic_with_fix<D: DiagnosticWithFix>(d: &D, sema: &Semantics<RootDatabase>) -> Diagnostic { | 98 | fn diagnostic_with_fix<D: DiagnosticWithFix>(d: &D, sema: &Semantics<RootDatabase>) -> Diagnostic { |
87 | Diagnostic { | 99 | Diagnostic { |
100 | name: Some(d.name().into()), | ||
88 | range: sema.diagnostics_display_range(d).range, | 101 | range: sema.diagnostics_display_range(d).range, |
89 | message: d.message(), | 102 | message: d.message(), |
90 | severity: Severity::Error, | 103 | severity: Severity::Error, |
@@ -111,6 +124,7 @@ fn check_unnecessary_braces_in_use_statement( | |||
111 | }); | 124 | }); |
112 | 125 | ||
113 | acc.push(Diagnostic { | 126 | acc.push(Diagnostic { |
127 | name: None, | ||
114 | range: use_range, | 128 | range: use_range, |
115 | message: "Unnecessary braces in use statement".to_string(), | 129 | message: "Unnecessary braces in use statement".to_string(), |
116 | severity: Severity::WeakWarning, | 130 | severity: Severity::WeakWarning, |
@@ -157,6 +171,7 @@ fn check_struct_shorthand_initialization( | |||
157 | 171 | ||
158 | let field_range = record_field.syntax().text_range(); | 172 | let field_range = record_field.syntax().text_range(); |
159 | acc.push(Diagnostic { | 173 | acc.push(Diagnostic { |
174 | name: None, | ||
160 | range: field_range, | 175 | range: field_range, |
161 | message: "Shorthand struct initialization".to_string(), | 176 | message: "Shorthand struct initialization".to_string(), |
162 | severity: Severity::WeakWarning, | 177 | severity: Severity::WeakWarning, |
@@ -174,10 +189,14 @@ fn check_struct_shorthand_initialization( | |||
174 | 189 | ||
175 | #[cfg(test)] | 190 | #[cfg(test)] |
176 | mod tests { | 191 | mod tests { |
192 | use std::collections::HashSet; | ||
177 | use stdx::trim_indent; | 193 | use stdx::trim_indent; |
178 | use test_utils::assert_eq_text; | 194 | use test_utils::assert_eq_text; |
179 | 195 | ||
180 | use crate::mock_analysis::{analysis_and_position, single_file, MockAnalysis}; | 196 | use crate::{ |
197 | mock_analysis::{analysis_and_position, single_file, MockAnalysis}, | ||
198 | AnalysisConfig, | ||
199 | }; | ||
181 | use expect::{expect, Expect}; | 200 | use expect::{expect, Expect}; |
182 | 201 | ||
183 | /// Takes a multi-file input fixture with annotated cursor positions, | 202 | /// Takes a multi-file input fixture with annotated cursor positions, |
@@ -241,6 +260,51 @@ mod tests { | |||
241 | assert_eq!(diagnostics.len(), 0, "unexpected diagnostics:\n{:#?}", diagnostics); | 260 | assert_eq!(diagnostics.len(), 0, "unexpected diagnostics:\n{:#?}", diagnostics); |
242 | } | 261 | } |
243 | 262 | ||
263 | /// Takes a multi-file input fixture with annotated cursor position and the list of disabled diagnostics, | ||
264 | /// and checks that provided diagnostics aren't spawned during analysis. | ||
265 | fn check_disabled_diagnostics(ra_fixture: &str, disabled_diagnostics: &[&'static str]) { | ||
266 | let disabled_diagnostics: HashSet<_> = | ||
267 | disabled_diagnostics.into_iter().map(|diag| diag.to_string()).collect(); | ||
268 | |||
269 | let mock = MockAnalysis::with_files(ra_fixture); | ||
270 | let files = mock.files().map(|(it, _)| it).collect::<Vec<_>>(); | ||
271 | let mut analysis = mock.analysis(); | ||
272 | analysis.set_config(AnalysisConfig { disabled_diagnostics: disabled_diagnostics.clone() }); | ||
273 | |||
274 | let diagnostics = files | ||
275 | .clone() | ||
276 | .into_iter() | ||
277 | .flat_map(|file_id| analysis.diagnostics(file_id, true).unwrap()) | ||
278 | .collect::<Vec<_>>(); | ||
279 | |||
280 | // First, we have to check that diagnostic is not emitted when it's added to the disabled diagnostics list. | ||
281 | for diagnostic in diagnostics { | ||
282 | if let Some(name) = diagnostic.name { | ||
283 | assert!(!disabled_diagnostics.contains(&name), "Diagnostic {} is disabled", name); | ||
284 | } | ||
285 | } | ||
286 | |||
287 | // Then, we must reset the config and repeat the check, so that we'll be sure that without | ||
288 | // config these diagnostics are emitted. | ||
289 | // This is required for tests to not become outdated if e.g. diagnostics name changes: | ||
290 | // without this additional run the test will pass simply because a diagnostic with an old name | ||
291 | // will no longer exist. | ||
292 | analysis.set_config(AnalysisConfig { disabled_diagnostics: Default::default() }); | ||
293 | |||
294 | let diagnostics = files | ||
295 | .into_iter() | ||
296 | .flat_map(|file_id| analysis.diagnostics(file_id, true).unwrap()) | ||
297 | .collect::<Vec<_>>(); | ||
298 | |||
299 | assert!( | ||
300 | diagnostics | ||
301 | .into_iter() | ||
302 | .filter_map(|diag| diag.name) | ||
303 | .any(|name| disabled_diagnostics.contains(&name)), | ||
304 | "At least one of the diagnostics was not emitted even without config; are the diagnostics names correct?" | ||
305 | ); | ||
306 | } | ||
307 | |||
244 | fn check_expect(ra_fixture: &str, expect: Expect) { | 308 | fn check_expect(ra_fixture: &str, expect: Expect) { |
245 | let (analysis, file_id) = single_file(ra_fixture); | 309 | let (analysis, file_id) = single_file(ra_fixture); |
246 | let diagnostics = analysis.diagnostics(file_id, true).unwrap(); | 310 | let diagnostics = analysis.diagnostics(file_id, true).unwrap(); |
@@ -503,6 +567,9 @@ fn test_fn() { | |||
503 | expect![[r#" | 567 | expect![[r#" |
504 | [ | 568 | [ |
505 | Diagnostic { | 569 | Diagnostic { |
570 | name: Some( | ||
571 | "unresolved-module", | ||
572 | ), | ||
506 | message: "unresolved module", | 573 | message: "unresolved module", |
507 | range: 0..8, | 574 | range: 0..8, |
508 | severity: Error, | 575 | severity: Error, |
@@ -676,4 +743,9 @@ struct Foo { | |||
676 | ", | 743 | ", |
677 | ) | 744 | ) |
678 | } | 745 | } |
746 | |||
747 | #[test] | ||
748 | fn test_disabled_diagnostics() { | ||
749 | check_disabled_diagnostics(r#"mod foo;"#, &["unresolved-module"]); | ||
750 | } | ||
679 | } | 751 | } |
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs index 89fcb6f17..2cbd7e4f0 100644 --- a/crates/ra_ide/src/lib.rs +++ b/crates/ra_ide/src/lib.rs | |||
@@ -45,7 +45,7 @@ mod syntax_highlighting; | |||
45 | mod syntax_tree; | 45 | mod syntax_tree; |
46 | mod typing; | 46 | mod typing; |
47 | 47 | ||
48 | use std::sync::Arc; | 48 | use std::{collections::HashSet, sync::Arc}; |
49 | 49 | ||
50 | use ra_cfg::CfgOptions; | 50 | use ra_cfg::CfgOptions; |
51 | use ra_db::{ | 51 | use ra_db::{ |
@@ -100,8 +100,15 @@ pub use ra_text_edit::{Indel, TextEdit}; | |||
100 | 100 | ||
101 | pub type Cancelable<T> = Result<T, Canceled>; | 101 | pub type Cancelable<T> = Result<T, Canceled>; |
102 | 102 | ||
103 | /// Configuration parameters for the analysis run. | ||
104 | #[derive(Debug, Default, Clone)] | ||
105 | pub struct AnalysisConfig { | ||
106 | pub disabled_diagnostics: HashSet<String>, | ||
107 | } | ||
108 | |||
103 | #[derive(Debug)] | 109 | #[derive(Debug)] |
104 | pub struct Diagnostic { | 110 | pub struct Diagnostic { |
111 | pub name: Option<String>, | ||
105 | pub message: String, | 112 | pub message: String, |
106 | pub range: TextRange, | 113 | pub range: TextRange, |
107 | pub severity: Severity, | 114 | pub severity: Severity, |
@@ -145,11 +152,16 @@ impl<T> RangeInfo<T> { | |||
145 | #[derive(Debug)] | 152 | #[derive(Debug)] |
146 | pub struct AnalysisHost { | 153 | pub struct AnalysisHost { |
147 | db: RootDatabase, | 154 | db: RootDatabase, |
155 | config: AnalysisConfig, | ||
148 | } | 156 | } |
149 | 157 | ||
150 | impl AnalysisHost { | 158 | impl AnalysisHost { |
151 | pub fn new(lru_capacity: Option<usize>) -> AnalysisHost { | 159 | pub fn new(lru_capacity: Option<usize>) -> Self { |
152 | AnalysisHost { db: RootDatabase::new(lru_capacity) } | 160 | Self::with_config(lru_capacity, AnalysisConfig::default()) |
161 | } | ||
162 | |||
163 | pub fn with_config(lru_capacity: Option<usize>, config: AnalysisConfig) -> Self { | ||
164 | AnalysisHost { db: RootDatabase::new(lru_capacity), config } | ||
153 | } | 165 | } |
154 | 166 | ||
155 | pub fn update_lru_capacity(&mut self, lru_capacity: Option<usize>) { | 167 | pub fn update_lru_capacity(&mut self, lru_capacity: Option<usize>) { |
@@ -159,7 +171,7 @@ impl AnalysisHost { | |||
159 | /// Returns a snapshot of the current state, which you can query for | 171 | /// Returns a snapshot of the current state, which you can query for |
160 | /// semantic information. | 172 | /// semantic information. |
161 | pub fn analysis(&self) -> Analysis { | 173 | pub fn analysis(&self) -> Analysis { |
162 | Analysis { db: self.db.snapshot() } | 174 | Analysis { db: self.db.snapshot(), config: self.config.clone() } |
163 | } | 175 | } |
164 | 176 | ||
165 | /// Applies changes to the current state of the world. If there are | 177 | /// Applies changes to the current state of the world. If there are |
@@ -203,6 +215,7 @@ impl Default for AnalysisHost { | |||
203 | #[derive(Debug)] | 215 | #[derive(Debug)] |
204 | pub struct Analysis { | 216 | pub struct Analysis { |
205 | db: salsa::Snapshot<RootDatabase>, | 217 | db: salsa::Snapshot<RootDatabase>, |
218 | config: AnalysisConfig, | ||
206 | } | 219 | } |
207 | 220 | ||
208 | // As a general design guideline, `Analysis` API are intended to be independent | 221 | // As a general design guideline, `Analysis` API are intended to be independent |
@@ -498,7 +511,7 @@ impl Analysis { | |||
498 | file_id: FileId, | 511 | file_id: FileId, |
499 | enable_experimental: bool, | 512 | enable_experimental: bool, |
500 | ) -> Cancelable<Vec<Diagnostic>> { | 513 | ) -> Cancelable<Vec<Diagnostic>> { |
501 | self.with_db(|db| diagnostics::diagnostics(db, file_id, enable_experimental)) | 514 | self.with_db(|db| diagnostics::diagnostics(db, file_id, enable_experimental, &self.config)) |
502 | } | 515 | } |
503 | 516 | ||
504 | /// Returns the edit required to rename reference at the position to the new | 517 | /// Returns the edit required to rename reference at the position to the new |
@@ -524,6 +537,11 @@ impl Analysis { | |||
524 | }) | 537 | }) |
525 | } | 538 | } |
526 | 539 | ||
540 | /// Sets the provided config. | ||
541 | pub fn set_config(&mut self, config: AnalysisConfig) { | ||
542 | self.config = config; | ||
543 | } | ||
544 | |||
527 | /// Performs an operation on that may be Canceled. | 545 | /// Performs an operation on that may be Canceled. |
528 | fn with_db<F: FnOnce(&RootDatabase) -> T + std::panic::UnwindSafe, T>( | 546 | fn with_db<F: FnOnce(&RootDatabase) -> T + std::panic::UnwindSafe, T>( |
529 | &self, | 547 | &self, |
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 70b4512d0..2c1db9546 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs | |||
@@ -7,11 +7,11 @@ | |||
7 | //! configure the server itself, feature flags are passed into analysis, and | 7 | //! configure the server itself, feature flags are passed into analysis, and |
8 | //! tweak things like automatic insertion of `()` in completions. | 8 | //! tweak things like automatic insertion of `()` in completions. |
9 | 9 | ||
10 | use std::{ffi::OsString, path::PathBuf}; | 10 | use std::{collections::HashSet, ffi::OsString, path::PathBuf}; |
11 | 11 | ||
12 | use flycheck::FlycheckConfig; | 12 | use flycheck::FlycheckConfig; |
13 | use lsp_types::ClientCapabilities; | 13 | use lsp_types::ClientCapabilities; |
14 | use ra_ide::{AssistConfig, CompletionConfig, HoverConfig, InlayHintsConfig}; | 14 | use ra_ide::{AnalysisConfig, AssistConfig, CompletionConfig, HoverConfig, InlayHintsConfig}; |
15 | use ra_project_model::{CargoConfig, ProjectJson, ProjectJsonData, ProjectManifest}; | 15 | use ra_project_model::{CargoConfig, ProjectJson, ProjectJsonData, ProjectManifest}; |
16 | use serde::Deserialize; | 16 | use serde::Deserialize; |
17 | use vfs::AbsPathBuf; | 17 | use vfs::AbsPathBuf; |
@@ -45,6 +45,8 @@ pub struct Config { | |||
45 | pub with_sysroot: bool, | 45 | pub with_sysroot: bool, |
46 | pub linked_projects: Vec<LinkedProject>, | 46 | pub linked_projects: Vec<LinkedProject>, |
47 | pub root_path: AbsPathBuf, | 47 | pub root_path: AbsPathBuf, |
48 | |||
49 | pub analysis: AnalysisConfig, | ||
48 | } | 50 | } |
49 | 51 | ||
50 | #[derive(Debug, Clone, Eq, PartialEq)] | 52 | #[derive(Debug, Clone, Eq, PartialEq)] |
@@ -176,6 +178,8 @@ impl Config { | |||
176 | hover: HoverConfig::default(), | 178 | hover: HoverConfig::default(), |
177 | linked_projects: Vec::new(), | 179 | linked_projects: Vec::new(), |
178 | root_path, | 180 | root_path, |
181 | |||
182 | analysis: AnalysisConfig::default(), | ||
179 | } | 183 | } |
180 | } | 184 | } |
181 | 185 | ||
@@ -293,6 +297,8 @@ impl Config { | |||
293 | goto_type_def: data.hoverActions_enable && data.hoverActions_gotoTypeDef, | 297 | goto_type_def: data.hoverActions_enable && data.hoverActions_gotoTypeDef, |
294 | }; | 298 | }; |
295 | 299 | ||
300 | self.analysis = AnalysisConfig { disabled_diagnostics: data.analysis_disabledDiagnostics }; | ||
301 | |||
296 | log::info!("Config::update() = {:#?}", self); | 302 | log::info!("Config::update() = {:#?}", self); |
297 | } | 303 | } |
298 | 304 | ||
@@ -444,5 +450,7 @@ config_data! { | |||
444 | rustfmt_overrideCommand: Option<Vec<String>> = None, | 450 | rustfmt_overrideCommand: Option<Vec<String>> = None, |
445 | 451 | ||
446 | withSysroot: bool = true, | 452 | withSysroot: bool = true, |
453 | |||
454 | analysis_disabledDiagnostics: HashSet<String> = HashSet::new(), | ||
447 | } | 455 | } |
448 | } | 456 | } |
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs index 658a50d15..f9f045f13 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs | |||
@@ -109,7 +109,7 @@ impl GlobalState { | |||
109 | Handle { handle, receiver } | 109 | Handle { handle, receiver } |
110 | }; | 110 | }; |
111 | 111 | ||
112 | let analysis_host = AnalysisHost::new(config.lru_capacity); | 112 | let analysis_host = AnalysisHost::with_config(config.lru_capacity, config.analysis.clone()); |
113 | let (flycheck_sender, flycheck_receiver) = unbounded(); | 113 | let (flycheck_sender, flycheck_receiver) = unbounded(); |
114 | GlobalState { | 114 | GlobalState { |
115 | sender, | 115 | sender, |
diff --git a/editors/code/package.json b/editors/code/package.json index ee5f96bf3..d186d1474 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -609,6 +609,15 @@ | |||
609 | }, | 609 | }, |
610 | "description": "List of warnings that should be displayed with hint severity.\nThe warnings will be indicated by faded text or three dots in code and will not show up in the problems panel.", | 610 | "description": "List of warnings that should be displayed with hint severity.\nThe warnings will be indicated by faded text or three dots in code and will not show up in the problems panel.", |
611 | "default": [] | 611 | "default": [] |
612 | }, | ||
613 | "rust-analyzer.analysis.disabledDiagnostics": { | ||
614 | "type": "array", | ||
615 | "uniqueItems": true, | ||
616 | "items": { | ||
617 | "type": "string" | ||
618 | }, | ||
619 | "description": "List of rust-analyzer diagnostics to disable", | ||
620 | "default": [] | ||
612 | } | 621 | } |
613 | } | 622 | } |
614 | }, | 623 | }, |
@@ -904,4 +913,4 @@ | |||
904 | ] | 913 | ] |
905 | } | 914 | } |
906 | } | 915 | } |
907 | } | 916 | } \ No newline at end of file |