@@ -117,11 +117,14 @@ pub struct Translator<'a> {
117117 resolve_paths : bool ,
118118 source_kind : SourceKind ,
119119 macro_context_depth : usize ,
120+ diagnostic_count : usize ,
120121}
121122
122123const UNKNOWN_LOCATION : ( LineCol , LineCol ) =
123124 ( LineCol { line : 0 , col : 0 } , LineCol { line : 0 , col : 0 } ) ;
124125
126+ const DIAGNOSTIC_LIMIT_PER_FILE : usize = 100 ;
127+
125128impl < ' 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+ diagnostic_count : 0 ,
145149 }
146150 }
147151 fn location ( & self , range : TextRange ) -> Option < ( LineCol , LineCol ) > {
@@ -228,6 +232,36 @@ impl<'a> Translator<'a> {
228232 } else {
229233 severity
230234 } ;
235+ if severity > DiagnosticSeverity :: Debug {
236+ self . diagnostic_count += 1 ;
237+ if self . diagnostic_count > DIAGNOSTIC_LIMIT_PER_FILE {
238+ return ;
239+ }
240+ }
241+ self . emit_diagnostic_unchecked ( severity, tag, message, full_message, location) ;
242+ }
243+ pub fn emit_truncated_diagnostics_message ( & mut self ) {
244+ if self . diagnostic_count > DIAGNOSTIC_LIMIT_PER_FILE {
245+ let count = self . diagnostic_count - DIAGNOSTIC_LIMIT_PER_FILE ;
246+ self . emit_diagnostic_unchecked (
247+ DiagnosticSeverity :: Warning ,
248+ "diagnostics" . to_owned ( ) ,
249+ "Too many diagnostic messages" . to_owned ( ) ,
250+ format ! (
251+ "Too many diagnostic messages, {count} diagnostic messages were suppressed"
252+ ) ,
253+ UNKNOWN_LOCATION ,
254+ ) ;
255+ }
256+ }
257+ fn emit_diagnostic_unchecked (
258+ & mut self ,
259+ severity : DiagnosticSeverity ,
260+ tag : String ,
261+ message : String ,
262+ full_message : String ,
263+ location : ( LineCol , LineCol ) ,
264+ ) {
231265 let ( start, end) = location;
232266 dispatch_to_tracing ! (
233267 severity,
0 commit comments