@osovv/vv-opencode 1.2.5 → 1.2.7
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/CHANGELOG.md +16 -0
- package/README.md +1 -1
- package/dist/commands/completion.js +1 -1
- package/dist/commands/completion.js.map +1 -1
- package/dist/commands/patch-provider.d.ts +51 -1
- package/dist/commands/patch-provider.js +53 -2
- package/dist/commands/patch-provider.js.map +1 -1
- package/dist/lib/vvoc-preset-registry.d.ts +1 -1
- package/dist/lib/vvoc-preset-registry.js +2 -2
- package/dist/lib/vvoc-preset-registry.js.map +1 -1
- package/dist/plugins/hashline-edit/edit-operation-primitives.d.ts +2 -2
- package/dist/plugins/hashline-edit/edit-operation-primitives.js +37 -37
- package/dist/plugins/hashline-edit/edit-operation-primitives.js.map +1 -1
- package/dist/plugins/hashline-edit/edit-operations.d.ts +1 -0
- package/dist/plugins/hashline-edit/edit-operations.js +17 -10
- package/dist/plugins/hashline-edit/edit-operations.js.map +1 -1
- package/dist/plugins/hashline-edit/edit-text-normalization.d.ts +27 -4
- package/dist/plugins/hashline-edit/edit-text-normalization.js +45 -56
- package/dist/plugins/hashline-edit/edit-text-normalization.js.map +1 -1
- package/dist/plugins/hashline-edit/index.js +61 -4
- package/dist/plugins/hashline-edit/index.js.map +1 -1
- package/dist/plugins/hashline-edit/normalize-edits.js +37 -5
- package/dist/plugins/hashline-edit/normalize-edits.js.map +1 -1
- package/dist/plugins/hashline-edit/tool-description.d.ts +1 -1
- package/dist/plugins/hashline-edit/tool-description.js +16 -11
- package/dist/plugins/hashline-edit/tool-description.js.map +1 -1
- package/package.json +1 -1
- package/schemas/vvoc/v3.json +1 -1
- package/dist/plugins/hashline-edit/autocorrect-replacement-lines.d.ts +0 -1
- package/dist/plugins/hashline-edit/autocorrect-replacement-lines.js +0 -188
- package/dist/plugins/hashline-edit/autocorrect-replacement-lines.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const HASHLINE_EDIT_DESCRIPTION = "Edit files using exact hash-anchored line references from the latest Read output.\n\n<must>\n1. SNAPSHOT: All edits in one call reference the ORIGINAL file state. Do NOT adjust line numbers for prior edits in the same batch \u2014 the system applies them bottom-up automatically.\n2. replace replaces ONE line at pos. It does NOT accept end. For multi-line replacement, use replace_range.\n3. replace_range with pos+end replaces ALL lines FROM pos THROUGH end (BOTH INCLUSIVE). The end line WILL BE replaced. If you set end to a line that belongs to the next function/method/statement, that line is DELETED.\n CORRECT: pos on the first line to replace, end on the LAST line to replace \u2014 not the line after.\n4. lines must contain ONLY the content that belongs inside the replaced range. Lines AFTER end survive unchanged \u2014 do NOT include them in lines. If you do, they will appear twice.\n INSERTION SAFETY: To add a function, handler, statement, or block NEXT TO existing code, use append/prepend anchored to a surviving line. To add code AFTER a closed block, append after its final structural closing line. Do NOT replace that closing line merely to reproduce it and add content after it.\n STRUCTURAL CLOSURES: If replace_range intentionally consumes lines containing closing syntax such as }, });, ], ), );, or </tag>, lines MUST include every closure required by the resulting code. Never assume
|
|
1
|
+
export declare const HASHLINE_EDIT_DESCRIPTION = "Edit files using exact hash-anchored line references from the latest Read output.\n\n<must>\n1. SNAPSHOT: All edits in one call reference the ORIGINAL file state. Do NOT adjust line numbers for prior edits in the same batch \u2014 the system applies them bottom-up automatically.\n2. replace replaces ONE line at pos. It does NOT accept end. For multi-line replacement, use replace_range.\n3. replace_range with pos+end replaces ALL lines FROM pos THROUGH end (BOTH INCLUSIVE). The end line WILL BE replaced. If you set end to a line that belongs to the next function/method/statement, that line is DELETED.\n CORRECT: pos on the first line to replace, end on the LAST line to replace \u2014 not the line after.\n4. lines must contain ONLY the content that belongs inside the replaced range. Lines AFTER end survive unchanged \u2014 do NOT include them in lines. If you do, they will appear twice.\n INSERTION SAFETY: To add a function, handler, statement, or block NEXT TO existing code, use append/prepend anchored to a surviving line. To add code AFTER a closed block, append after its final structural closing line. Do NOT replace that closing line merely to reproduce it and add content after it.\n STRUCTURAL CLOSURES: If replace_range intentionally consumes lines containing closing syntax such as }, });, ], ), );, or </tag>, lines MUST include every closure required by the resulting code. Never assume the tool reconstructs omitted closing syntax.\n5. Tags MUST be copied exactly from read output or >>> mismatch output. NEVER guess or reconstruct tags.\n6. Batch = multiple operations in edits[], NOT one big replace covering everything. Each operation targets the smallest possible change.\n7. lines must contain plain replacement text only (no LINE#HASH#ANCHOR| prefixes, no diff + markers).\n8. CRITICAL: Double-quote characters inside lines strings MUST be escaped as \\\". Unescaped \\\" inside a JSON string will break the parser. Example: [\"const x = \\\"hello\\\";\"] \u2014 NOT [\"const x = \"hello\";\"]. Single quotes and backticks do NOT need escaping.\n9. LITERAL APPLICATION: payloads are applied byte-for-byte. There is NO merging, splitting, indentation fixing, or other content rewriting. The only automatic removals are exact duplicate echoes, and each one is reported as a Warning line in the result.\n10. PHYSICAL LINES: every string[] entry in lines must be exactly one physical line. Entries with embedded newlines are rejected. A string value is split on newlines.\n11. DELETION: to delete lines use lines: [] or lines: null with replace/replace_range. lines: [\"\"] is REJECTED because a single blank line is ambiguous \u2014 use append/prepend when you really want to insert a blank line.\n12. VERIFY: successful results include a bounded diff (@@ block) of what changed. Check that it matches your intent before moving on.\n</must>\n\n<operations>\nANCHOR FORMAT:\n Each anchor is `{line_number}#{hash_id}#{anchor_hash}` from read output like `42#VK#AB|content`.\n Backward-compatible `{line}#{hash}` also accepted.\n\nOPERATION CHOICE:\n replace with pos -> replace ONE line at pos (end is rejected)\n replace_range with pos+end -> replace range pos..end INCLUSIVE (both lines replaced); use only when those existing lines must change or be removed\n append with pos -> insert lines AFTER the anchored line; preferred for adding code after a block's final }, });, ], or other closing line\n prepend with pos -> insert lines BEFORE the anchored line; preferred for adding code before an existing declaration or block\n append/prepend without pos -> EOF/BOF insertion (also creates missing files)\n\nCONTENT FORMAT:\n lines: string (single line) or string[] (multi-line, preferred); each array entry is exactly one physical line\n lines: null or lines: [] with replace/replace_range -> DELETE those lines\n lines: [\"\"] with replace/replace_range -> REJECTED (ambiguous); use [] / null to delete, append/prepend to insert blank lines\n\nFILE MODES:\n delete=true deletes file and requires edits=[] with no rename\n rename moves final content to a new path and removes old path\n</operations>\n\n<examples>\nGiven this file after read:\n 10#VK#AB|function hello() {\n 11#XJ#CD| console.log(\"hi\");\n 12#MB#EF| console.log(\"bye\");\n 13#QR#GH|} // end of hello()\n\nSingle-line replace (change line 11):\n { op: \"replace\", pos: \"11#XJ#CD\", lines: [\" console.log(\\\"hello\\\");\"] }\n Result: line 11 replaced. Lines 10, 12-13 unchanged.\n\nRange replace (replace lines 11-12, function body):\n { op: \"replace_range\", pos: \"11#XJ#CD\", end: \"12#MB#EF\", lines: [\" return \\\"hello world\\\";\"] }\n Result: lines 11-12 removed, replaced by 1 new line. Lines 10, 13 unchanged.\n\nBAD - end is one line too far (DELETES closing brace):\n { op: \"replace_range\", pos: \"11#XJ#CD\", end: \"13#QR#GH\", lines: [\" return \\\"hello world\\\";\"] }\n Result: line 13 (closing brace) is REPLACED too \u2014 function is broken!\n CORRECT: use end: \"12#MB#EF\" \u2014 only replace lines 11-12, keep line 13 unchanged.\n\nBAD - lines extend past end (DUPLICATES line 13):\n { op: \"replace_range\", pos: \"11#XJ#CD\", end: \"12#MB#EF\", lines: [\" return \\\"hi\\\";\", \"}\"] }\n Line 13 is \"}\" which already exists after end. Including it in lines duplicates it.\n CORRECT: { op: \"replace_range\", pos: \"11#XJ#CD\", end: \"12#MB#EF\", lines: [\" return \\\"hi\\\";\"] }\n\nAppend after a line (insert between functions):\n { op: \"append\", pos: \"13#QR#GH\", lines: [\"\", \"function added() {\", \" return true;\", \"}\"] }\n Result: 4 lines inserted after line 13. All existing lines unchanged.\n\nBAD - replacing a closing line only to insert after it:\n { op: \"replace_range\", pos: \"13#QR#GH\", end: \"13#QR#GH\", lines: [\"} // end of hello()\", \"\", \"function added() {\", \"}\"] }\n This unnecessarily consumes the existing closing line. If that closure is omitted or altered, hello() becomes unbalanced.\n CORRECT: { op: \"append\", pos: \"13#QR#GH\", lines: [\"\", \"function added() {\", \"}\"] }\n\nWhen a structural rewrite really changes both opening and closing syntax:\n Use replace_range covering the complete structure, and include the required replacement closures explicitly. Re-read the edited region or run the narrow syntax/type check immediately afterward.\n</examples>\n\n<auto>\nBuilt-in normalization (you do NOT need to handle these):\n BOM and CRLF line endings are preserved automatically.\n Hashline prefixes and diff + markers copied into text are auto-stripped.\n Exact duplicate echoes are dropped and reported as Warning lines: a payload line identical to the append/prepend anchor line, or a range payload longer than its range whose first/last line exactly duplicates a surviving neighbor.\nEverything else is applied literally \u2014 no merging, splitting, or indentation fixes.\n</auto>\n\nRecovery:\n- If you get a hash mismatch error, copy the updated anchors shown in that error or re-read the file before retrying.";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// FILE: src/plugins/hashline-edit/tool-description.ts
|
|
2
|
-
// VERSION: 0.
|
|
2
|
+
// VERSION: 0.8.0
|
|
3
3
|
// START_MODULE_CONTRACT
|
|
4
4
|
// PURPOSE: Provide the LLM-facing tool description for the hash-anchored edit override.
|
|
5
|
-
// SCOPE: Stable instructions for read-then-edit workflow, anchor usage,
|
|
5
|
+
// SCOPE: Stable instructions for read-then-edit workflow, anchor usage, operation choice, literal payload semantics, and stale-anchor recovery.
|
|
6
6
|
// DEPENDS: []
|
|
7
7
|
// LINKS: [M-PLUGIN-HASHLINE-EDIT]
|
|
8
8
|
// ROLE: RUNTIME
|
|
@@ -12,8 +12,9 @@
|
|
|
12
12
|
// START_MODULE_MAP
|
|
13
13
|
// HASHLINE_EDIT_DESCRIPTION - Canonical LLM-facing description for the hashline-backed `edit` tool.
|
|
14
14
|
// END_MODULE_MAP
|
|
15
|
+
//
|
|
15
16
|
// START_CHANGE_SUMMARY
|
|
16
|
-
// LAST_CHANGE: [v0.
|
|
17
|
+
// LAST_CHANGE: [v0.8.0 - Documented literal application, physical single-line entries, blank-payload rejection, exact echo trimming with warnings, and the post-edit diff summary.]
|
|
17
18
|
// END_CHANGE_SUMMARY
|
|
18
19
|
export const HASHLINE_EDIT_DESCRIPTION = `Edit files using exact hash-anchored line references from the latest Read output.
|
|
19
20
|
|
|
@@ -24,11 +25,15 @@ export const HASHLINE_EDIT_DESCRIPTION = `Edit files using exact hash-anchored l
|
|
|
24
25
|
CORRECT: pos on the first line to replace, end on the LAST line to replace — not the line after.
|
|
25
26
|
4. lines must contain ONLY the content that belongs inside the replaced range. Lines AFTER end survive unchanged — do NOT include them in lines. If you do, they will appear twice.
|
|
26
27
|
INSERTION SAFETY: To add a function, handler, statement, or block NEXT TO existing code, use append/prepend anchored to a surviving line. To add code AFTER a closed block, append after its final structural closing line. Do NOT replace that closing line merely to reproduce it and add content after it.
|
|
27
|
-
STRUCTURAL CLOSURES: If replace_range intentionally consumes lines containing closing syntax such as }, });, ], ), );, or </tag>, lines MUST include every closure required by the resulting code. Never assume
|
|
28
|
+
STRUCTURAL CLOSURES: If replace_range intentionally consumes lines containing closing syntax such as }, });, ], ), );, or </tag>, lines MUST include every closure required by the resulting code. Never assume the tool reconstructs omitted closing syntax.
|
|
28
29
|
5. Tags MUST be copied exactly from read output or >>> mismatch output. NEVER guess or reconstruct tags.
|
|
29
30
|
6. Batch = multiple operations in edits[], NOT one big replace covering everything. Each operation targets the smallest possible change.
|
|
30
31
|
7. lines must contain plain replacement text only (no LINE#HASH#ANCHOR| prefixes, no diff + markers).
|
|
31
32
|
8. CRITICAL: Double-quote characters inside lines strings MUST be escaped as \\". Unescaped \\" inside a JSON string will break the parser. Example: ["const x = \\"hello\\";"] — NOT ["const x = "hello";"]. Single quotes and backticks do NOT need escaping.
|
|
33
|
+
9. LITERAL APPLICATION: payloads are applied byte-for-byte. There is NO merging, splitting, indentation fixing, or other content rewriting. The only automatic removals are exact duplicate echoes, and each one is reported as a Warning line in the result.
|
|
34
|
+
10. PHYSICAL LINES: every string[] entry in lines must be exactly one physical line. Entries with embedded newlines are rejected. A string value is split on newlines.
|
|
35
|
+
11. DELETION: to delete lines use lines: [] or lines: null with replace/replace_range. lines: [""] is REJECTED because a single blank line is ambiguous — use append/prepend when you really want to insert a blank line.
|
|
36
|
+
12. VERIFY: successful results include a bounded diff (@@ block) of what changed. Check that it matches your intent before moving on.
|
|
32
37
|
</must>
|
|
33
38
|
|
|
34
39
|
<operations>
|
|
@@ -44,8 +49,9 @@ OPERATION CHOICE:
|
|
|
44
49
|
append/prepend without pos -> EOF/BOF insertion (also creates missing files)
|
|
45
50
|
|
|
46
51
|
CONTENT FORMAT:
|
|
47
|
-
lines: string (single line) or string[] (multi-line, preferred)
|
|
48
|
-
lines: null or lines: [] with replace -> DELETE those lines
|
|
52
|
+
lines: string (single line) or string[] (multi-line, preferred); each array entry is exactly one physical line
|
|
53
|
+
lines: null or lines: [] with replace/replace_range -> DELETE those lines
|
|
54
|
+
lines: [""] with replace/replace_range -> REJECTED (ambiguous); use [] / null to delete, append/prepend to insert blank lines
|
|
49
55
|
|
|
50
56
|
FILE MODES:
|
|
51
57
|
delete=true deletes file and requires edits=[] with no rename
|
|
@@ -91,12 +97,11 @@ When a structural rewrite really changes both opening and closing syntax:
|
|
|
91
97
|
</examples>
|
|
92
98
|
|
|
93
99
|
<auto>
|
|
94
|
-
Built-in
|
|
95
|
-
Merged lines are auto-expanded back to original line count.
|
|
96
|
-
Indentation is auto-restored from original lines.
|
|
100
|
+
Built-in normalization (you do NOT need to handle these):
|
|
97
101
|
BOM and CRLF line endings are preserved automatically.
|
|
98
|
-
Hashline prefixes and diff markers
|
|
99
|
-
|
|
102
|
+
Hashline prefixes and diff + markers copied into text are auto-stripped.
|
|
103
|
+
Exact duplicate echoes are dropped and reported as Warning lines: a payload line identical to the append/prepend anchor line, or a range payload longer than its range whose first/last line exactly duplicates a surviving neighbor.
|
|
104
|
+
Everything else is applied literally — no merging, splitting, or indentation fixes.
|
|
100
105
|
</auto>
|
|
101
106
|
|
|
102
107
|
Recovery:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-description.js","sourceRoot":"","sources":["../../../src/plugins/hashline-edit/tool-description.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,iBAAiB;AACjB,wBAAwB;AACxB,0FAA0F;AAC1F,
|
|
1
|
+
{"version":3,"file":"tool-description.js","sourceRoot":"","sources":["../../../src/plugins/hashline-edit/tool-description.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,iBAAiB;AACjB,wBAAwB;AACxB,0FAA0F;AAC1F,kJAAkJ;AAClJ,gBAAgB;AAChB,oCAAoC;AACpC,kBAAkB;AAClB,sBAAsB;AACtB,sBAAsB;AACtB,EAAE;AACF,mBAAmB;AACnB,sGAAsG;AACtG,iBAAiB;AACjB,EAAE;AACF,uBAAuB;AACvB,sLAAsL;AACtL,qBAAqB;AACrB,MAAM,CAAC,MAAM,yBAAyB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;sHAyF6E,CAAC"}
|
package/package.json
CHANGED
package/schemas/vvoc/v3.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"$id": "https://cdn.jsdelivr.net/npm/@osovv/vv-opencode@1.2.
|
|
3
|
+
"$id": "https://cdn.jsdelivr.net/npm/@osovv/vv-opencode@1.2.7/schemas/vvoc/v3.json",
|
|
4
4
|
"title": "vvoc config",
|
|
5
5
|
"description": "Canonical vvoc configuration document.",
|
|
6
6
|
"type": "object",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function autocorrectReplacementLines(originalLines: string[], replacementLines: string[]): string[];
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
// FILE: src/plugins/hashline-edit/autocorrect-replacement-lines.ts
|
|
2
|
-
// VERSION: 0.1.0
|
|
3
|
-
// START_MODULE_CONTRACT
|
|
4
|
-
// PURPOSE: Recover common model formatting mistakes in replacement payloads without changing user-requested semantics.
|
|
5
|
-
// SCOPE: Merged-line expansion, recovery of uniquely wrapped original lines, and indentation restoration for paired replacements.
|
|
6
|
-
// DEPENDS: []
|
|
7
|
-
// LINKS: [M-PLUGIN-HASHLINE-EDIT]
|
|
8
|
-
// ROLE: RUNTIME
|
|
9
|
-
// MAP_MODE: EXPORTS
|
|
10
|
-
// END_MODULE_CONTRACT
|
|
11
|
-
//
|
|
12
|
-
// START_MODULE_MAP
|
|
13
|
-
// autocorrectReplacementLines - Apply conservative autocorrections to replacement payload lines.
|
|
14
|
-
// END_MODULE_MAP
|
|
15
|
-
//
|
|
16
|
-
// START_CHANGE_SUMMARY
|
|
17
|
-
// LAST_CHANGE: [v0.0.0 - Initial GRACE compliance: added missing CHANGE_SUMMARY.]
|
|
18
|
-
// END_CHANGE_SUMMARY
|
|
19
|
-
function normalizeTokens(text) {
|
|
20
|
-
return text.replace(/\s+/g, "");
|
|
21
|
-
}
|
|
22
|
-
function stripTrailingContinuationTokens(text) {
|
|
23
|
-
return text.replace(/(?:&&|\|\||\?\?|\?|:|=|,|\+|-|\*|\/|\.|\()\s*$/u, "");
|
|
24
|
-
}
|
|
25
|
-
function stripMergeOperatorChars(text) {
|
|
26
|
-
return text.replace(/[|&?]/g, "");
|
|
27
|
-
}
|
|
28
|
-
function leadingWhitespace(text) {
|
|
29
|
-
return text.match(/^\s*/)?.[0] ?? "";
|
|
30
|
-
}
|
|
31
|
-
function restoreOldWrappedLines(originalLines, replacementLines) {
|
|
32
|
-
if (originalLines.length === 0 || replacementLines.length < 2) {
|
|
33
|
-
return replacementLines;
|
|
34
|
-
}
|
|
35
|
-
const canonicalToOriginal = new Map();
|
|
36
|
-
for (const line of originalLines) {
|
|
37
|
-
const canonical = normalizeTokens(line);
|
|
38
|
-
const existing = canonicalToOriginal.get(canonical);
|
|
39
|
-
if (existing) {
|
|
40
|
-
existing.count += 1;
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
canonicalToOriginal.set(canonical, { line, count: 1 });
|
|
44
|
-
}
|
|
45
|
-
const candidates = [];
|
|
46
|
-
for (let start = 0; start < replacementLines.length; start += 1) {
|
|
47
|
-
for (let length = 2; length <= 10 && start + length <= replacementLines.length; length += 1) {
|
|
48
|
-
const span = replacementLines.slice(start, start + length);
|
|
49
|
-
if (span.some((line) => line.trim().length === 0)) {
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
const canonicalSpan = normalizeTokens(span.join(""));
|
|
53
|
-
const original = canonicalToOriginal.get(canonicalSpan);
|
|
54
|
-
if (original && original.count === 1 && canonicalSpan.length >= 6) {
|
|
55
|
-
candidates.push({
|
|
56
|
-
start,
|
|
57
|
-
len: length,
|
|
58
|
-
replacement: original.line,
|
|
59
|
-
canonical: canonicalSpan,
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (candidates.length === 0) {
|
|
65
|
-
return replacementLines;
|
|
66
|
-
}
|
|
67
|
-
const canonicalCounts = new Map();
|
|
68
|
-
for (const candidate of candidates) {
|
|
69
|
-
canonicalCounts.set(candidate.canonical, (canonicalCounts.get(candidate.canonical) ?? 0) + 1);
|
|
70
|
-
}
|
|
71
|
-
const uniqueCandidates = candidates.filter((candidate) => (canonicalCounts.get(candidate.canonical) ?? 0) === 1);
|
|
72
|
-
if (uniqueCandidates.length === 0) {
|
|
73
|
-
return replacementLines;
|
|
74
|
-
}
|
|
75
|
-
uniqueCandidates.sort((left, right) => right.start - left.start);
|
|
76
|
-
const corrected = [...replacementLines];
|
|
77
|
-
for (const candidate of uniqueCandidates) {
|
|
78
|
-
corrected.splice(candidate.start, candidate.len, candidate.replacement);
|
|
79
|
-
}
|
|
80
|
-
return corrected;
|
|
81
|
-
}
|
|
82
|
-
function maybeExpandSingleLineMerge(originalLines, replacementLines) {
|
|
83
|
-
if (replacementLines.length !== 1 || originalLines.length <= 1) {
|
|
84
|
-
return replacementLines;
|
|
85
|
-
}
|
|
86
|
-
const merged = replacementLines[0] ?? "";
|
|
87
|
-
const parts = originalLines.map((line) => line.trim()).filter((line) => line.length > 0);
|
|
88
|
-
if (parts.length !== originalLines.length) {
|
|
89
|
-
return replacementLines;
|
|
90
|
-
}
|
|
91
|
-
const indices = [];
|
|
92
|
-
let offset = 0;
|
|
93
|
-
let orderedMatch = true;
|
|
94
|
-
for (const part of parts) {
|
|
95
|
-
let index = merged.indexOf(part, offset);
|
|
96
|
-
let matchedLength = part.length;
|
|
97
|
-
if (index === -1) {
|
|
98
|
-
const stripped = stripTrailingContinuationTokens(part);
|
|
99
|
-
if (stripped !== part) {
|
|
100
|
-
index = merged.indexOf(stripped, offset);
|
|
101
|
-
if (index !== -1) {
|
|
102
|
-
matchedLength = stripped.length;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
if (index === -1) {
|
|
107
|
-
const segment = merged.slice(offset);
|
|
108
|
-
const fuzzyIndex = stripMergeOperatorChars(segment).indexOf(stripMergeOperatorChars(part));
|
|
109
|
-
if (fuzzyIndex !== -1) {
|
|
110
|
-
let strippedPos = 0;
|
|
111
|
-
let originalPos = 0;
|
|
112
|
-
while (strippedPos < fuzzyIndex && originalPos < segment.length) {
|
|
113
|
-
if (!/[|&?]/.test(segment[originalPos] ?? "")) {
|
|
114
|
-
strippedPos += 1;
|
|
115
|
-
}
|
|
116
|
-
originalPos += 1;
|
|
117
|
-
}
|
|
118
|
-
index = offset + originalPos;
|
|
119
|
-
matchedLength = part.length;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
if (index === -1) {
|
|
123
|
-
orderedMatch = false;
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
indices.push(index);
|
|
127
|
-
offset = index + matchedLength;
|
|
128
|
-
}
|
|
129
|
-
const expanded = [];
|
|
130
|
-
if (orderedMatch) {
|
|
131
|
-
for (let index = 0; index < indices.length; index += 1) {
|
|
132
|
-
const start = indices[index] ?? 0;
|
|
133
|
-
const end = index + 1 < indices.length ? (indices[index + 1] ?? merged.length) : merged.length;
|
|
134
|
-
const candidate = merged.slice(start, end).trim();
|
|
135
|
-
if (candidate.length === 0) {
|
|
136
|
-
orderedMatch = false;
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
expanded.push(candidate);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
if (orderedMatch && expanded.length === originalLines.length) {
|
|
143
|
-
return expanded;
|
|
144
|
-
}
|
|
145
|
-
const semicolonSplit = merged
|
|
146
|
-
.split(/;\s+/)
|
|
147
|
-
.map((line, index, array) => {
|
|
148
|
-
if (index < array.length - 1 && !line.endsWith(";")) {
|
|
149
|
-
return `${line};`;
|
|
150
|
-
}
|
|
151
|
-
return line;
|
|
152
|
-
})
|
|
153
|
-
.map((line) => line.trim())
|
|
154
|
-
.filter((line) => line.length > 0);
|
|
155
|
-
if (semicolonSplit.length === originalLines.length) {
|
|
156
|
-
return semicolonSplit;
|
|
157
|
-
}
|
|
158
|
-
return replacementLines;
|
|
159
|
-
}
|
|
160
|
-
function restoreIndentForPairedReplacement(originalLines, replacementLines) {
|
|
161
|
-
if (originalLines.length !== replacementLines.length) {
|
|
162
|
-
return replacementLines;
|
|
163
|
-
}
|
|
164
|
-
return replacementLines.map((line, index) => {
|
|
165
|
-
if (line.length === 0) {
|
|
166
|
-
return line;
|
|
167
|
-
}
|
|
168
|
-
if (leadingWhitespace(line).length > 0) {
|
|
169
|
-
return line;
|
|
170
|
-
}
|
|
171
|
-
const indent = leadingWhitespace(originalLines[index] ?? "");
|
|
172
|
-
if (indent.length === 0) {
|
|
173
|
-
return line;
|
|
174
|
-
}
|
|
175
|
-
if ((originalLines[index] ?? "").trim() === line.trim()) {
|
|
176
|
-
return line;
|
|
177
|
-
}
|
|
178
|
-
return `${indent}${line}`;
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
export function autocorrectReplacementLines(originalLines, replacementLines) {
|
|
182
|
-
let next = replacementLines;
|
|
183
|
-
next = maybeExpandSingleLineMerge(originalLines, next);
|
|
184
|
-
next = restoreOldWrappedLines(originalLines, next);
|
|
185
|
-
next = restoreIndentForPairedReplacement(originalLines, next);
|
|
186
|
-
return next;
|
|
187
|
-
}
|
|
188
|
-
//# sourceMappingURL=autocorrect-replacement-lines.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"autocorrect-replacement-lines.js","sourceRoot":"","sources":["../../../src/plugins/hashline-edit/autocorrect-replacement-lines.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,iBAAiB;AACjB,wBAAwB;AACxB,yHAAyH;AACzH,oIAAoI;AACpI,gBAAgB;AAChB,oCAAoC;AACpC,kBAAkB;AAClB,sBAAsB;AACtB,sBAAsB;AACtB,EAAE;AACF,mBAAmB;AACnB,mGAAmG;AACnG,iBAAiB;AACjB,EAAE;AACF,uBAAuB;AACvB,oFAAoF;AACpF,qBAAqB;AAErB,SAAS,eAAe,CAAC,IAAY;IACnC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,+BAA+B,CAAC,IAAY;IACnD,OAAO,IAAI,CAAC,OAAO,CAAC,iDAAiD,EAAE,EAAE,CAAC,CAAC;AAC7E,CAAC;AAED,SAAS,uBAAuB,CAAC,IAAY;IAC3C,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;AACpC,CAAC;AAED,SAAS,iBAAiB,CAAC,IAAY;IACrC,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;AACvC,CAAC;AAED,SAAS,sBAAsB,CAAC,aAAuB,EAAE,gBAA0B;IACjF,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC9D,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IAED,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAA2C,CAAC;IAC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