From 92a4ec80a0ce1dd834578f53ea3fd018530ec0e6 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 24 Jul 2020 17:39:44 +0200 Subject: Only display experimental diagnostics when enabled --- crates/ra_ide/src/diagnostics.rs | 17 ++++++++++++----- crates/ra_ide/src/lib.rs | 8 ++++++-- 2 files changed, 18 insertions(+), 7 deletions(-) (limited to 'crates/ra_ide') 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 { WeakWarning, } -pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec { +pub(crate) fn diagnostics( + db: &RootDatabase, + file_id: FileId, + enable_experimental: bool, +) -> Vec { let _p = profile("diagnostics"); let sema = Semantics::new(db); let parse = db.parse(file_id); @@ -116,6 +120,9 @@ pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec fix: missing_struct_field_fix(&sema, file_id, d), }) }) + // Only collect experimental diagnostics when they're enabled. + .filter(|diag| !diag.is_experimental() || enable_experimental) + // Diagnostics not handled above get no fix and default treatment. .build(|d| { res.borrow_mut().push(Diagnostic { message: d.message(), @@ -301,7 +308,7 @@ mod tests { let after = trim_indent(ra_fixture_after); let (analysis, file_position) = analysis_and_position(ra_fixture_before); - let diagnostic = analysis.diagnostics(file_position.file_id).unwrap().pop().unwrap(); + let diagnostic = analysis.diagnostics(file_position.file_id, true).unwrap().pop().unwrap(); let mut fix = diagnostic.fix.unwrap(); let edit = fix.source_change.source_file_edits.pop().unwrap().edit; let target_file_contents = analysis.file_text(file_position.file_id).unwrap(); @@ -327,7 +334,7 @@ mod tests { let ra_fixture_after = &trim_indent(ra_fixture_after); let (analysis, file_pos) = analysis_and_position(ra_fixture_before); let current_file_id = file_pos.file_id; - let diagnostic = analysis.diagnostics(current_file_id).unwrap().pop().unwrap(); + let diagnostic = analysis.diagnostics(current_file_id, true).unwrap().pop().unwrap(); let mut fix = diagnostic.fix.unwrap(); let edit = fix.source_change.source_file_edits.pop().unwrap(); let changed_file_id = edit.file_id; @@ -348,14 +355,14 @@ mod tests { let analysis = mock.analysis(); let diagnostics = files .into_iter() - .flat_map(|file_id| analysis.diagnostics(file_id).unwrap()) + .flat_map(|file_id| analysis.diagnostics(file_id, true).unwrap()) .collect::>(); assert_eq!(diagnostics.len(), 0, "unexpected diagnostics:\n{:#?}", diagnostics); } fn check_expect(ra_fixture: &str, expect: Expect) { let (analysis, file_id) = single_file(ra_fixture); - let diagnostics = analysis.diagnostics(file_id).unwrap(); + let diagnostics = analysis.diagnostics(file_id, true).unwrap(); expect.assert_debug_eq(&diagnostics) } 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 { } /// Computes the set of diagnostics for the given file. - pub fn diagnostics(&self, file_id: FileId) -> Cancelable> { - self.with_db(|db| diagnostics::diagnostics(db, file_id)) + pub fn diagnostics( + &self, + file_id: FileId, + enable_experimental: bool, + ) -> Cancelable> { + self.with_db(|db| diagnostics::diagnostics(db, file_id, enable_experimental)) } /// Returns the edit required to rename reference at the position to the new -- cgit v1.2.3