mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Only display experimental diagnostics when enabled
This commit is contained in:
parent
f6f49735e8
commit
92a4ec80a0
@ -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)
|
||||
}
|
||||
|
||||
|
@ -487,8 +487,12 @@ impl Analysis {
|
||||
}
|
||||
|
||||
/// Computes the set of diagnostics for the given file.
|
||||
pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> {
|
||||
self.with_db(|db| diagnostics::diagnostics(db, file_id))
|
||||
pub fn diagnostics(
|
||||
&self,
|
||||
file_id: FileId,
|
||||
enable_experimental: bool,
|
||||
) -> Cancelable<Vec<Diagnostic>> {
|
||||
self.with_db(|db| diagnostics::diagnostics(db, file_id, enable_experimental))
|
||||
}
|
||||
|
||||
/// Returns the edit required to rename reference at the position to the new
|
||||
|
@ -70,7 +70,7 @@ pub fn analysis_bench(
|
||||
match &what {
|
||||
BenchWhat::Highlight { .. } => {
|
||||
let res = do_work(&mut host, file_id, |analysis| {
|
||||
analysis.diagnostics(file_id).unwrap();
|
||||
analysis.diagnostics(file_id, true).unwrap();
|
||||
analysis.highlight_as_html(file_id, false).unwrap()
|
||||
});
|
||||
if verbosity.is_verbose() {
|
||||
|
@ -47,7 +47,7 @@ pub fn diagnostics(
|
||||
String::from("unknown")
|
||||
};
|
||||
println!("processing crate: {}, module: {}", crate_name, _vfs.file_path(file_id));
|
||||
for diagnostic in analysis.diagnostics(file_id).unwrap() {
|
||||
for diagnostic in analysis.diagnostics(file_id, true).unwrap() {
|
||||
if matches!(diagnostic.severity, Severity::Error) {
|
||||
found_error = true;
|
||||
}
|
||||
|
@ -774,7 +774,7 @@ fn handle_fixes(
|
||||
None => {}
|
||||
};
|
||||
|
||||
let diagnostics = snap.analysis.diagnostics(file_id)?;
|
||||
let diagnostics = snap.analysis.diagnostics(file_id, snap.config.experimental_diagnostics)?;
|
||||
|
||||
let fixes_from_diagnostics = diagnostics
|
||||
.into_iter()
|
||||
@ -1040,7 +1040,7 @@ pub(crate) fn publish_diagnostics(
|
||||
let line_index = snap.analysis.file_line_index(file_id)?;
|
||||
let diagnostics: Vec<Diagnostic> = snap
|
||||
.analysis
|
||||
.diagnostics(file_id)?
|
||||
.diagnostics(file_id, snap.config.experimental_diagnostics)?
|
||||
.into_iter()
|
||||
.map(|d| Diagnostic {
|
||||
range: to_proto::range(&line_index, d.range),
|
||||
|
Loading…
x
Reference in New Issue
Block a user