Skip to content

Commit b1f5e62

Browse files
committed
Add support for parsing renamed files from markdown headings and handle file renaming in the clipboard parser
1 parent 29726c1 commit b1f5e62

5 files changed

Lines changed: 59 additions & 0 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
@@ -555,6 +555,27 @@ describe('clipboard-parser', () => {
555555
})
556556
})
557557

558+
it('parses file path for a renamed file from markdown heading preceding a code block', () => {
559+
const test_case = 'path-above-code-block-renaming'
560+
const text = load_test_case_file(test_case, `${test_case}.txt`)
561+
const result = parse_multiple_files({
562+
response: text,
563+
is_single_root_folder_workspace: true
564+
})
565+
566+
expect(result).toHaveLength(2)
567+
expect(result[0]).toMatchObject({
568+
type: 'file',
569+
file_path: 'src/welcome.ts',
570+
content: load_test_case_file(test_case, '1-file.txt')
571+
})
572+
expect(result[1]).toMatchObject({
573+
type: 'file',
574+
file_path: 'src/hello-world.ts',
575+
content: load_test_case_file(test_case, '2-file.txt')
576+
})
577+
})
578+
558579
it('parses file path when it is included immediately after the opening code block backticks', () => {
559580
const test_case = 'markdown-backticks-file-path-in-one-line'
560581
const text = load_test_case_file(test_case, `${test_case}.txt`)

packages/vscode/src/commands/apply-chat-response-command/utils/clipboard-parser/parsers/multiple-files-parser.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,38 @@ export const parse_multiple_files = (params: {
253253
}
254254
}
255255

256+
const renamed_file_match = line
257+
.trim()
258+
.match(/^###\s+Renamed file:\s*`([^`]+)`.*?`([^`]+)`/i)
259+
if (
260+
renamed_file_match &&
261+
renamed_file_match[1] &&
262+
renamed_file_match[2]
263+
) {
264+
flush_text_block({
265+
text_block: current_text_block,
266+
results
267+
})
268+
current_text_block = ''
269+
const { workspace_name, relative_path } =
270+
extract_and_set_workspace_path({
271+
raw_file_path: renamed_file_match[1],
272+
is_single_root_folder_workspace:
273+
params.is_single_root_folder_workspace
274+
})
275+
create_or_update_file_item({
276+
file_name: relative_path,
277+
content: '',
278+
workspace_name,
279+
file_ref_map,
280+
results
281+
})
282+
283+
last_seen_file_path_comment = renamed_file_match[2]
284+
last_seen_file_path_was_header = true
285+
continue
286+
}
287+
256288
const deleted_file_match = line
257289
.trim()
258290
.match(/^###\s+Deleted file:\s*`([^`]+)`$/i)

packages/vscode/src/commands/apply-chat-response-command/utils/clipboard-parser/test-cases/path-above-code-block-renaming/1-file.txt

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('Hello world!')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### Renamed file: `src/welcome.ts` (old) `src/hello-world.ts` (new)
2+
3+
```typescript
4+
console.log('Hello world!')
5+
```

0 commit comments

Comments
 (0)