dsh-vscode-mode 0.29.0 → 0.29.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -4
- package/lib/index.js +402 -182
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/pending/hunks.ts +6 -150
- package/src/pending/lineDiff.ts +413 -0
- package/src/shared/review.ts +5 -0
package/README.md
CHANGED
|
@@ -217,6 +217,10 @@ Host 优先采集官方 `workspaceChanges` 的轮次净差异;旧版逐工具
|
|
|
217
217
|
执行后用回执 `items` 对齐——回执完成却没预读到的路径只记采集诊断,绝不伪造基线;
|
|
218
218
|
`dryRun` 预览不预读也不出条目。`ops_bash` 等非声明式写盘不在实时采集范围(git 工作区仍由官方每轮
|
|
219
219
|
快照展示;非 git 工作区可手动从版本库导入基线)。
|
|
220
|
+
- **差异精度**:行差异先裁公共前后缀,再按两侧唯一出现的相同行做锚点递归切分,
|
|
221
|
+
只在足够小的窗口内做 LCS;千行文件上的少量/分散改动按真实位置成块,不再因
|
|
222
|
+
单元格上限整段替换。只有窗口内确实没有可匹配行时才整段替换并标 `coarse`;
|
|
223
|
+
同时修正多 hunk 的 `oldStart/newStart` 行号(此前每块会多偏移一个上下文长度)。
|
|
220
224
|
- **采集诊断**:进程内按工作区最多 50 条、全局最多 500 条;会话/插件释放后清理,Host 重启不保留。
|
|
221
225
|
它不替代官方持久化采集完整性记录,也不绕过写回内容和 provider 原子版本守卫。
|
|
222
226
|
- **采集作用域**:写前冻结当前 `workingDirectory`、provider 与目标;写后读回完成才释放
|
|
@@ -593,13 +597,13 @@ profile 请替换为实际目标,不要把示例目录当成当前运行 profi
|
|
|
593
597
|
|
|
594
598
|
```bash
|
|
595
599
|
# ① Git 安装(clone + prepare 构建;推荐打固定 tag)
|
|
596
|
-
dsh plugin --profile web add github:Lenonss/DSH_VsCodeMode#v0.29.
|
|
600
|
+
dsh plugin --profile web add github:Lenonss/DSH_VsCodeMode#v0.29.1
|
|
597
601
|
|
|
598
602
|
# ② npm 注册表(发布到 npm 后)
|
|
599
|
-
dsh plugin --profile web add dsh-vscode-mode@0.29.
|
|
603
|
+
dsh plugin --profile web add dsh-vscode-mode@0.29.1
|
|
600
604
|
|
|
601
605
|
# ③ GitHub Release tgz 直装(Release asset 可用后)
|
|
602
|
-
dsh plugin --profile web add https://github.com/Lenonss/DSH_VsCodeMode/releases/download/v0.29.
|
|
606
|
+
dsh plugin --profile web add https://github.com/Lenonss/DSH_VsCodeMode/releases/download/v0.29.1/dsh-vscode-mode-0.29.1.tgz
|
|
603
607
|
```
|
|
604
608
|
|
|
605
609
|
> **DSH 版本政策(0.17.0 起)**:六项 DSH peer 仍统一声明为 `*`,另以
|
|
@@ -981,6 +985,7 @@ Keep All / Undo All 却是亮的。修复:单文件 Keep / Undo 覆盖冲突
|
|
|
981
985
|
|
|
982
986
|
| 版本 | 要点 |
|
|
983
987
|
| --- | --- |
|
|
988
|
+
| v0.29.1 | 待审行差异引擎精准化:唯一行锚点切分 + 小窗口 LCS,千行文件不再整段替换;修正多 hunk 行号偏移 |
|
|
984
989
|
| v0.29.0 | Excel 引擎与编解码改为按需分块(根包 930 KB,打开表格才加载 11.4 MB 引擎);调试 hover / 侧栏拖拽 / 快捷菜单测量性能优化;官方文件侧栏 CSS 运行时兼容 |
|
|
985
990
|
| v0.28.0 | dsh-ops 写工具纳入待审差异采集:ops_edit_file / ops_write_file / ops_remove / ops_copy / ops_move 可查看差异、Keep、Undo;ops_replace 按候选预读 + 回执对齐尽力采集 |
|
|
986
991
|
| v0.27.2 | 当前编辑文件 Tab 自动滚入可见区域;分组独立定位,适配宽度变化,不抢编辑焦点 |
|
|
@@ -998,7 +1003,18 @@ Keep All / Undo All 却是亮的。修复:单文件 Keep / Undo 覆盖冲突
|
|
|
998
1003
|
| v0.23.0 | 快捷菜单:可拖动悬浮按钮 + 自定义菜单树 |
|
|
999
1004
|
|
|
1000
1005
|
<details>
|
|
1001
|
-
<summary>完整版本记录(v0.29.
|
|
1006
|
+
<summary>完整版本记录(v0.29.1 → v0.1.5x,点击展开)</summary>
|
|
1007
|
+
|
|
1008
|
+
- **v0.29.1**:待审差异引擎重写——新增 `src/pending/lineDiff.ts`:先裁窗口公共前后缀,再按两侧
|
|
1009
|
+
唯一出现的相同行做锚点、按最长递增链切分,只在小窗口内做 LCS;单窗口 100 万单元格、单次差异
|
|
1010
|
+
1200 万单元格(约 80 ms)与深度 64 三层预算兜底。千行文件上的少量/分散改动不再因单元格上限
|
|
1011
|
+
整段替换,只有真正无锚点的区域才标 `coarse`。同版修正 `buildHunks` 每块重复计入 `head`
|
|
1012
|
+
导致的多 hunk 行号偏移(块 ID、行区间选块、删除行 gutter),并新增 9 例精准性/行号/重建/
|
|
1013
|
+
性能测试。验证:typecheck 0;全量 304 文件 3861 通过 / 22 跳过 + `node --test` 9/9;
|
|
1014
|
+
真实归档历史 20 个旧触发状态 20/20 精准(最坏 6,094,517 单元格从整段替换变为 -0/+76);
|
|
1015
|
+
Web 3080 真机重载前后对比:旧 host `coarse=true`/+1141/−1140/1 hunk → 新 host
|
|
1016
|
+
`coarse=false`/+2/−1/2 hunks;构建 host 1,101,565 B、根 client 930,057 B,产物校验通过。
|
|
1017
|
+
见 [0.29.1 发布说明](docs/release-0.29.1.md)。
|
|
1002
1018
|
|
|
1003
1019
|
- **v0.29.0**:Excel 引擎与编解码按需分块——根包不再内联 Univer / ExcelJS / fflate / saxes,打开表格才加载 `client.excel.js`(引擎面板)与 `client.excelcodec.js`(解码/导出);`ExcelHost` 负责加载与重试,`mountExcel` 复用同一引擎节点(切换文件不重建),`codecLoader` 单例懒加载,`lazyPanel` 扩展为通用 `loadChunk`。构建新增两个 chunk entry 并启用 minify,`check-client-artifacts` 增加逐 chunk 契约与根包 3 MB 预算 / 引擎下限,防止引擎被重新内联。同版性能修复:调试 hover 树的 MutationObserver 只处理本批次受影响 hover 并跳过 Monaco 展示层;侧栏拖拽宽度改为 rAF 合并绘制、pointerup 一次性提交;快捷菜单测量收敛到 `quickMeasure`;官方文件侧栏 CSS 以运行时补丁兼容(不改安装包)。验证:typecheck 0 error;全量 303 文件 3852 通过 / 22 跳过 + `node --test` 9/9;构建 host 1,093,961 B、根 client 930,057 B(v0.28.0 为 23,431,817 B)、client.excel.js 11,371,696 B、client.excelcodec.js 1,002,902 B,产物校验通过;Web 3080 真机冒烟:打开 xlsx 渲染 Univer 面板(canvas ×3)、侧栏拖拽 452→560 px、console 无本插件新增错误(host-bridge 404 来自 dsh-notify-me)。快捷菜单入口与调试 hover 树未做真机冒烟(入口未显示、需 DAP 会话),缺口保留。见 [0.29.0 发布说明](docs/release-0.29.0.md)。
|
|
1004
1020
|
- **v0.28.0**:把 dsh-ops 的写工具接进累计待审通道——`ops_edit_file` / `ops_write_file` / `ops_remove` / `ops_copy` / `ops_move` 执行前冻结写前基线、执行后读回真实内容,面板可查看差异、Keep 与 Undo;`ops_replace` 以替换作用域为搜索根按字面量预读候选(最多 16 个文件)、执行后用回执对齐,未预读到的文件只记缺口不伪造基线;`dryRun` 预览不采集。候选搜索直接走 `searchRipgrepContent`,不抢占用户的同根搜索。`ops_bash` 内的写盘、PTC 内联工具与非 git 工作区仍未覆盖:git 侧由官方快照列出但无字节证据,非 git 侧可走版本库导入 RPC 兜底。类型检查 0 error;全量 301 文件 3835 通过 / 22 跳过 + `node --test` 9/9;构建双面通过。Host 改动需重启 DSH 才生效,本次未安装、未重启,真实面板 Keep/Undo 冒烟缺口经维护者接受。参见 [0.28.0 发布说明](docs/release-0.28.0.md)。
|
package/lib/index.js
CHANGED
|
@@ -7099,7 +7099,7 @@ function rememberColdCwd(sessionId, cwd) {
|
|
|
7099
7099
|
/** dsh-remote-ssh 工作区标记文件名。 */
|
|
7100
7100
|
const MARKER = ".remote-ssh.json";
|
|
7101
7101
|
/** 向上探测的最大层数(含 cwd 自身;与上游 findMirrorRoot 的 8 层有界一致)。 */
|
|
7102
|
-
const MAX_DEPTH = 8;
|
|
7102
|
+
const MAX_DEPTH$1 = 8;
|
|
7103
7103
|
/** 探测结果 TTL(edrv.list 为 5s 轮询,避免每轮都做文件 IO)。 */
|
|
7104
7104
|
const TTL_MS = 6e4;
|
|
7105
7105
|
/** cwd → { at, ws } 探测缓存(含阴性结果)。 */
|
|
@@ -7137,7 +7137,7 @@ function markerWsOf(root, raw) {
|
|
|
7137
7137
|
*/
|
|
7138
7138
|
function walkRemoteWs(cwd) {
|
|
7139
7139
|
let dir = cwd;
|
|
7140
|
-
for (let i = 0; i < MAX_DEPTH; i++) {
|
|
7140
|
+
for (let i = 0; i < MAX_DEPTH$1; i++) {
|
|
7141
7141
|
try {
|
|
7142
7142
|
const ws = markerWsOf(dir, readFileSync(join(dir, MARKER), "utf8"));
|
|
7143
7143
|
if (ws) return ws;
|
|
@@ -11073,11 +11073,405 @@ function decodeXml(value) {
|
|
|
11073
11073
|
return value.replace(/</g, "<").replace(/>/g, ">").replace(/"/g, "\"").replace(/'/g, "'").replace(/&/g, "&");
|
|
11074
11074
|
}
|
|
11075
11075
|
//#endregion
|
|
11076
|
-
//#region src/pending/
|
|
11076
|
+
//#region src/pending/lineDiff.ts
|
|
11077
|
+
/** 单窗口 LCS 单元格上限:超过先找锚点;4 MB 表实测约 7 ms。 */
|
|
11078
|
+
const LCS_CELLS = 1e6;
|
|
11079
|
+
/** 一次差异的 LCS 总预算:防止病态输入拖慢 Host,约 80 ms 量级封顶。 */
|
|
11080
|
+
const WORK_CELLS = 12e6;
|
|
11081
|
+
/** 锚点递归深度上限:超过即把该窗口按整段替换处理。 */
|
|
11082
|
+
const MAX_DEPTH = 64;
|
|
11077
11083
|
/** 每个 hunk 的上下文行数。 */
|
|
11078
11084
|
const CONTEXT = 3;
|
|
11079
|
-
/**
|
|
11080
|
-
|
|
11085
|
+
/**
|
|
11086
|
+
* @public
|
|
11087
|
+
* @author ddj 2026年11月11号
|
|
11088
|
+
* @description: 计算两侧逻辑行的差异并装配 hunk;相同输入不产出 hunk。
|
|
11089
|
+
* @param oldLines 基线行
|
|
11090
|
+
* @param newLines 当前行
|
|
11091
|
+
* @returns hunk 列表与退化标记
|
|
11092
|
+
*/
|
|
11093
|
+
function lineHunks(oldLines, newLines) {
|
|
11094
|
+
if (sameLines(oldLines, newLines)) return {
|
|
11095
|
+
hunks: [],
|
|
11096
|
+
degraded: false
|
|
11097
|
+
};
|
|
11098
|
+
const work = {
|
|
11099
|
+
cells: 0,
|
|
11100
|
+
degraded: false
|
|
11101
|
+
};
|
|
11102
|
+
const ops = [];
|
|
11103
|
+
diffWindows(oldLines, 0, oldLines.length, newLines, 0, newLines.length, 0, work, ops);
|
|
11104
|
+
return {
|
|
11105
|
+
hunks: buildHunks(ops),
|
|
11106
|
+
degraded: work.degraded
|
|
11107
|
+
};
|
|
11108
|
+
}
|
|
11109
|
+
/**
|
|
11110
|
+
* @private
|
|
11111
|
+
* @author ddj 2026年11月11号
|
|
11112
|
+
* @description: 判断两组行是否逐行相同,避免为完全相同的文件生成整页上下文。
|
|
11113
|
+
* @param oldLines 基线行
|
|
11114
|
+
* @param newLines 当前行
|
|
11115
|
+
* @returns 是否逐行相同
|
|
11116
|
+
*/
|
|
11117
|
+
function sameLines(oldLines, newLines) {
|
|
11118
|
+
if (oldLines.length !== newLines.length) return false;
|
|
11119
|
+
return oldLines.every((text, index) => text === newLines[index]);
|
|
11120
|
+
}
|
|
11121
|
+
/**
|
|
11122
|
+
* @private
|
|
11123
|
+
* @author ddj 2026年11月11号
|
|
11124
|
+
* @description: 先裁当前窗口的公共前后缀并发成上下文行,再让中段进入核心比较。
|
|
11125
|
+
* @param oldLines 基线行
|
|
11126
|
+
* @param oldStart 基线窗口起点
|
|
11127
|
+
* @param oldCount 基线窗口行数
|
|
11128
|
+
* @param newLines 当前行
|
|
11129
|
+
* @param newStart 当前窗口起点
|
|
11130
|
+
* @param newCount 当前窗口行数
|
|
11131
|
+
* @param depth 递归深度
|
|
11132
|
+
* @param work 共享预算
|
|
11133
|
+
* @param ops 输出操作
|
|
11134
|
+
* @returns 无
|
|
11135
|
+
*/
|
|
11136
|
+
function diffWindows(oldLines, oldStart, oldCount, newLines, newStart, newCount, depth, work, ops) {
|
|
11137
|
+
let prefix = 0;
|
|
11138
|
+
while (prefix < oldCount && prefix < newCount && oldLines[oldStart + prefix] === newLines[newStart + prefix]) prefix++;
|
|
11139
|
+
let suffix = 0;
|
|
11140
|
+
while (suffix < oldCount - prefix && suffix < newCount - prefix && oldLines[oldStart + oldCount - 1 - suffix] === newLines[newStart + newCount - 1 - suffix]) suffix++;
|
|
11141
|
+
for (let index = 0; index < prefix; index++) ops.push({
|
|
11142
|
+
kind: " ",
|
|
11143
|
+
text: oldLines[oldStart + index]
|
|
11144
|
+
});
|
|
11145
|
+
diffCore(oldLines, oldStart + prefix, oldCount - prefix - suffix, newLines, newStart + prefix, newCount - prefix - suffix, depth, work, ops);
|
|
11146
|
+
for (let index = 0; index < suffix; index++) ops.push({
|
|
11147
|
+
kind: " ",
|
|
11148
|
+
text: oldLines[oldStart + oldCount - suffix + index]
|
|
11149
|
+
});
|
|
11150
|
+
}
|
|
11151
|
+
/**
|
|
11152
|
+
* @private
|
|
11153
|
+
* @author ddj 2026年11月11号
|
|
11154
|
+
* @description: 核心比较:小窗口做最优 LCS,大窗口按唯一行锚点递归切分,无锚点才整段替换。
|
|
11155
|
+
* @param oldLines 基线行
|
|
11156
|
+
* @param oldStart 基线窗口起点
|
|
11157
|
+
* @param oldCount 基线窗口行数
|
|
11158
|
+
* @param newLines 当前行
|
|
11159
|
+
* @param newStart 当前窗口起点
|
|
11160
|
+
* @param newCount 当前窗口行数
|
|
11161
|
+
* @param depth 递归深度
|
|
11162
|
+
* @param work 共享预算
|
|
11163
|
+
* @param ops 输出操作
|
|
11164
|
+
* @returns 无
|
|
11165
|
+
*/
|
|
11166
|
+
function diffCore(oldLines, oldStart, oldCount, newLines, newStart, newCount, depth, work, ops) {
|
|
11167
|
+
if (oldCount === 0) {
|
|
11168
|
+
for (let index = 0; index < newCount; index++) ops.push({
|
|
11169
|
+
kind: "+",
|
|
11170
|
+
text: newLines[newStart + index]
|
|
11171
|
+
});
|
|
11172
|
+
return;
|
|
11173
|
+
}
|
|
11174
|
+
if (newCount === 0) {
|
|
11175
|
+
for (let index = 0; index < oldCount; index++) ops.push({
|
|
11176
|
+
kind: "-",
|
|
11177
|
+
text: oldLines[oldStart + index]
|
|
11178
|
+
});
|
|
11179
|
+
return;
|
|
11180
|
+
}
|
|
11181
|
+
const cells = oldCount * newCount;
|
|
11182
|
+
if (cells <= LCS_CELLS && work.cells + cells <= WORK_CELLS) {
|
|
11183
|
+
runLcs(oldLines, oldStart, oldCount, newLines, newStart, newCount, work, ops);
|
|
11184
|
+
return;
|
|
11185
|
+
}
|
|
11186
|
+
if (depth >= MAX_DEPTH || work.cells >= WORK_CELLS) {
|
|
11187
|
+
appendReplace(oldLines, oldStart, oldCount, newLines, newStart, newCount, ops);
|
|
11188
|
+
work.degraded = true;
|
|
11189
|
+
return;
|
|
11190
|
+
}
|
|
11191
|
+
const anchors = pickAnchors(oldLines, oldStart, oldCount, newLines, newStart, newCount);
|
|
11192
|
+
if (anchors.length === 0) {
|
|
11193
|
+
appendReplace(oldLines, oldStart, oldCount, newLines, newStart, newCount, ops);
|
|
11194
|
+
work.degraded = true;
|
|
11195
|
+
return;
|
|
11196
|
+
}
|
|
11197
|
+
let oldOffset = 0;
|
|
11198
|
+
let newOffset = 0;
|
|
11199
|
+
for (const anchor of anchors) {
|
|
11200
|
+
diffWindows(oldLines, oldStart + oldOffset, anchor.oldIndex - oldOffset, newLines, newStart + newOffset, anchor.newIndex - newOffset, depth + 1, work, ops);
|
|
11201
|
+
ops.push({
|
|
11202
|
+
kind: " ",
|
|
11203
|
+
text: oldLines[oldStart + anchor.oldIndex]
|
|
11204
|
+
});
|
|
11205
|
+
oldOffset = anchor.oldIndex + 1;
|
|
11206
|
+
newOffset = anchor.newIndex + 1;
|
|
11207
|
+
}
|
|
11208
|
+
diffWindows(oldLines, oldStart + oldOffset, oldCount - oldOffset, newLines, newStart + newOffset, newCount - newOffset, depth + 1, work, ops);
|
|
11209
|
+
}
|
|
11210
|
+
/**
|
|
11211
|
+
* @private
|
|
11212
|
+
* @author ddj 2026年11月11号
|
|
11213
|
+
* @description: 在窗口内做最优 LCS;平局优先删行,保持与历史实现一致的 hunk 形状。
|
|
11214
|
+
* @param oldLines 基线行
|
|
11215
|
+
* @param oldStart 基线窗口起点
|
|
11216
|
+
* @param oldCount 基线窗口行数
|
|
11217
|
+
* @param newLines 当前行
|
|
11218
|
+
* @param newStart 当前窗口起点
|
|
11219
|
+
* @param newCount 当前窗口行数
|
|
11220
|
+
* @param work 共享预算
|
|
11221
|
+
* @param ops 输出操作
|
|
11222
|
+
* @returns 无
|
|
11223
|
+
*/
|
|
11224
|
+
function runLcs(oldLines, oldStart, oldCount, newLines, newStart, newCount, work, ops) {
|
|
11225
|
+
work.cells += oldCount * newCount;
|
|
11226
|
+
const cols = newCount + 1;
|
|
11227
|
+
const table = new Uint32Array((oldCount + 1) * cols);
|
|
11228
|
+
for (let oldIndex = oldCount - 1; oldIndex >= 0; oldIndex--) {
|
|
11229
|
+
const row = oldIndex * cols;
|
|
11230
|
+
const nextRow = row + cols;
|
|
11231
|
+
for (let newIndex = newCount - 1; newIndex >= 0; newIndex--) table[row + newIndex] = oldLines[oldStart + oldIndex] === newLines[newStart + newIndex] ? table[nextRow + newIndex + 1] + 1 : Math.max(table[nextRow + newIndex], table[row + newIndex + 1]);
|
|
11232
|
+
}
|
|
11233
|
+
let oldIndex = 0;
|
|
11234
|
+
let newIndex = 0;
|
|
11235
|
+
while (oldIndex < oldCount && newIndex < newCount) {
|
|
11236
|
+
if (oldLines[oldStart + oldIndex] === newLines[newStart + newIndex]) {
|
|
11237
|
+
ops.push({
|
|
11238
|
+
kind: " ",
|
|
11239
|
+
text: oldLines[oldStart + oldIndex]
|
|
11240
|
+
});
|
|
11241
|
+
oldIndex++;
|
|
11242
|
+
newIndex++;
|
|
11243
|
+
continue;
|
|
11244
|
+
}
|
|
11245
|
+
if (table[(oldIndex + 1) * cols + newIndex] >= table[oldIndex * cols + newIndex + 1]) {
|
|
11246
|
+
ops.push({
|
|
11247
|
+
kind: "-",
|
|
11248
|
+
text: oldLines[oldStart + oldIndex]
|
|
11249
|
+
});
|
|
11250
|
+
oldIndex++;
|
|
11251
|
+
} else {
|
|
11252
|
+
ops.push({
|
|
11253
|
+
kind: "+",
|
|
11254
|
+
text: newLines[newStart + newIndex]
|
|
11255
|
+
});
|
|
11256
|
+
newIndex++;
|
|
11257
|
+
}
|
|
11258
|
+
}
|
|
11259
|
+
while (oldIndex < oldCount) ops.push({
|
|
11260
|
+
kind: "-",
|
|
11261
|
+
text: oldLines[oldStart + oldIndex++]
|
|
11262
|
+
});
|
|
11263
|
+
while (newIndex < newCount) ops.push({
|
|
11264
|
+
kind: "+",
|
|
11265
|
+
text: newLines[newStart + newIndex++]
|
|
11266
|
+
});
|
|
11267
|
+
}
|
|
11268
|
+
/**
|
|
11269
|
+
* @private
|
|
11270
|
+
* @author ddj 2026年11月11号
|
|
11271
|
+
* @description: 退化口径:整段删除再整段新增,绝不谎报逐行对应。
|
|
11272
|
+
* @param oldLines 基线行
|
|
11273
|
+
* @param oldStart 基线窗口起点
|
|
11274
|
+
* @param oldCount 基线窗口行数
|
|
11275
|
+
* @param newLines 当前行
|
|
11276
|
+
* @param newStart 当前窗口起点
|
|
11277
|
+
* @param newCount 当前窗口行数
|
|
11278
|
+
* @param ops 输出操作
|
|
11279
|
+
* @returns 无
|
|
11280
|
+
*/
|
|
11281
|
+
function appendReplace(oldLines, oldStart, oldCount, newLines, newStart, newCount, ops) {
|
|
11282
|
+
for (let index = 0; index < oldCount; index++) ops.push({
|
|
11283
|
+
kind: "-",
|
|
11284
|
+
text: oldLines[oldStart + index]
|
|
11285
|
+
});
|
|
11286
|
+
for (let index = 0; index < newCount; index++) ops.push({
|
|
11287
|
+
kind: "+",
|
|
11288
|
+
text: newLines[newStart + index]
|
|
11289
|
+
});
|
|
11290
|
+
}
|
|
11291
|
+
/**
|
|
11292
|
+
* @private
|
|
11293
|
+
* @author ddj 2026年11月11号
|
|
11294
|
+
* @description: 取两侧都恰好出现一次的相同行做锚点,并按出现顺序取最长递增链,避免交叉配对。
|
|
11295
|
+
* @param oldLines 基线行
|
|
11296
|
+
* @param oldStart 基线窗口起点
|
|
11297
|
+
* @param oldCount 基线窗口行数
|
|
11298
|
+
* @param newLines 当前行
|
|
11299
|
+
* @param newStart 当前窗口起点
|
|
11300
|
+
* @param newCount 当前窗口行数
|
|
11301
|
+
* @returns 顺序递增的锚点列表
|
|
11302
|
+
*/
|
|
11303
|
+
function pickAnchors(oldLines, oldStart, oldCount, newLines, newStart, newCount) {
|
|
11304
|
+
const oldCounts = countRange(oldLines, oldStart, oldCount);
|
|
11305
|
+
const newCounts = countRange(newLines, newStart, newCount);
|
|
11306
|
+
const newIndexes = /* @__PURE__ */ new Map();
|
|
11307
|
+
for (let index = 0; index < newCount; index++) {
|
|
11308
|
+
const text = newLines[newStart + index];
|
|
11309
|
+
if (newCounts.get(text) === 1) newIndexes.set(text, index);
|
|
11310
|
+
}
|
|
11311
|
+
const pairs = [];
|
|
11312
|
+
for (let index = 0; index < oldCount; index++) {
|
|
11313
|
+
const text = oldLines[oldStart + index];
|
|
11314
|
+
if (oldCounts.get(text) !== 1) continue;
|
|
11315
|
+
const newIndex = newIndexes.get(text);
|
|
11316
|
+
if (newIndex === void 0) continue;
|
|
11317
|
+
pairs.push({
|
|
11318
|
+
oldIndex: index,
|
|
11319
|
+
newIndex
|
|
11320
|
+
});
|
|
11321
|
+
}
|
|
11322
|
+
return longestChain(pairs);
|
|
11323
|
+
}
|
|
11324
|
+
/**
|
|
11325
|
+
* @private
|
|
11326
|
+
* @author ddj 2026年11月11号
|
|
11327
|
+
* @description: 统计窗口内每一行文本的出现次数。
|
|
11328
|
+
* @param lines 行集合
|
|
11329
|
+
* @param start 窗口起点
|
|
11330
|
+
* @param count 窗口行数
|
|
11331
|
+
* @returns 行文本到出现次数的映射
|
|
11332
|
+
*/
|
|
11333
|
+
function countRange(lines, start, count) {
|
|
11334
|
+
const counts = /* @__PURE__ */ new Map();
|
|
11335
|
+
for (let index = 0; index < count; index++) {
|
|
11336
|
+
const text = lines[start + index];
|
|
11337
|
+
counts.set(text, (counts.get(text) ?? 0) + 1);
|
|
11338
|
+
}
|
|
11339
|
+
return counts;
|
|
11340
|
+
}
|
|
11341
|
+
/**
|
|
11342
|
+
* @private
|
|
11343
|
+
* @author ddj 2026年11月11号
|
|
11344
|
+
* @description: 按右侧下标做最长递增子序列(耐心排序 O(n log n)),保持锚点不交叉。
|
|
11345
|
+
* @param pairs 已按左侧下标升序的候选锚点
|
|
11346
|
+
* @returns 顺序递增的锚点子序列
|
|
11347
|
+
*/
|
|
11348
|
+
function longestChain(pairs) {
|
|
11349
|
+
const tails = [];
|
|
11350
|
+
const previous = new Array(pairs.length).fill(-1);
|
|
11351
|
+
for (let index = 0; index < pairs.length; index++) {
|
|
11352
|
+
const value = pairs[index].newIndex;
|
|
11353
|
+
let left = 0;
|
|
11354
|
+
let right = tails.length;
|
|
11355
|
+
while (left < right) {
|
|
11356
|
+
const middle = left + right >>> 1;
|
|
11357
|
+
if (pairs[tails[middle]].newIndex < value) left = middle + 1;
|
|
11358
|
+
else right = middle;
|
|
11359
|
+
}
|
|
11360
|
+
if (left > 0) previous[index] = tails[left - 1];
|
|
11361
|
+
tails[left] = index;
|
|
11362
|
+
}
|
|
11363
|
+
const ordered = [];
|
|
11364
|
+
let cursor = tails.length ? tails[tails.length - 1] : -1;
|
|
11365
|
+
while (cursor >= 0) {
|
|
11366
|
+
ordered.push(pairs[cursor]);
|
|
11367
|
+
cursor = previous[cursor];
|
|
11368
|
+
}
|
|
11369
|
+
return ordered.reverse();
|
|
11370
|
+
}
|
|
11371
|
+
/**
|
|
11372
|
+
* @private
|
|
11373
|
+
* @author ddj 2026年11月11号
|
|
11374
|
+
* @description: 把操作流装配成带上下文的 hunk;变化间隔不超过 2×上下文时合并同一 hunk。
|
|
11375
|
+
* 行号按已消费行数推进:head 已在主循环逐行计入,块结束只补 tail。
|
|
11376
|
+
* @param ops 完整操作流
|
|
11377
|
+
* @returns hunk 列表
|
|
11378
|
+
*/
|
|
11379
|
+
function buildHunks(ops) {
|
|
11380
|
+
const hunks = [];
|
|
11381
|
+
let index = 0;
|
|
11382
|
+
let oldLine = 0;
|
|
11383
|
+
let newLine = 0;
|
|
11384
|
+
while (index < ops.length) {
|
|
11385
|
+
if (ops[index].kind === " ") {
|
|
11386
|
+
oldLine++;
|
|
11387
|
+
newLine++;
|
|
11388
|
+
index++;
|
|
11389
|
+
continue;
|
|
11390
|
+
}
|
|
11391
|
+
const head = ops.slice(Math.max(0, index - CONTEXT), index);
|
|
11392
|
+
const { changes, stop } = collectChanges(ops, index);
|
|
11393
|
+
const tail = ops.slice(stop, stop + CONTEXT);
|
|
11394
|
+
hunks.push(makeHunk([
|
|
11395
|
+
...head,
|
|
11396
|
+
...changes,
|
|
11397
|
+
...tail
|
|
11398
|
+
], oldLine - head.length + 1, newLine - head.length + 1));
|
|
11399
|
+
for (const op of changes) {
|
|
11400
|
+
if (op.kind !== "+") oldLine++;
|
|
11401
|
+
if (op.kind !== "-") newLine++;
|
|
11402
|
+
}
|
|
11403
|
+
oldLine += tail.length;
|
|
11404
|
+
newLine += tail.length;
|
|
11405
|
+
index = stop + tail.length;
|
|
11406
|
+
}
|
|
11407
|
+
return hunks;
|
|
11408
|
+
}
|
|
11409
|
+
/**
|
|
11410
|
+
* @private
|
|
11411
|
+
* @author ddj 2026年11月11号
|
|
11412
|
+
* @description: 收集从首个变化开始的连续操作,直到遇到足够长的纯上下文段才停止。
|
|
11413
|
+
* @param ops 完整操作流
|
|
11414
|
+
* @param start 首个变化的位置
|
|
11415
|
+
* @returns 变化段操作与停止位置
|
|
11416
|
+
*/
|
|
11417
|
+
function collectChanges(ops, start) {
|
|
11418
|
+
const changes = [];
|
|
11419
|
+
let probe = start;
|
|
11420
|
+
while (probe < ops.length) {
|
|
11421
|
+
const op = ops[probe];
|
|
11422
|
+
if (op.kind !== " ") {
|
|
11423
|
+
changes.push(op);
|
|
11424
|
+
probe++;
|
|
11425
|
+
continue;
|
|
11426
|
+
}
|
|
11427
|
+
if (!hasChange(ops, probe)) break;
|
|
11428
|
+
changes.push(op);
|
|
11429
|
+
probe++;
|
|
11430
|
+
}
|
|
11431
|
+
return {
|
|
11432
|
+
changes,
|
|
11433
|
+
stop: probe
|
|
11434
|
+
};
|
|
11435
|
+
}
|
|
11436
|
+
/**
|
|
11437
|
+
* @private
|
|
11438
|
+
* @author ddj 2026年11月11号
|
|
11439
|
+
* @description: 判断上下文窗口内是否还有变化,用于决定是否把两处改动并进同一 hunk。
|
|
11440
|
+
* @param ops 完整操作流
|
|
11441
|
+
* @param at 待检查上下文段起点
|
|
11442
|
+
* @returns 窗口内是否含变化
|
|
11443
|
+
*/
|
|
11444
|
+
function hasChange(ops, at) {
|
|
11445
|
+
return ops.slice(at, at + 6 + 1).some((op) => op.kind !== " ");
|
|
11446
|
+
}
|
|
11447
|
+
/**
|
|
11448
|
+
* @private
|
|
11449
|
+
* @author ddj 2026年11月11号
|
|
11450
|
+
* @description: 由一段操作装配 hunk,并统计两侧行数。
|
|
11451
|
+
* @param ops 该 hunk 的操作
|
|
11452
|
+
* @param oldStart 基线起始行(1 基)
|
|
11453
|
+
* @param newStart 当前起始行(1 基)
|
|
11454
|
+
* @returns hunk
|
|
11455
|
+
*/
|
|
11456
|
+
function makeHunk(ops, oldStart, newStart) {
|
|
11457
|
+
let oldLines = 0;
|
|
11458
|
+
let newLines = 0;
|
|
11459
|
+
const lines = [];
|
|
11460
|
+
for (const op of ops) {
|
|
11461
|
+
if (op.kind !== "+") oldLines++;
|
|
11462
|
+
if (op.kind !== "-") newLines++;
|
|
11463
|
+
lines.push(op.kind + op.text);
|
|
11464
|
+
}
|
|
11465
|
+
return {
|
|
11466
|
+
oldStart,
|
|
11467
|
+
oldLines,
|
|
11468
|
+
newStart,
|
|
11469
|
+
newLines,
|
|
11470
|
+
lines
|
|
11471
|
+
};
|
|
11472
|
+
}
|
|
11473
|
+
//#endregion
|
|
11474
|
+
//#region src/pending/hunks.ts
|
|
11081
11475
|
/**
|
|
11082
11476
|
* @author ddj 2026年10月29号
|
|
11083
11477
|
* @description: 构造可直接交给官方渲染器的差异;两侧完全相同时返回空 hunk 列表。
|
|
@@ -11085,10 +11479,10 @@ const CELL_LIMIT = 1e6;
|
|
|
11085
11479
|
* @param display 展示名
|
|
11086
11480
|
* @param oldText 基线全文
|
|
11087
11481
|
* @param newText 当前全文
|
|
11088
|
-
* @returns
|
|
11482
|
+
* @returns 文本差异;coarse 表示比较中确有区域退化为整段替换
|
|
11089
11483
|
*/
|
|
11090
11484
|
function textDiff(path, display, oldText, newText) {
|
|
11091
|
-
const hunks =
|
|
11485
|
+
const { hunks, degraded } = lineHunks(logicalLines(oldText), logicalLines(newText));
|
|
11092
11486
|
return {
|
|
11093
11487
|
kind: "text",
|
|
11094
11488
|
path,
|
|
@@ -11096,7 +11490,7 @@ function textDiff(path, display, oldText, newText) {
|
|
|
11096
11490
|
before: true,
|
|
11097
11491
|
after: true,
|
|
11098
11492
|
hunks,
|
|
11099
|
-
coarse:
|
|
11493
|
+
coarse: degraded
|
|
11100
11494
|
};
|
|
11101
11495
|
}
|
|
11102
11496
|
/**
|
|
@@ -11173,180 +11567,6 @@ function locateSpan(lines, pattern) {
|
|
|
11173
11567
|
}
|
|
11174
11568
|
return at >= 0 ? at : null;
|
|
11175
11569
|
}
|
|
11176
|
-
/**
|
|
11177
|
-
* @author ddj 2026年10月29号
|
|
11178
|
-
* @description: 生成带上下文的标准 hunk 列表。
|
|
11179
|
-
* @param oldLines 基线行
|
|
11180
|
-
* @param newLines 当前行
|
|
11181
|
-
* @returns hunk 列表
|
|
11182
|
-
*/
|
|
11183
|
-
function buildHunks(oldLines, newLines) {
|
|
11184
|
-
const ops = diffLines(oldLines, newLines);
|
|
11185
|
-
const hunks = [];
|
|
11186
|
-
let index = 0;
|
|
11187
|
-
let oldLine = 0;
|
|
11188
|
-
let newLine = 0;
|
|
11189
|
-
while (index < ops.length) {
|
|
11190
|
-
if (ops[index].kind === " ") {
|
|
11191
|
-
oldLine++;
|
|
11192
|
-
newLine++;
|
|
11193
|
-
index++;
|
|
11194
|
-
continue;
|
|
11195
|
-
}
|
|
11196
|
-
const head = ops.slice(Math.max(0, index - CONTEXT), index);
|
|
11197
|
-
const collected = [];
|
|
11198
|
-
let probe = index;
|
|
11199
|
-
while (probe < ops.length) {
|
|
11200
|
-
const op = ops[probe];
|
|
11201
|
-
if (op.kind !== " ") {
|
|
11202
|
-
collected.push(op);
|
|
11203
|
-
probe++;
|
|
11204
|
-
continue;
|
|
11205
|
-
}
|
|
11206
|
-
if (ops.slice(probe, probe + 6 + 1).some((item) => item.kind !== " ")) {
|
|
11207
|
-
collected.push(op);
|
|
11208
|
-
probe++;
|
|
11209
|
-
continue;
|
|
11210
|
-
}
|
|
11211
|
-
break;
|
|
11212
|
-
}
|
|
11213
|
-
const tail = ops.slice(probe, probe + CONTEXT);
|
|
11214
|
-
const oldStartLine = oldLine - head.length + 1;
|
|
11215
|
-
const newStartLine = newLine - head.length + 1;
|
|
11216
|
-
hunks.push(makeHunk([
|
|
11217
|
-
...head,
|
|
11218
|
-
...collected,
|
|
11219
|
-
...tail
|
|
11220
|
-
], oldStartLine, newStartLine));
|
|
11221
|
-
for (const op of collected) {
|
|
11222
|
-
if (op.kind !== "+") oldLine++;
|
|
11223
|
-
if (op.kind !== "-") newLine++;
|
|
11224
|
-
}
|
|
11225
|
-
oldLine += head.length + tail.length;
|
|
11226
|
-
newLine += head.length + tail.length;
|
|
11227
|
-
index = probe + tail.length;
|
|
11228
|
-
}
|
|
11229
|
-
return hunks;
|
|
11230
|
-
}
|
|
11231
|
-
/**
|
|
11232
|
-
* @author ddj 2026年10月29号
|
|
11233
|
-
* @description: 由一段操作装配 hunk。
|
|
11234
|
-
* @param ops 该 hunk 的操作
|
|
11235
|
-
* @param oldStart 基线起始行
|
|
11236
|
-
* @param newStart 当前起始行
|
|
11237
|
-
* @returns hunk
|
|
11238
|
-
*/
|
|
11239
|
-
function makeHunk(ops, oldStart, newStart) {
|
|
11240
|
-
return {
|
|
11241
|
-
oldStart,
|
|
11242
|
-
oldLines: ops.filter((op) => op.kind !== "+").length,
|
|
11243
|
-
newStart,
|
|
11244
|
-
newLines: ops.filter((op) => op.kind !== "-").length,
|
|
11245
|
-
lines: ops.map((op) => op.kind + op.text)
|
|
11246
|
-
};
|
|
11247
|
-
}
|
|
11248
|
-
/**
|
|
11249
|
-
* @author ddj 2026年10月29号
|
|
11250
|
-
* @description: 行级差异:先剪公共前后缀,剩余部分在限额内做 LCS,超限按整段替换。
|
|
11251
|
-
* @param oldLines 基线行
|
|
11252
|
-
* @param newLines 当前行
|
|
11253
|
-
* @returns 顺序完整的操作列表
|
|
11254
|
-
*/
|
|
11255
|
-
function diffLines(oldLines, newLines) {
|
|
11256
|
-
let head = 0;
|
|
11257
|
-
while (head < oldLines.length && head < newLines.length && oldLines[head] === newLines[head]) head++;
|
|
11258
|
-
let tail = 0;
|
|
11259
|
-
while (tail < oldLines.length - head && tail < newLines.length - head && oldLines[oldLines.length - 1 - tail] === newLines[newLines.length - 1 - tail]) tail++;
|
|
11260
|
-
const left = oldLines.slice(head, oldLines.length - tail);
|
|
11261
|
-
const right = newLines.slice(head, newLines.length - tail);
|
|
11262
|
-
const middle = left.length * right.length > CELL_LIMIT ? coarseOps(left, right) : lcsOps(left, right);
|
|
11263
|
-
return [
|
|
11264
|
-
...oldLines.slice(0, head).map((text) => ({
|
|
11265
|
-
kind: " ",
|
|
11266
|
-
text
|
|
11267
|
-
})),
|
|
11268
|
-
...middle,
|
|
11269
|
-
...oldLines.slice(oldLines.length - tail).map((text) => ({
|
|
11270
|
-
kind: " ",
|
|
11271
|
-
text
|
|
11272
|
-
}))
|
|
11273
|
-
];
|
|
11274
|
-
}
|
|
11275
|
-
/**
|
|
11276
|
-
* @author ddj 2026年10月29号
|
|
11277
|
-
* @description: 超限时的退化口径:整段删除再整段新增,绝不谎报逐行对应。
|
|
11278
|
-
* @param left 基线剩余行
|
|
11279
|
-
* @param right 当前剩余行
|
|
11280
|
-
* @returns 操作列表
|
|
11281
|
-
*/
|
|
11282
|
-
function coarseOps(left, right) {
|
|
11283
|
-
return [...left.map((text) => ({
|
|
11284
|
-
kind: "-",
|
|
11285
|
-
text
|
|
11286
|
-
})), ...right.map((text) => ({
|
|
11287
|
-
kind: "+",
|
|
11288
|
-
text
|
|
11289
|
-
}))];
|
|
11290
|
-
}
|
|
11291
|
-
/**
|
|
11292
|
-
* @author ddj 2026年10月29号
|
|
11293
|
-
* @description: 限额内的 LCS 行差异。
|
|
11294
|
-
* @param left 基线剩余行
|
|
11295
|
-
* @param right 当前剩余行
|
|
11296
|
-
* @returns 操作列表
|
|
11297
|
-
*/
|
|
11298
|
-
function lcsOps(left, right) {
|
|
11299
|
-
const rows = left.length + 1;
|
|
11300
|
-
const cols = right.length + 1;
|
|
11301
|
-
const table = new Uint32Array(rows * cols);
|
|
11302
|
-
for (let i = left.length - 1; i >= 0; i--) for (let j = right.length - 1; j >= 0; j--) table[i * cols + j] = left[i] === right[j] ? table[(i + 1) * cols + j + 1] + 1 : Math.max(table[(i + 1) * cols + j], table[i * cols + j + 1]);
|
|
11303
|
-
const ops = [];
|
|
11304
|
-
let i = 0;
|
|
11305
|
-
let j = 0;
|
|
11306
|
-
while (i < left.length && j < right.length) {
|
|
11307
|
-
if (left[i] === right[j]) {
|
|
11308
|
-
ops.push({
|
|
11309
|
-
kind: " ",
|
|
11310
|
-
text: left[i]
|
|
11311
|
-
});
|
|
11312
|
-
i++;
|
|
11313
|
-
j++;
|
|
11314
|
-
continue;
|
|
11315
|
-
}
|
|
11316
|
-
if (table[(i + 1) * cols + j] >= table[i * cols + j + 1]) {
|
|
11317
|
-
ops.push({
|
|
11318
|
-
kind: "-",
|
|
11319
|
-
text: left[i]
|
|
11320
|
-
});
|
|
11321
|
-
i++;
|
|
11322
|
-
} else {
|
|
11323
|
-
ops.push({
|
|
11324
|
-
kind: "+",
|
|
11325
|
-
text: right[j]
|
|
11326
|
-
});
|
|
11327
|
-
j++;
|
|
11328
|
-
}
|
|
11329
|
-
}
|
|
11330
|
-
while (i < left.length) ops.push({
|
|
11331
|
-
kind: "-",
|
|
11332
|
-
text: left[i++]
|
|
11333
|
-
});
|
|
11334
|
-
while (j < right.length) ops.push({
|
|
11335
|
-
kind: "+",
|
|
11336
|
-
text: right[j++]
|
|
11337
|
-
});
|
|
11338
|
-
return ops;
|
|
11339
|
-
}
|
|
11340
|
-
/**
|
|
11341
|
-
* @author ddj 2026年10月29号
|
|
11342
|
-
* @description: 判断这次差异是否触发了大文件退化口径。
|
|
11343
|
-
* @param oldText 基线全文
|
|
11344
|
-
* @param newText 当前全文
|
|
11345
|
-
* @returns 是否粗粒度
|
|
11346
|
-
*/
|
|
11347
|
-
function isCoarse(oldText, newText) {
|
|
11348
|
-
return logicalLines(oldText).length * logicalLines(newText).length > CELL_LIMIT;
|
|
11349
|
-
}
|
|
11350
11570
|
//#endregion
|
|
11351
11571
|
//#region src/pending/kernel.ts
|
|
11352
11572
|
/**
|