Skip to content

Commit bd214b4

Browse files
committed
Rust: limit number of diagnostics to 100 per trap file
1 parent f5ea929 commit bd214b4

File tree

1 file changed

+6
-1
lines changed
  • rust/extractor/src/translate

1 file changed

+6
-1
lines changed

rust/extractor/src/translate/base.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,14 @@ pub struct Translator<'a> {
117117
resolve_paths: bool,
118118
source_kind: SourceKind,
119119
macro_context_depth: usize,
120+
emit_diagnostic_limit: usize,
120121
}
121122

122123
const UNKNOWN_LOCATION: (LineCol, LineCol) =
123124
(LineCol { line: 0, col: 0 }, LineCol { line: 0, col: 0 });
124125

126+
const EMIT_DIAGNOSTIC_LIMIT_PER_FILE: usize = 100;
127+
125128
impl<'a> Translator<'a> {
126129
pub fn new(
127130
trap: TrapFile,
@@ -142,6 +145,7 @@ impl<'a> Translator<'a> {
142145
resolve_paths: resolve_paths == ResolvePaths::Yes,
143146
source_kind,
144147
macro_context_depth: 0,
148+
emit_diagnostic_limit: EMIT_DIAGNOSTIC_LIMIT_PER_FILE,
145149
}
146150
}
147151
fn location(&self, range: TextRange) -> Option<(LineCol, LineCol)> {
@@ -238,7 +242,8 @@ impl<'a> Translator<'a> {
238242
&full_message,
239243
);
240244

241-
if severity > DiagnosticSeverity::Debug {
245+
if severity > DiagnosticSeverity::Debug && self.emit_diagnostic_limit > 0 {
246+
self.diagnostic_count -= 1;
242247
let location = self.trap.emit_location_label(self.label, start, end);
243248
self.trap
244249
.emit_diagnostic(severity, tag, message, full_message, location);

0 commit comments

Comments
 (0)