Skip to content

Commit 3e41ba3

Browse files
committed
Add support for parsing diffs with redundant closing markdown backticks and clean up trailing empty code block markers
1 parent c256f42 commit 3e41ba3

4 files changed

Lines changed: 40 additions & 0 deletions

File tree

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,5 +1730,23 @@ describe('clipboard-parser', () => {
17301730
content: load_test_case_file(test_case, '1-file.txt')
17311731
})
17321732
})
1733+
1734+
it('parses diff format with redundant closing backticks', () => {
1735+
const test_case = 'diff-markdown-redundant-closing-backticks'
1736+
const text = load_test_case_file(
1737+
test_case,
1738+
'diff-markdown-redundant-closing-backticks.txt'
1739+
)
1740+
const result = parse_response({
1741+
response: text,
1742+
is_single_root_folder_workspace: true
1743+
})
1744+
expect(result).toHaveLength(1)
1745+
expect(result[0]).toMatchObject({
1746+
type: 'diff',
1747+
file_path: 'src/index.ts',
1748+
content: load_test_case_file(test_case, '1-file.txt')
1749+
})
1750+
})
17331751
})
17341752
})

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,13 @@ const extract_all_code_block_patches = (params: {
818818
)
819819
}
820820

821+
if (items.length > 0) {
822+
const last_item = items[items.length - 1]
823+
if (last_item.type == 'text' && last_item.content.trim() == '```') {
824+
items.pop()
825+
}
826+
}
827+
821828
return items
822829
}
823830

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
--- a/src/index.ts
2+
+++ b/src/index.ts
3+
@@ -1,3 +1,3 @@
4+
console.log("hello")
5+
-console.log("old message")
6+
+console.log("new message")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
```diff
2+
--- a/src/index.ts
3+
+++ b/src/index.ts
4+
@@ -1,3 +1,3 @@
5+
console.log("hello")
6+
-console.log("old message")
7+
+console.log("new message")
8+
```
9+
```

0 commit comments

Comments
 (0)