Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rust/extractor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ impl<'a> Extractor<'a> {
}
}
translator.emit_source_file(&ast);
translator.emit_truncated_diagnostics_message();
translator.trap.commit().unwrap_or_else(|err| {
error!(
"Failed to write trap file for: {}: {}",
Expand Down
34 changes: 34 additions & 0 deletions rust/extractor/src/translate/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,14 @@ pub struct Translator<'a> {
resolve_paths: bool,
source_kind: SourceKind,
macro_context_depth: usize,
diagnostic_count: usize,
}

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

const DIAGNOSTIC_LIMIT_PER_FILE: usize = 100;

impl<'a> Translator<'a> {
pub fn new(
trap: TrapFile,
Expand All @@ -148,6 +151,7 @@ impl<'a> Translator<'a> {
resolve_paths: resolve_paths == ResolvePaths::Yes,
source_kind,
macro_context_depth: 0,
diagnostic_count: 0,
}
}
fn location(&self, range: TextRange) -> Option<(LineCol, LineCol)> {
Expand Down Expand Up @@ -234,6 +238,36 @@ impl<'a> Translator<'a> {
} else {
severity
};
if severity > DiagnosticSeverity::Debug {
self.diagnostic_count += 1;
if self.diagnostic_count > DIAGNOSTIC_LIMIT_PER_FILE {
return;
}
}
self.emit_diagnostic_unchecked(severity, tag, message, full_message, location);
}
pub fn emit_truncated_diagnostics_message(&mut self) {
if self.diagnostic_count > DIAGNOSTIC_LIMIT_PER_FILE {
let count = self.diagnostic_count - DIAGNOSTIC_LIMIT_PER_FILE;
self.emit_diagnostic_unchecked(
DiagnosticSeverity::Warning,
"diagnostics".to_owned(),
"Too many diagnostic messages".to_owned(),
format!(
"Too many diagnostic messages, {count} diagnostic messages were suppressed"
),
UNKNOWN_LOCATION,
);
}
}
fn emit_diagnostic_unchecked(
&mut self,
severity: DiagnosticSeverity,
tag: String,
message: String,
full_message: String,
location: (LineCol, LineCol),
) {
let (start, end) = location;
dispatch_to_tracing!(
severity,
Expand Down