@@ -127,11 +127,14 @@ pub struct Translator<'a> {
127
127
resolve_paths : bool ,
128
128
source_kind : SourceKind ,
129
129
pub ( crate ) macro_context_depth : usize ,
130
+ diagnostic_count : usize ,
130
131
}
131
132
132
133
const UNKNOWN_LOCATION : ( LineCol , LineCol ) =
133
134
( LineCol { line : 0 , col : 0 } , LineCol { line : 0 , col : 0 } ) ;
134
135
136
+ const DIAGNOSTIC_LIMIT_PER_FILE : usize = 100 ;
137
+
135
138
impl < ' a > Translator < ' a > {
136
139
pub fn new (
137
140
trap : TrapFile ,
@@ -152,6 +155,7 @@ impl<'a> Translator<'a> {
152
155
resolve_paths : resolve_paths == ResolvePaths :: Yes ,
153
156
source_kind,
154
157
macro_context_depth : 0 ,
158
+ diagnostic_count : 0 ,
155
159
}
156
160
}
157
161
fn location ( & self , range : TextRange ) -> Option < ( LineCol , LineCol ) > {
@@ -238,6 +242,36 @@ impl<'a> Translator<'a> {
238
242
} else {
239
243
severity
240
244
} ;
245
+ if severity > DiagnosticSeverity :: Debug {
246
+ self . diagnostic_count += 1 ;
247
+ if self . diagnostic_count > DIAGNOSTIC_LIMIT_PER_FILE {
248
+ return ;
249
+ }
250
+ }
251
+ self . emit_diagnostic_unchecked ( severity, tag, message, full_message, location) ;
252
+ }
253
+ pub fn emit_truncated_diagnostics_message ( & mut self ) {
254
+ if self . diagnostic_count > DIAGNOSTIC_LIMIT_PER_FILE {
255
+ let count = self . diagnostic_count - DIAGNOSTIC_LIMIT_PER_FILE ;
256
+ self . emit_diagnostic_unchecked (
257
+ DiagnosticSeverity :: Warning ,
258
+ "diagnostics" . to_owned ( ) ,
259
+ "Too many diagnostic messages" . to_owned ( ) ,
260
+ format ! (
261
+ "Too many diagnostic messages, {count} diagnostic messages were suppressed"
262
+ ) ,
263
+ UNKNOWN_LOCATION ,
264
+ ) ;
265
+ }
266
+ }
267
+ fn emit_diagnostic_unchecked (
268
+ & mut self ,
269
+ severity : DiagnosticSeverity ,
270
+ tag : String ,
271
+ message : String ,
272
+ full_message : String ,
273
+ location : ( LineCol , LineCol ) ,
274
+ ) {
241
275
let ( start, end) = location;
242
276
dispatch_to_tracing ! (
243
277
severity,
0 commit comments