@@ -127,11 +127,14 @@ pub struct Translator<'a> {
127127 resolve_paths : bool ,
128128 source_kind : SourceKind ,
129129 pub ( crate ) macro_context_depth : usize ,
130+ diagnostic_count : usize ,
130131}
131132
132133const UNKNOWN_LOCATION : ( LineCol , LineCol ) =
133134 ( LineCol { line : 0 , col : 0 } , LineCol { line : 0 , col : 0 } ) ;
134135
136+ const DIAGNOSTIC_LIMIT_PER_FILE : usize = 100 ;
137+
135138impl < ' a > Translator < ' a > {
136139 pub fn new (
137140 trap : TrapFile ,
@@ -152,6 +155,7 @@ impl<'a> Translator<'a> {
152155 resolve_paths : resolve_paths == ResolvePaths :: Yes ,
153156 source_kind,
154157 macro_context_depth : 0 ,
158+ diagnostic_count : 0 ,
155159 }
156160 }
157161 fn location ( & self , range : TextRange ) -> Option < ( LineCol , LineCol ) > {
@@ -238,6 +242,36 @@ impl<'a> Translator<'a> {
238242 } else {
239243 severity
240244 } ;
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+ ) {
241275 let ( start, end) = location;
242276 dispatch_to_tracing ! (
243277 severity,
0 commit comments