@@ -123,11 +123,14 @@ pub struct Translator<'a> {
123123 resolve_paths : bool ,
124124 source_kind : SourceKind ,
125125 macro_context_depth : usize ,
126+ diagnostic_count : usize ,
126127}
127128
128129const UNKNOWN_LOCATION : ( LineCol , LineCol ) =
129130 ( LineCol { line : 0 , col : 0 } , LineCol { line : 0 , col : 0 } ) ;
130131
132+ const DIAGNOSTIC_LIMIT_PER_FILE : usize = 100 ;
133+
131134impl < ' a > Translator < ' a > {
132135 pub fn new (
133136 trap : TrapFile ,
@@ -148,6 +151,7 @@ impl<'a> Translator<'a> {
148151 resolve_paths : resolve_paths == ResolvePaths :: Yes ,
149152 source_kind,
150153 macro_context_depth : 0 ,
154+ diagnostic_count : 0 ,
151155 }
152156 }
153157 fn location ( & self , range : TextRange ) -> Option < ( LineCol , LineCol ) > {
@@ -234,6 +238,36 @@ impl<'a> Translator<'a> {
234238 } else {
235239 severity
236240 } ;
241+ if severity > DiagnosticSeverity :: Debug {
242+ self . diagnostic_count += 1 ;
243+ if self . diagnostic_count > DIAGNOSTIC_LIMIT_PER_FILE {
244+ return ;
245+ }
246+ }
247+ self . emit_diagnostic_unchecked ( severity, tag, message, full_message, location) ;
248+ }
249+ pub fn emit_truncated_diagnostics_message ( & mut self ) {
250+ if self . diagnostic_count > DIAGNOSTIC_LIMIT_PER_FILE {
251+ let count = self . diagnostic_count - DIAGNOSTIC_LIMIT_PER_FILE ;
252+ self . emit_diagnostic_unchecked (
253+ DiagnosticSeverity :: Warning ,
254+ "diagnostics" . to_owned ( ) ,
255+ "Too many diagnostic messages" . to_owned ( ) ,
256+ format ! (
257+ "Too many diagnostic messages, {count} diagnostic messages were suppressed"
258+ ) ,
259+ UNKNOWN_LOCATION ,
260+ ) ;
261+ }
262+ }
263+ fn emit_diagnostic_unchecked (
264+ & mut self ,
265+ severity : DiagnosticSeverity ,
266+ tag : String ,
267+ message : String ,
268+ full_message : String ,
269+ location : ( LineCol , LineCol ) ,
270+ ) {
237271 let ( start, end) = location;
238272 dispatch_to_tracing ! (
239273 severity,
0 commit comments