mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 15:15:24 +00:00
Only display experimental diagnostics when enabled
This commit is contained in:
parent
f6f49735e8
commit
92a4ec80a0
5 changed files with 22 additions and 11 deletions
|
@ -29,7 +29,11 @@ pub enum Severity {
|
|||
WeakWarning,
|
||||
}
|
||||
|
||||
pub(crate) fn diagnostics(db: &RootDatabase, file_id: FileId) -> Vec<Diagnostic> {
|
||||
pub(crate) fn diagnostics(
|
||||
db: &RootDatabase,
|
||||
file_id: FileId,
|
||||
enable_experimental: bool,
|
||||
) -> Vec<Diagnostic> {
|
||||
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<Diagnostic>
|
|||
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::<Vec<_>>();
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue