aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_ide/src/diagnostics.rs17
-rw-r--r--crates/ra_ide/src/lib.rs8
-rw-r--r--crates/rust-analyzer/src/cli/analysis_bench.rs2
-rw-r--r--crates/rust-analyzer/src/cli/diagnostics.rs2
-rw-r--r--crates/rust-analyzer/src/handlers.rs4
5 files changed, 22 insertions, 11 deletions
diff --git a/crates/ra_ide/src/diagnostics.rs b/crates/ra_ide/src/diagnostics.rs
index 8e715faa4..897177d05 100644
--- a/crates/ra_ide/src/diagnostics.rs
+++ b/crates/ra_ide/src/diagnostics.rs
@@ -29,7 +29,11 @@ pub enum Severity {
29 WeakWarning, 29 WeakWarning,
30} 30}
31 31
32pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic> { 32pub(crate) fn diagnostics(
33 db: &RootDatabase,
34 file_id: FileId,
35 enable_experimental: bool,
36) -> Vec<Diagnostic> {
33 let _p = profile("diagnostics"); 37 let _p = profile("diagnostics");
34 let sema = Semantics::new(db); 38 let sema = Semantics::new(db);
35 let parse = db.parse(file_id); 39 let parse = db.parse(file_id);
@@ -116,6 +120,9 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic>
116 fix: missing_struct_field_fix(&sema, file_id, d), 120 fix: missing_struct_field_fix(&sema, file_id, d),
117 }) 121 })
118 }) 122 })
123 // Only collect experimental diagnostics when they're enabled.
124 .filter(|diag| !diag.is_experimental() || enable_experimental)
125 // Diagnostics not handled above get no fix and default treatment.
119 .build(|d| { 126 .build(|d| {
120 res.borrow_mut().push(Diagnostic { 127 res.borrow_mut().push(Diagnostic {
121 message: d.message(), 128 message: d.message(),
@@ -301,7 +308,7 @@ mod tests {
301 let after = trim_indent(ra_fixture_after); 308 let after = trim_indent(ra_fixture_after);
302 309
303 let (analysis, file_position) = analysis_and_position(ra_fixture_before); 310 let (analysis, file_position) = analysis_and_position(ra_fixture_before);
304 let diagnostic = analysis.diagnostics(file_position.file_id).unwrap().pop().unwrap(); 311 let diagnostic = analysis.diagnostics(file_position.file_id, true).unwrap().pop().unwrap();
305 let mut fix = diagnostic.fix.unwrap(); 312 let mut fix = diagnostic.fix.unwrap();
306 let edit = fix.source_change.source_file_edits.pop().unwrap().edit; 313 let edit = fix.source_change.source_file_edits.pop().unwrap().edit;
307 let target_file_contents = analysis.file_text(file_position.file_id).unwrap(); 314 let target_file_contents = analysis.file_text(file_position.file_id).unwrap();
@@ -327,7 +334,7 @@ mod tests {
327 let ra_fixture_after = &trim_indent(ra_fixture_after); 334 let ra_fixture_after = &trim_indent(ra_fixture_after);
328 let (analysis, file_pos) = analysis_and_position(ra_fixture_before); 335 let (analysis, file_pos) = analysis_and_position(ra_fixture_before);
329 let current_file_id = file_pos.file_id; 336 let current_file_id = file_pos.file_id;
330 let diagnostic = analysis.diagnostics(current_file_id).unwrap().pop().unwrap(); 337 let diagnostic = analysis.diagnostics(current_file_id, true).unwrap().pop().unwrap();
331 let mut fix = diagnostic.fix.unwrap(); 338 let mut fix = diagnostic.fix.unwrap();
332 let edit = fix.source_change.source_file_edits.pop().unwrap(); 339 let edit = fix.source_change.source_file_edits.pop().unwrap();
333 let changed_file_id = edit.file_id; 340 let changed_file_id = edit.file_id;
@@ -348,14 +355,14 @@ mod tests {
348 let analysis = mock.analysis(); 355 let analysis = mock.analysis();
349 let diagnostics = files 356 let diagnostics = files
350 .into_iter() 357 .into_iter()
351 .flat_map(|file_id| analysis.diagnostics(file_id).unwrap()) 358 .flat_map(|file_id| analysis.diagnostics(file_id, true).unwrap())
352 .collect::<Vec<_>>(); 359 .collect::<Vec<_>>();
353 assert_eq!(diagnostics.len(), 0, "unexpected diagnostics:\n{:#?}", diagnostics); 360 assert_eq!(diagnostics.len(), 0, "unexpected diagnostics:\n{:#?}", diagnostics);
354 } 361 }
355 362
356 fn check_expect(ra_fixture: &str, expect: Expect) { 363 fn check_expect(ra_fixture: &str, expect: Expect) {
357 let (analysis, file_id) = single_file(ra_fixture); 364 let (analysis, file_id) = single_file(ra_fixture);
358 let diagnostics = analysis.diagnostics(file_id).unwrap(); 365 let diagnostics = analysis.diagnostics(file_id, true).unwrap();
359 expect.assert_debug_eq(&diagnostics) 366 expect.assert_debug_eq(&diagnostics)
360 } 367 }
361 368
diff --git a/crates/ra_ide/src/lib.rs b/crates/ra_ide/src/lib.rs
index 7356e947b..4c4d9f6fa 100644
--- a/crates/ra_ide/src/lib.rs
+++ b/crates/ra_ide/src/lib.rs
@@ -487,8 +487,12 @@ impl Analysis {
487 } 487 }
488 488
489 /// Computes the set of diagnostics for the given file. 489 /// Computes the set of diagnostics for the given file.
490 pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> { 490 pub fn diagnostics(
491 self.with_db(|db| diagnostics::diagnostics(db, file_id)) 491 &self,
492 file_id: FileId,
493 enable_experimental: bool,
494 ) -> Cancelable<Vec<Diagnostic>> {
495 self.with_db(|db| diagnostics::diagnostics(db, file_id, enable_experimental))
492 } 496 }
493 497
494 /// Returns the edit required to rename reference at the position to the new 498 /// Returns the edit required to rename reference at the position to the new
diff --git a/crates/rust-analyzer/src/cli/analysis_bench.rs b/crates/rust-analyzer/src/cli/analysis_bench.rs
index 9299879b7..076184ad6 100644
--- a/crates/rust-analyzer/src/cli/analysis_bench.rs
+++ b/crates/rust-analyzer/src/cli/analysis_bench.rs
@@ -70,7 +70,7 @@ pub fn analysis_bench(
70 match &what { 70 match &what {
71 BenchWhat::Highlight { .. } => { 71 BenchWhat::Highlight { .. } => {
72 let res = do_work(&mut host, file_id, |analysis| { 72 let res = do_work(&mut host, file_id, |analysis| {
73 analysis.diagnostics(file_id).unwrap(); 73 analysis.diagnostics(file_id, true).unwrap();
74 analysis.highlight_as_html(file_id, false).unwrap() 74 analysis.highlight_as_html(file_id, false).unwrap()
75 }); 75 });
76 if verbosity.is_verbose() { 76 if verbosity.is_verbose() {
diff --git a/crates/rust-analyzer/src/cli/diagnostics.rs b/crates/rust-analyzer/src/cli/diagnostics.rs
index 6f3c1c1f9..4ac8c8772 100644
--- a/crates/rust-analyzer/src/cli/diagnostics.rs
+++ b/crates/rust-analyzer/src/cli/diagnostics.rs
@@ -47,7 +47,7 @@ pub fn diagnostics(
47 String::from("unknown") 47 String::from("unknown")
48 }; 48 };
49 println!("processing crate: {}, module: {}", crate_name, _vfs.file_path(file_id)); 49 println!("processing crate: {}, module: {}", crate_name, _vfs.file_path(file_id));
50 for diagnostic in analysis.diagnostics(file_id).unwrap() { 50 for diagnostic in analysis.diagnostics(file_id, true).unwrap() {
51 if matches!(diagnostic.severity, Severity::Error) { 51 if matches!(diagnostic.severity, Severity::Error) {
52 found_error = true; 52 found_error = true;
53 } 53 }
diff --git a/crates/rust-analyzer/src/handlers.rs b/crates/rust-analyzer/src/handlers.rs
index cad92c444..cd309ed74 100644
--- a/crates/rust-analyzer/src/handlers.rs
+++ b/crates/rust-analyzer/src/handlers.rs
@@ -774,7 +774,7 @@ fn handle_fixes(
774 None => {} 774 None => {}
775 }; 775 };
776 776
777 let diagnostics = snap.analysis.diagnostics(file_id)?; 777 let diagnostics = snap.analysis.diagnostics(file_id, snap.config.experimental_diagnostics)?;
778 778
779 let fixes_from_diagnostics = diagnostics 779 let fixes_from_diagnostics = diagnostics
780 .into_iter() 780 .into_iter()
@@ -1040,7 +1040,7 @@ pub(crate) fn publish_diagnostics(
1040 let line_index = snap.analysis.file_line_index(file_id)?; 1040 let line_index = snap.analysis.file_line_index(file_id)?;
1041 let diagnostics: Vec<Diagnostic> = snap 1041 let diagnostics: Vec<Diagnostic> = snap
1042 .analysis 1042 .analysis
1043 .diagnostics(file_id)? 1043 .diagnostics(file_id, snap.config.experimental_diagnostics)?
1044 .into_iter() 1044 .into_iter()
1045 .map(|d| Diagnostic { 1045 .map(|d| Diagnostic {
1046 range: to_proto::range(&line_index, d.range), 1046 range: to_proto::range(&line_index, d.range),