feat: add ErrorContextAnalyser for sliding-window error/warning surfacing
Walks Entry[] once and emits one ErrorContextProblem per ERROR or WARNING entry, attaching up to 20 entries before and 20 after as context. Overlapping windows clip the second hit's before- and after-ranges so no Entry appears in two context arrays. Caps emission at 500 hits and adds an ErrorContextTruncatedInformation when reached. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace IndifferentKetchup\Codex\Analysis\ProjectZomboid;
|
||||
|
||||
use IndifferentKetchup\Codex\Analysis\Information;
|
||||
use IndifferentKetchup\Codex\Analysis\InsightInterface;
|
||||
|
||||
/**
|
||||
* Emitted by ErrorContextAnalyser exactly once when its hit cap is
|
||||
* reached, so downstream consumers can surface a "results truncated"
|
||||
* notice instead of silently dropping subsequent error/warning hits.
|
||||
*/
|
||||
class ErrorContextTruncatedInformation extends Information
|
||||
{
|
||||
private int $hitCap = 0;
|
||||
|
||||
/**
|
||||
* @param int $hitCap the cap that was hit (mirrors
|
||||
* ErrorContextAnalyser::HIT_CAP at emission time)
|
||||
* @return $this
|
||||
*/
|
||||
public function setHitCap(int $hitCap): static
|
||||
{
|
||||
$this->hitCap = $hitCap;
|
||||
$this->setLabel('Error context');
|
||||
$this->setValue(sprintf('truncated after %d hits', $hitCap));
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getHitCap(): int
|
||||
{
|
||||
return $this->hitCap;
|
||||
}
|
||||
|
||||
public function isEqual(InsightInterface $insight): bool
|
||||
{
|
||||
return $insight instanceof self;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user