mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Merge branch 'main' into redsun82/cargo-upgrade-3
This commit is contained in:
@@ -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: {}: {}",
|
||||
|
||||
@@ -127,11 +127,14 @@ pub struct Translator<'a> {
|
||||
resolve_paths: bool,
|
||||
source_kind: SourceKind,
|
||||
pub(crate) 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,
|
||||
@@ -152,6 +155,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)> {
|
||||
@@ -238,6 +242,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,
|
||||
|
||||
Reference in New Issue
Block a user