Skip to content

Commit bbc0ef8

Browse files
committed
Refactor and extend diff parsing logic to correctly handle mixed code blocks (new files) and diff blocks (patches) within a single response, including adding a new test case for this scenario
1 parent f5a66f0 commit bbc0ef8

7 files changed

Lines changed: 255 additions & 157 deletions

File tree

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,27 @@ describe('clipboard-parser', () => {
857857
)
858858
})
859859

860+
it('should parse multiple diff files format in variant n', () => {
861+
const text = load_test_case_file(
862+
'diff-multiple-files-variant-n',
863+
'diff-multiple-files-variant-n.txt'
864+
)
865+
const result = parse_response(text, true)
866+
867+
expect(result.type).toBe('patches')
868+
expect(result.patches).toHaveLength(2)
869+
870+
expect(result.patches![0].file_path).toBe('src/lorem.html')
871+
expect(result.patches![1].file_path).toBe('src/ipsum.ts')
872+
873+
expect(result.patches![0].content).toBe(
874+
load_test_case_file('diff-multiple-files-variant-n', 'file-1.txt')
875+
)
876+
expect(result.patches![1].content).toBe(
877+
load_test_case_file('diff-multiple-files-variant-n', 'file-2.txt')
878+
)
879+
})
880+
860881
it('should handle inner backticks within a diff block', () => {
861882
const text = load_test_case_file(
862883
'diff-inner-backticks',

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,10 @@ export const parse_response = (
592592
response.startsWith('--- ') ||
593593
response.startsWith('diff --git')
594594
) {
595-
const patches = extract_diffs(response, is_single_root_folder_workspace)
595+
const patches = extract_diffs({
596+
clipboard_text: response,
597+
is_single_root: is_single_root_folder_workspace
598+
})
596599
if (patches.length) {
597600
return {
598601
type: 'patches',

0 commit comments

Comments
 (0)