Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 58bf593

Browse files
committed
Auto merge of rust-lang#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.
2 parents ef54168 + 87da256 commit 58bf593

File tree

1 file changed

+8
-1
lines changed
  • src/tools/rust-analyzer/crates/ide-diagnostics/src

1 file changed

+8
-1
lines changed

src/tools/rust-analyzer/crates/ide-diagnostics/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,13 @@ pub fn diagnostics(
311311
FileRange { file_id, range: err.range() },
312312
)
313313
}));
314+
let parse_errors = res.len();
314315

315316
let parse = sema.parse(file_id);
316317

318+
// FIXME: This iterates the entire file which is a rather expensive operation.
319+
// We should implement these differently in some form?
320+
// Salsa caching + incremental re-parse would be better here
317321
for node in parse.syntax().descendants() {
318322
handlers::useless_braces::useless_braces(&mut res, file_id, &node);
319323
handlers::field_shorthand::field_shorthand(&mut res, file_id, &node);
@@ -326,7 +330,10 @@ pub fn diagnostics(
326330

327331
let mut diags = Vec::new();
328332
match module {
329-
Some(m) => m.diagnostics(db, &mut diags, config.style_lints),
333+
// A bunch of parse errors in a file indicate some bigger structural parse changes in the
334+
// file, so we skip semantic diagnostics so we can show these faster.
335+
Some(m) if parse_errors < 16 => m.diagnostics(db, &mut diags, config.style_lints),
336+
Some(_) => (),
330337
None => handlers::unlinked_file::unlinked_file(&ctx, &mut res, file_id),
331338
}
332339

0 commit comments

Comments
 (0)