支持实时响应时解析编辑工具的代码行号

This commit is contained in:
xintaofei
2026-03-28 17:13:29 +08:00
parent 75139a1226
commit 0ab9d46b63
4 changed files with 84 additions and 11 deletions

View File

@@ -896,7 +896,15 @@ function buildDiffChunk(
const newStr =
typeof parsed.new_string === "string" ? parsed.new_string : ""
return buildUnifiedDiff(filePath, oldStr, newStr)
const diff = buildUnifiedDiff(filePath, oldStr, newStr)
if (!diff) return null
const startLine =
typeof parsed._start_line === "number" ? parsed._start_line : 0
if (startLine <= 1) return diff
return diff.replace(
/^@@ -(\d+),(\d+) \+(\d+),(\d+) @@/gm,
(_, _o, oc, _n, nc) => `@@ -${startLine},${oc} +${startLine},${nc} @@`
)
}
if (op === "write") {