feat(parser/diff): default max diff lines 50
All checks were successful
submodules sync / sync (push) Successful in 55s
build / build (push) Successful in 2m34s
build / trigger-build-image (push) Successful in 14s

This commit is contained in:
张泊明518370910136 2025-03-28 08:58:48 -04:00
parent 29c05f4b36
commit 7f7eead5f7
GPG Key ID: D47306D7062CDA9D
2 changed files with 13 additions and 1 deletions

View File

@ -21,6 +21,7 @@ type Conf struct {
AlwaysHide bool
ForceQuitOnDiff bool
MaxDiffLength int `default:"2048"` // just for reference
MaxDiffLines int `default:"50"` // just for reference
}
}
}

View File

@ -68,10 +68,13 @@ func (*Diff) Run(results []stage.ExecutorResult, confAny any) (
if output.MaxDiffLength == 0 { // real default value
output.MaxDiffLength = 2048
}
if output.MaxDiffLines == 0 { // real default value
output.MaxDiffLines = 50
}
// Convert answer to string and split by lines
truncated := false
answerStr := string(answer)
resultStr := result.Files[output.FileName]
truncated := false
if len(answerStr) > output.MaxDiffLength {
answerStr = answerStr[:output.MaxDiffLength]
truncated = true
@ -82,6 +85,14 @@ func (*Diff) Run(results []stage.ExecutorResult, confAny any) (
}
answerLines := strings.Split(answerStr, "\n")
resultLines := strings.Split(resultStr, "\n")
if len(answerLines) > output.MaxDiffLines {
answerLines = answerLines[:output.MaxDiffLines]
truncated = true
}
if len(resultLines) > output.MaxDiffLines {
resultLines = resultLines[:output.MaxDiffLines]
truncated = true
}
diffs := patienceDiff(
answerLines,
resultLines,