mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-28 04:45:05 +00:00
Auto merge of #17536 - Veykril:syntax-diags, r=Veykril
fix: Don't emit semantic diagnostics in files with a lot of syntax errors These will only add to the noise when something very unexpected breaks or where parser recovery fails to kick in.
This commit is contained in:
commit
cae997e338
1 changed files with 8 additions and 1 deletions
|
@ -311,9 +311,13 @@ pub fn diagnostics(
|
||||||
FileRange { file_id, range: err.range() },
|
FileRange { file_id, range: err.range() },
|
||||||
)
|
)
|
||||||
}));
|
}));
|
||||||
|
let parse_errors = res.len();
|
||||||
|
|
||||||
let parse = sema.parse(file_id);
|
let parse = sema.parse(file_id);
|
||||||
|
|
||||||
|
// FIXME: This iterates the entire file which is a rather expensive operation.
|
||||||
|
// We should implement these differently in some form?
|
||||||
|
// Salsa caching + incremental re-parse would be better here
|
||||||
for node in parse.syntax().descendants() {
|
for node in parse.syntax().descendants() {
|
||||||
handlers::useless_braces::useless_braces(&mut res, file_id, &node);
|
handlers::useless_braces::useless_braces(&mut res, file_id, &node);
|
||||||
handlers::field_shorthand::field_shorthand(&mut res, file_id, &node);
|
handlers::field_shorthand::field_shorthand(&mut res, file_id, &node);
|
||||||
|
@ -326,7 +330,10 @@ pub fn diagnostics(
|
||||||
|
|
||||||
let mut diags = Vec::new();
|
let mut diags = Vec::new();
|
||||||
match module {
|
match module {
|
||||||
Some(m) => m.diagnostics(db, &mut diags, config.style_lints),
|
// A bunch of parse errors in a file indicate some bigger structural parse changes in the
|
||||||
|
// file, so we skip semantic diagnostics so we can show these faster.
|
||||||
|
Some(m) if parse_errors < 16 => m.diagnostics(db, &mut diags, config.style_lints),
|
||||||
|
Some(_) => (),
|
||||||
None => handlers::unlinked_file::unlinked_file(&ctx, &mut res, file_id),
|
None => handlers::unlinked_file::unlinked_file(&ctx, &mut res, file_id),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue