Skip to content

Commit 06c5607

Browse files
committed
Add support for parsing mixed rename and update diffs in clipboard responses
1 parent fa17bdd commit 06c5607

6 files changed

Lines changed: 46 additions & 2 deletions

File tree

‎apps/editor/src/commands/apply-chat-response-command/response-processor.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ export const process_chat_response = async (
9999
is_single_root_folder_workspace
100100
})
101101

102+
console.log('xxx', clipboard_items)
103+
102104
if (clipboard_items.some((item) => item.type == 'relevant-files')) {
103105
const relevant_files_item = clipboard_items.find(
104106
(item) => item.type == 'relevant-files'

‎apps/editor/src/commands/apply-chat-response-command/utils/clipboard-parser/clipboard-parser.spec.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,6 +1796,23 @@ describe('clipboard-parser', () => {
17961796
})
17971797
})
17981798

1799+
it('parses a mix of a rename heading and an update diff for the same file', () => {
1800+
const test_case = 'diff-mix-rename-and-update'
1801+
const text = load_test_case_file('diffs', test_case, `${test_case}.txt`)
1802+
const result = parse_response({
1803+
response: text,
1804+
is_single_root_folder_workspace: true
1805+
})
1806+
1807+
expect(result).toHaveLength(1)
1808+
expect(result[0]).toMatchObject({
1809+
type: 'diff',
1810+
file_path: 'src/old.ts',
1811+
new_file_path: 'src/new.ts',
1812+
content: load_test_case_file('diffs', test_case, '1-file.txt')
1813+
})
1814+
})
1815+
17991816
it('parses multiple files with text between the markdown code blocks', () => {
18001817
const test_case = 'text-between'
18011818
const text = load_test_case_file(

‎apps/editor/src/commands/apply-chat-response-command/utils/clipboard-parser/parsers/diff-parser/diff-parser.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,8 @@ const extract_all_code_block_patches = (params: {
546546
remove_path_line_from_text_block({
547547
text_item: last_item,
548548
target_file_path: patches[0].file_path,
549-
is_single_root: params.is_single_root
549+
is_single_root: params.is_single_root,
550+
target_new_file_path: patches[0].new_file_path
550551
})
551552

552553
if (!last_item.content) {

‎apps/editor/src/commands/apply-chat-response-command/utils/clipboard-parser/parsers/diff-parser/helpers/block-utils.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export const remove_path_line_from_text_block = (params: {
5151
text_item: TextItem
5252
target_file_path: string
5353
is_single_root: boolean
54+
target_new_file_path?: string
5455
}) => {
5556
const content_lines = params.text_item.content.split('\n')
5657
let path_line_index = -1
@@ -66,7 +67,11 @@ export const remove_path_line_from_text_block = (params: {
6667
raw_file_path: extracted,
6768
is_single_root_folder_workspace: params.is_single_root
6869
})
69-
if (relative_path === params.target_file_path) {
70+
if (
71+
relative_path == params.target_file_path ||
72+
(params.target_new_file_path &&
73+
relative_path == params.target_new_file_path)
74+
) {
7075
if (line.startsWith('###')) {
7176
path_line_index = i
7277
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
--- a/src/old.ts
2+
+++ b/src/old.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,13 @@
1+
### Renamed file: `src/old.ts` (old) `src/new.ts` (new)
2+
3+
### Updated file: `src/new.ts`
4+
5+
```diff
6+
--- a/src/old.ts
7+
+++ b/src/new.ts
8+
@@ -1,3 +1,3 @@
9+
console.log("hello")
10+
-console.log("old message")
11+
+console.log("new message")
12+
13+
```

0 commit comments

Comments
 (0)