Skip to content

Commit 90d5d2f

Browse files
committed
Prevent duplicate file patches by prioritizing existing diffs over subsequent full content blocks for the same file
1 parent 450c64e commit 90d5d2f

4 files changed

Lines changed: 51 additions & 3 deletions

File tree

‎packages/vscode/src/commands/apply-chat-response-command/utils/clipboard-parser/clipboard-parser.spec.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,26 @@ describe('clipboard-parser', () => {
953953
)
954954
})
955955

956+
it('should parse multiple diff files format in variant o', () => {
957+
const text = load_test_case_file(
958+
'diff-multiple-files-variant-o',
959+
'diff-multiple-files-variant-o.txt'
960+
)
961+
const result = parse_response({
962+
response: text,
963+
is_single_root_folder_workspace: true
964+
})
965+
966+
expect(result.type).toBe('patches')
967+
expect(result.patches).toHaveLength(1)
968+
969+
expect(result.patches![0].file_path).toBe('src/ipsum.ts')
970+
971+
expect(result.patches![0].content).toBe(
972+
load_test_case_file('diff-multiple-files-variant-o', 'file-1.txt')
973+
)
974+
})
975+
956976
it('should handle inner backticks within a diff block', () => {
957977
const text = load_test_case_file(
958978
'diff-inner-backticks',

‎packages/vscode/src/commands/apply-chat-response-command/utils/clipboard-parser/extract-diff-patches/extract-diffs.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,18 @@ const extract_all_code_block_patches = (params: {
381381
file_path_hint
382382
})
383383
if (patch) {
384-
if (workspace_hint && !patch.workspace_name) {
385-
patch.workspace_name = workspace_hint
384+
const file_already_has_diff = patches.some(
385+
(p) =>
386+
p.file_path == patch.file_path &&
387+
p.workspace_name == patch.workspace_name
388+
)
389+
390+
if (!file_already_has_diff) {
391+
if (workspace_hint && !patch.workspace_name) {
392+
patch.workspace_name = workspace_hint
393+
}
394+
patches.push(patch)
386395
}
387-
patches.push(patch)
388396
}
389397
}
390398
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
```diff
2+
--- src/ipsum.ts
3+
+++ src/ipsum.ts
4+
@@ -1,3 +1,3 @@
5+
console.log("hello")
6+
-console.log("old ipsum")
7+
+console.log("new ipsum")
8+
```
9+
10+
### New file: `src/ipsum.ts`
11+
12+
```typescript
13+
<div>lorem ipsum</div>
14+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
--- a/src/ipsum.ts
2+
+++ b/src/ipsum.ts
3+
@@ -1,3 +1,3 @@
4+
console.log("hello")
5+
-console.log("old ipsum")
6+
+console.log("new ipsum")

0 commit comments

Comments
 (0)