diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir_def/src/diagnostics.rs | 3 | ||||
-rw-r--r-- | crates/hir_expand/src/diagnostics.rs | 1 | ||||
-rw-r--r-- | crates/hir_ty/src/diagnostics.rs | 25 | ||||
-rw-r--r-- | crates/ide/src/diagnostics.rs | 80 | ||||
-rw-r--r-- | crates/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 |
7 files changed, 139 insertions, 12 deletions
diff --git a/crates/hir_def/src/diagnostics.rs b/crates/hir_def/src/diagnostics.rs index 2e38a978f..c7723de00 100644 --- a/crates/hir_def/src/diagnostics.rs +++ b/crates/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/hir_expand/src/diagnostics.rs b/crates/hir_expand/src/diagnostics.rs index 59d35debe..6c81b2501 100644 --- a/crates/hir_expand/src/diagnostics.rs +++ b/crates/hir_expand/src/diagnostics.rs | |||
@@ -21,6 +21,7 @@ use 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/hir_ty/src/diagnostics.rs b/crates/hir_ty/src/diagnostics.rs index ae0cf8d09..38fa24ee0 100644 --- a/crates/hir_ty/src/diagnostics.rs +++ b/crates/hir_ty/src/diagnostics.rs | |||
@@ -32,6 +32,10 @@ pub struct NoSuchField { | |||
32 | } | 32 | } |
33 | 33 | ||
34 | impl Diagnostic for NoSuchField { | 34 | impl Diagnostic for NoSuchField { |
35 | fn name(&self) -> &'static str { | ||
36 | "no-such-field" | ||
37 | } | ||
38 | |||
35 | fn message(&self) -> String { | 39 | fn message(&self) -> String { |
36 | "no such field".to_string() | 40 | "no such field".to_string() |
37 | } | 41 | } |
@@ -54,6 +58,9 @@ pub struct MissingFields { | |||
54 | } | 58 | } |
55 | 59 | ||
56 | impl Diagnostic for MissingFields { | 60 | impl Diagnostic for MissingFields { |
61 | fn name(&self) -> &'static str { | ||
62 | "missing-structure-fields" | ||
63 | } | ||
57 | fn message(&self) -> String { | 64 | fn message(&self) -> String { |
58 | let mut buf = String::from("Missing structure fields:\n"); | 65 | let mut buf = String::from("Missing structure fields:\n"); |
59 | for field in &self.missed_fields { | 66 | for field in &self.missed_fields { |
@@ -87,6 +94,9 @@ pub struct MissingPatFields { | |||
87 | } | 94 | } |
88 | 95 | ||
89 | impl Diagnostic for MissingPatFields { | 96 | impl Diagnostic for MissingPatFields { |
97 | fn name(&self) -> &'static str { | ||
98 | "missing-pat-fields" | ||
99 | } | ||
90 | fn message(&self) -> String { | 100 | fn message(&self) -> String { |
91 | let mut buf = String::from("Missing structure fields:\n"); | 101 | let mut buf = String::from("Missing structure fields:\n"); |
92 | for field in &self.missed_fields { | 102 | for field in &self.missed_fields { |
@@ -117,6 +127,9 @@ pub struct MissingMatchArms { | |||
117 | } | 127 | } |
118 | 128 | ||
119 | impl Diagnostic for MissingMatchArms { | 129 | impl Diagnostic for MissingMatchArms { |
130 | fn name(&self) -> &'static str { | ||
131 | "missing-match-arm" | ||
132 | } | ||
120 | fn message(&self) -> String { | 133 | fn message(&self) -> String { |
121 | String::from("Missing match arm") | 134 | String::from("Missing match arm") |
122 | } | 135 | } |
@@ -135,6 +148,9 @@ pub struct MissingOkInTailExpr { | |||
135 | } | 148 | } |
136 | 149 | ||
137 | impl Diagnostic for MissingOkInTailExpr { | 150 | impl Diagnostic for MissingOkInTailExpr { |
151 | fn name(&self) -> &'static str { | ||
152 | "missing-ok-in-tail-expr" | ||
153 | } | ||
138 | fn message(&self) -> String { | 154 | fn message(&self) -> String { |
139 | "wrap return expression in Ok".to_string() | 155 | "wrap return expression in Ok".to_string() |
140 | } | 156 | } |
@@ -153,6 +169,9 @@ pub struct BreakOutsideOfLoop { | |||
153 | } | 169 | } |
154 | 170 | ||
155 | impl Diagnostic for BreakOutsideOfLoop { | 171 | impl Diagnostic for BreakOutsideOfLoop { |
172 | fn name(&self) -> &'static str { | ||
173 | "break-outside-of-loop" | ||
174 | } | ||
156 | fn message(&self) -> String { | 175 | fn message(&self) -> String { |
157 | "break outside of loop".to_string() | 176 | "break outside of loop".to_string() |
158 | } | 177 | } |
@@ -171,6 +190,9 @@ pub struct MissingUnsafe { | |||
171 | } | 190 | } |
172 | 191 | ||
173 | impl Diagnostic for MissingUnsafe { | 192 | impl Diagnostic for MissingUnsafe { |
193 | fn name(&self) -> &'static str { | ||
194 | "missing-unsafe" | ||
195 | } | ||
174 | fn message(&self) -> String { | 196 | fn message(&self) -> String { |
175 | format!("This operation is unsafe and requires an unsafe function or block") | 197 | format!("This operation is unsafe and requires an unsafe function or block") |
176 | } | 198 | } |
@@ -191,6 +213,9 @@ pub struct MismatchedArgCount { | |||
191 | } | 213 | } |
192 | 214 | ||
193 | impl Diagnostic for MismatchedArgCount { | 215 | impl Diagnostic for MismatchedArgCount { |
216 | fn name(&self) -> &'static str { | ||
217 | "mismatched-arg-count" | ||
218 | } | ||
194 | fn message(&self) -> String { | 219 | fn message(&self) -> String { |
195 | let s = if self.expected == 1 { "" } else { "s" }; | 220 | let s = if self.expected == 1 { "" } else { "s" }; |
196 | format!("Expected {} argument{}, found {}", self.expected, s, self.found) | 221 | format!("Expected {} argument{}, found {}", self.expected, s, self.found) |
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs index a3ec98178..a54df37db 100644 --- a/crates/ide/src/diagnostics.rs +++ b/crates/ide/src/diagnostics.rs | |||
@@ -16,7 +16,7 @@ use syntax::{ | |||
16 | }; | 16 | }; |
17 | use text_edit::TextEdit; | 17 | use text_edit::TextEdit; |
18 | 18 | ||
19 | use crate::{Diagnostic, FileId, Fix, SourceFileEdit}; | 19 | use crate::{AnalysisConfig, Diagnostic, FileId, Fix, SourceFileEdit}; |
20 | 20 | ||
21 | mod diagnostics_with_fix; | 21 | mod diagnostics_with_fix; |
22 | use diagnostics_with_fix::DiagnosticWithFix; | 22 | use diagnostics_with_fix::DiagnosticWithFix; |
@@ -31,6 +31,7 @@ pub(crate) fn diagnostics( | |||
31 | db: &RootDatabase, | 31 | db: &RootDatabase, |
32 | file_id: FileId, | 32 | file_id: FileId, |
33 | enable_experimental: bool, | 33 | enable_experimental: bool, |
34 | analysis_config: &AnalysisConfig, | ||
34 | ) -> Vec<Diagnostic> { | 35 | ) -> Vec<Diagnostic> { |
35 | let _p = profile::span("diagnostics"); | 36 | let _p = profile::span("diagnostics"); |
36 | let sema = Semantics::new(db); | 37 | let sema = Semantics::new(db); |
@@ -39,6 +40,7 @@ pub(crate) fn diagnostics( | |||
39 | 40 | ||
40 | // [#34344] Only take first 128 errors to prevent slowing down editor/ide, the number 128 is chosen arbitrarily. | 41 | // [#34344] Only take first 128 errors to prevent slowing down editor/ide, the number 128 is chosen arbitrarily. |
41 | res.extend(parse.errors().iter().take(128).map(|err| Diagnostic { | 42 | res.extend(parse.errors().iter().take(128).map(|err| Diagnostic { |
43 | name: None, | ||
42 | range: err.range(), | 44 | range: err.range(), |
43 | message: format!("Syntax Error: {}", err), | 45 | message: format!("Syntax Error: {}", err), |
44 | severity: Severity::Error, | 46 | severity: Severity::Error, |
@@ -50,7 +52,7 @@ pub(crate) fn diagnostics( | |||
50 | check_struct_shorthand_initialization(&mut res, file_id, &node); | 52 | check_struct_shorthand_initialization(&mut res, file_id, &node); |
51 | } | 53 | } |
52 | let res = RefCell::new(res); | 54 | let res = RefCell::new(res); |
53 | let mut sink = DiagnosticSinkBuilder::new() | 55 | let mut sink_builder = DiagnosticSinkBuilder::new() |
54 | .on::<hir::diagnostics::UnresolvedModule, _>(|d| { | 56 | .on::<hir::diagnostics::UnresolvedModule, _>(|d| { |
55 | res.borrow_mut().push(diagnostic_with_fix(d, &sema)); | 57 | res.borrow_mut().push(diagnostic_with_fix(d, &sema)); |
56 | }) | 58 | }) |
@@ -64,10 +66,20 @@ pub(crate) fn diagnostics( | |||
64 | res.borrow_mut().push(diagnostic_with_fix(d, &sema)); | 66 | res.borrow_mut().push(diagnostic_with_fix(d, &sema)); |
65 | }) | 67 | }) |
66 | // Only collect experimental diagnostics when they're enabled. | 68 | // Only collect experimental diagnostics when they're enabled. |
67 | .filter(|diag| !diag.is_experimental() || enable_experimental) | 69 | .filter(|diag| !diag.is_experimental() || enable_experimental); |
70 | |||
71 | if !analysis_config.disabled_diagnostics.is_empty() { | ||
72 | // Do not collect disabled diagnostics. | ||
73 | sink_builder = | ||
74 | sink_builder.filter(|diag| !analysis_config.disabled_diagnostics.contains(diag.name())); | ||
75 | } | ||
76 | |||
77 | // Finalize the `DiagnosticSink` building process. | ||
78 | let mut sink = sink_builder | ||
68 | // Diagnostics not handled above get no fix and default treatment. | 79 | // Diagnostics not handled above get no fix and default treatment. |
69 | .build(|d| { | 80 | .build(|d| { |
70 | res.borrow_mut().push(Diagnostic { | 81 | res.borrow_mut().push(Diagnostic { |
82 | name: Some(d.name().into()), | ||
71 | message: d.message(), | 83 | message: d.message(), |
72 | range: sema.diagnostics_display_range(d).range, | 84 | range: sema.diagnostics_display_range(d).range, |
73 | severity: Severity::Error, | 85 | severity: Severity::Error, |
@@ -84,6 +96,7 @@ pub(crate) fn diagnostics( | |||
84 | 96 | ||
85 | fn diagnostic_with_fix<D: DiagnosticWithFix>(d: &D, sema: &Semantics<RootDatabase>) -> Diagnostic { | 97 | fn diagnostic_with_fix<D: DiagnosticWithFix>(d: &D, sema: &Semantics<RootDatabase>) -> Diagnostic { |
86 | Diagnostic { | 98 | Diagnostic { |
99 | name: Some(d.name().into()), | ||
87 | range: sema.diagnostics_display_range(d).range, | 100 | range: sema.diagnostics_display_range(d).range, |
88 | message: d.message(), | 101 | message: d.message(), |
89 | severity: Severity::Error, | 102 | severity: Severity::Error, |
@@ -110,6 +123,7 @@ fn check_unnecessary_braces_in_use_statement( | |||
110 | }); | 123 | }); |
111 | 124 | ||
112 | acc.push(Diagnostic { | 125 | acc.push(Diagnostic { |
126 | name: None, | ||
113 | range: use_range, | 127 | range: use_range, |
114 | message: "Unnecessary braces in use statement".to_string(), | 128 | message: "Unnecessary braces in use statement".to_string(), |
115 | severity: Severity::WeakWarning, | 129 | severity: Severity::WeakWarning, |
@@ -156,6 +170,7 @@ fn check_struct_shorthand_initialization( | |||
156 | 170 | ||
157 | let field_range = record_field.syntax().text_range(); | 171 | let field_range = record_field.syntax().text_range(); |
158 | acc.push(Diagnostic { | 172 | acc.push(Diagnostic { |
173 | name: None, | ||
159 | range: field_range, | 174 | range: field_range, |
160 | message: "Shorthand struct initialization".to_string(), | 175 | message: "Shorthand struct initialization".to_string(), |
161 | severity: Severity::WeakWarning, | 176 | severity: Severity::WeakWarning, |
@@ -173,10 +188,14 @@ fn check_struct_shorthand_initialization( | |||
173 | 188 | ||
174 | #[cfg(test)] | 189 | #[cfg(test)] |
175 | mod tests { | 190 | mod tests { |
191 | use std::collections::HashSet; | ||
176 | use stdx::trim_indent; | 192 | use stdx::trim_indent; |
177 | use test_utils::assert_eq_text; | 193 | use test_utils::assert_eq_text; |
178 | 194 | ||
179 | use crate::mock_analysis::{analysis_and_position, single_file, MockAnalysis}; | 195 | use crate::{ |
196 | mock_analysis::{analysis_and_position, single_file, MockAnalysis}, | ||
197 | AnalysisConfig, | ||
198 | }; | ||
180 | use expect::{expect, Expect}; | 199 | use expect::{expect, Expect}; |
181 | 200 | ||
182 | /// Takes a multi-file input fixture with annotated cursor positions, | 201 | /// Takes a multi-file input fixture with annotated cursor positions, |
@@ -240,6 +259,51 @@ mod tests { | |||
240 | assert_eq!(diagnostics.len(), 0, "unexpected diagnostics:\n{:#?}", diagnostics); | 259 | assert_eq!(diagnostics.len(), 0, "unexpected diagnostics:\n{:#?}", diagnostics); |
241 | } | 260 | } |
242 | 261 | ||
262 | /// Takes a multi-file input fixture with annotated cursor position and the list of disabled diagnostics, | ||
263 | /// and checks that provided diagnostics aren't spawned during analysis. | ||
264 | fn check_disabled_diagnostics(ra_fixture: &str, disabled_diagnostics: &[&'static str]) { | ||
265 | let disabled_diagnostics: HashSet<_> = | ||
266 | disabled_diagnostics.into_iter().map(|diag| diag.to_string()).collect(); | ||
267 | |||
268 | let mock = MockAnalysis::with_files(ra_fixture); | ||
269 | let files = mock.files().map(|(it, _)| it).collect::<Vec<_>>(); | ||
270 | let mut analysis = mock.analysis(); | ||
271 | analysis.set_config(AnalysisConfig { disabled_diagnostics: disabled_diagnostics.clone() }); | ||
272 | |||
273 | let diagnostics = files | ||
274 | .clone() | ||
275 | .into_iter() | ||
276 | .flat_map(|file_id| analysis.diagnostics(file_id, true).unwrap()) | ||
277 | .collect::<Vec<_>>(); | ||
278 | |||
279 | // First, we have to check that diagnostic is not emitted when it's added to the disabled diagnostics list. | ||
280 | for diagnostic in diagnostics { | ||
281 | if let Some(name) = diagnostic.name { | ||
282 | assert!(!disabled_diagnostics.contains(&name), "Diagnostic {} is disabled", name); | ||
283 | } | ||
284 | } | ||
285 | |||
286 | // Then, we must reset the config and repeat the check, so that we'll be sure that without | ||
287 | // config these diagnostics are emitted. | ||
288 | // This is required for tests to not become outdated if e.g. diagnostics name changes: | ||
289 | // without this additional run the test will pass simply because a diagnostic with an old name | ||
290 | // will no longer exist. | ||
291 | analysis.set_config(AnalysisConfig { disabled_diagnostics: Default::default() }); | ||
292 | |||
293 | let diagnostics = files | ||
294 | .into_iter() | ||
295 | .flat_map(|file_id| analysis.diagnostics(file_id, true).unwrap()) | ||
296 | .collect::<Vec<_>>(); | ||
297 | |||
298 | assert!( | ||
299 | diagnostics | ||
300 | .into_iter() | ||
301 | .filter_map(|diag| diag.name) | ||
302 | .any(|name| disabled_diagnostics.contains(&name)), | ||
303 | "At least one of the diagnostics was not emitted even without config; are the diagnostics names correct?" | ||
304 | ); | ||
305 | } | ||
306 | |||
243 | fn check_expect(ra_fixture: &str, expect: Expect) { | 307 | fn check_expect(ra_fixture: &str, expect: Expect) { |
244 | let (analysis, file_id) = single_file(ra_fixture); | 308 | let (analysis, file_id) = single_file(ra_fixture); |
245 | let diagnostics = analysis.diagnostics(file_id, true).unwrap(); | 309 | let diagnostics = analysis.diagnostics(file_id, true).unwrap(); |
@@ -502,6 +566,9 @@ fn test_fn() { | |||
502 | expect![[r#" | 566 | expect![[r#" |
503 | [ | 567 | [ |
504 | Diagnostic { | 568 | Diagnostic { |
569 | name: Some( | ||
570 | "unresolved-module", | ||
571 | ), | ||
505 | message: "unresolved module", | 572 | message: "unresolved module", |
506 | range: 0..8, | 573 | range: 0..8, |
507 | severity: Error, | 574 | severity: Error, |
@@ -675,4 +742,9 @@ struct Foo { | |||
675 | ", | 742 | ", |
676 | ) | 743 | ) |
677 | } | 744 | } |
745 | |||
746 | #[test] | ||
747 | fn test_disabled_diagnostics() { | ||
748 | check_disabled_diagnostics(r#"mod foo;"#, &["unresolved-module"]); | ||
749 | } | ||
678 | } | 750 | } |
diff --git a/crates/ide/src/lib.rs b/crates/ide/src/lib.rs index eb6389529..b762c994e 100644 --- a/crates/ide/src/lib.rs +++ b/crates/ide/src/lib.rs | |||
@@ -44,7 +44,7 @@ mod syntax_highlighting; | |||
44 | mod syntax_tree; | 44 | mod syntax_tree; |
45 | mod typing; | 45 | mod typing; |
46 | 46 | ||
47 | use std::sync::Arc; | 47 | use std::{collections::HashSet, sync::Arc}; |
48 | 48 | ||
49 | use base_db::{ | 49 | use base_db::{ |
50 | salsa::{self, ParallelDatabase}, | 50 | salsa::{self, ParallelDatabase}, |
@@ -99,8 +99,15 @@ pub use text_edit::{Indel, TextEdit}; | |||
99 | 99 | ||
100 | pub type Cancelable<T> = Result<T, Canceled>; | 100 | pub type Cancelable<T> = Result<T, Canceled>; |
101 | 101 | ||
102 | /// Configuration parameters for the analysis run. | ||
103 | #[derive(Debug, Default, Clone)] | ||
104 | pub struct AnalysisConfig { | ||
105 | pub disabled_diagnostics: HashSet<String>, | ||
106 | } | ||
107 | |||
102 | #[derive(Debug)] | 108 | #[derive(Debug)] |
103 | pub struct Diagnostic { | 109 | pub struct Diagnostic { |
110 | pub name: Option<String>, | ||
104 | pub message: String, | 111 | pub message: String, |
105 | pub range: TextRange, | 112 | pub range: TextRange, |
106 | pub severity: Severity, | 113 | pub severity: Severity, |
@@ -144,11 +151,16 @@ impl<T> RangeInfo<T> { | |||
144 | #[derive(Debug)] | 151 | #[derive(Debug)] |
145 | pub struct AnalysisHost { | 152 | pub struct AnalysisHost { |
146 | db: RootDatabase, | 153 | db: RootDatabase, |
154 | config: AnalysisConfig, | ||
147 | } | 155 | } |
148 | 156 | ||
149 | impl AnalysisHost { | 157 | impl AnalysisHost { |
150 | pub fn new(lru_capacity: Option<usize>) -> AnalysisHost { | 158 | pub fn new(lru_capacity: Option<usize>) -> Self { |
151 | AnalysisHost { db: RootDatabase::new(lru_capacity) } | 159 | Self::with_config(lru_capacity, AnalysisConfig::default()) |
160 | } | ||
161 | |||
162 | pub fn with_config(lru_capacity: Option<usize>, config: AnalysisConfig) -> Self { | ||
163 | AnalysisHost { db: RootDatabase::new(lru_capacity), config } | ||
152 | } | 164 | } |
153 | 165 | ||
154 | pub fn update_lru_capacity(&mut self, lru_capacity: Option<usize>) { | 166 | pub fn update_lru_capacity(&mut self, lru_capacity: Option<usize>) { |
@@ -158,7 +170,7 @@ impl AnalysisHost { | |||
158 | /// Returns a snapshot of the current state, which you can query for | 170 | /// Returns a snapshot of the current state, which you can query for |
159 | /// semantic information. | 171 | /// semantic information. |
160 | pub fn analysis(&self) -> Analysis { | 172 | pub fn analysis(&self) -> Analysis { |
161 | Analysis { db: self.db.snapshot() } | 173 | Analysis { db: self.db.snapshot(), config: self.config.clone() } |
162 | } | 174 | } |
163 | 175 | ||
164 | /// Applies changes to the current state of the world. If there are | 176 | /// Applies changes to the current state of the world. If there are |
@@ -202,6 +214,7 @@ impl Default for AnalysisHost { | |||
202 | #[derive(Debug)] | 214 | #[derive(Debug)] |
203 | pub struct Analysis { | 215 | pub struct Analysis { |
204 | db: salsa::Snapshot<RootDatabase>, | 216 | db: salsa::Snapshot<RootDatabase>, |
217 | config: AnalysisConfig, | ||
205 | } | 218 | } |
206 | 219 | ||
207 | // As a general design guideline, `Analysis` API are intended to be independent | 220 | // As a general design guideline, `Analysis` API are intended to be independent |
@@ -497,7 +510,7 @@ impl Analysis { | |||
497 | file_id: FileId, | 510 | file_id: FileId, |
498 | enable_experimental: bool, | 511 | enable_experimental: bool, |
499 | ) -> Cancelable<Vec<Diagnostic>> { | 512 | ) -> Cancelable<Vec<Diagnostic>> { |
500 | self.with_db(|db| diagnostics::diagnostics(db, file_id, enable_experimental)) | 513 | self.with_db(|db| diagnostics::diagnostics(db, file_id, enable_experimental, &self.config)) |
501 | } | 514 | } |
502 | 515 | ||
503 | /// Returns the edit required to rename reference at the position to the new | 516 | /// Returns the edit required to rename reference at the position to the new |
@@ -526,6 +539,11 @@ impl Analysis { | |||
526 | }) | 539 | }) |
527 | } | 540 | } |
528 | 541 | ||
542 | /// Sets the provided config. | ||
543 | pub fn set_config(&mut self, config: AnalysisConfig) { | ||
544 | self.config = config; | ||
545 | } | ||
546 | |||
529 | /// Performs an operation on that may be Canceled. | 547 | /// Performs an operation on that may be Canceled. |
530 | fn with_db<F, T>(&self, f: F) -> Cancelable<T> | 548 | fn with_db<F, T>(&self, f: F) -> Cancelable<T> |
531 | where | 549 | where |
diff --git a/crates/rust-analyzer/src/config.rs b/crates/rust-analyzer/src/config.rs index 33fb5e9c2..949824479 100644 --- a/crates/rust-analyzer/src/config.rs +++ b/crates/rust-analyzer/src/config.rs | |||
@@ -7,10 +7,10 @@ | |||
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 ide::{AssistConfig, CompletionConfig, HoverConfig, InlayHintsConfig}; | 13 | use ide::{AnalysisConfig, AssistConfig, CompletionConfig, HoverConfig, InlayHintsConfig}; |
14 | use lsp_types::ClientCapabilities; | 14 | use lsp_types::ClientCapabilities; |
15 | use project_model::{CargoConfig, ProjectJson, ProjectJsonData, ProjectManifest}; | 15 | use project_model::{CargoConfig, ProjectJson, ProjectJsonData, ProjectManifest}; |
16 | use serde::Deserialize; | 16 | use serde::Deserialize; |
@@ -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 212f98a30..8fa31f59c 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs | |||
@@ -108,7 +108,7 @@ impl GlobalState { | |||
108 | Handle { handle, receiver } | 108 | Handle { handle, receiver } |
109 | }; | 109 | }; |
110 | 110 | ||
111 | let analysis_host = AnalysisHost::new(config.lru_capacity); | 111 | let analysis_host = AnalysisHost::with_config(config.lru_capacity, config.analysis.clone()); |
112 | let (flycheck_sender, flycheck_receiver) = unbounded(); | 112 | let (flycheck_sender, flycheck_receiver) = unbounded(); |
113 | GlobalState { | 113 | GlobalState { |
114 | sender, | 114 | sender, |