Skip to content

Commit a10d362

Browse files
committed
Enhance file path extraction logic to correctly identify file paths enclosed in backticks or comments immediately preceding a code block, even with intermediate empty lines
1 parent 2bacbcf commit a10d362

11 files changed

Lines changed: 97 additions & 2 deletions

File tree

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,73 @@ describe('clipboard-parser', () => {
558558
})
559559
})
560560

561+
it('extracts file path from backticks when there are no intermediate lines before code block', () => {
562+
const test_case = 'path-in-backticks-no-intermediate-empty-lines'
563+
const text = load_test_case_file(test_case, `${test_case}.txt`)
564+
const result = parse_multiple_files({
565+
response: text,
566+
is_single_root_folder_workspace: true
567+
})
568+
569+
expect(result).toHaveLength(1)
570+
expect(result[0]).toMatchObject({
571+
type: 'file',
572+
file_path: 'src/main.py',
573+
content: load_test_case_file(test_case, '1-file.txt')
574+
})
575+
})
576+
577+
it('extracts file path from backticks when there are only empty intermediate lines before code block', () => {
578+
const test_case = 'path-in-backticks-with-intermediate-empty-lines'
579+
const text = load_test_case_file(test_case, `${test_case}.txt`)
580+
const result = parse_multiple_files({
581+
response: text,
582+
is_single_root_folder_workspace: true
583+
})
584+
585+
expect(result).toHaveLength(1)
586+
expect(result[0]).toMatchObject({
587+
type: 'file',
588+
file_path: 'src/main.py',
589+
content: load_test_case_file(test_case, '1-file.txt')
590+
})
591+
})
592+
593+
it('does not extract file path from backticks when there is intermediate text before code block', () => {
594+
const test_case = 'path-in-backticks-with-intermediate-text'
595+
const text = load_test_case_file(test_case, `${test_case}.txt`)
596+
const result = parse_multiple_files({
597+
response: text,
598+
is_single_root_folder_workspace: true
599+
})
600+
601+
expect(result).toHaveLength(1)
602+
expect(result[0]).toMatchObject({
603+
type: 'text',
604+
content: load_test_case_file(test_case, '1-text.txt').trim()
605+
})
606+
})
607+
608+
it('extracts file path from commented backticks even with intermediate text before code block', () => {
609+
const test_case = 'path-in-backticks-comment-with-intermediate-text'
610+
const text = load_test_case_file(test_case, `${test_case}.txt`)
611+
const result = parse_multiple_files({
612+
response: text,
613+
is_single_root_folder_workspace: true
614+
})
615+
616+
expect(result).toHaveLength(2)
617+
expect(result[0]).toMatchObject({
618+
type: 'text',
619+
content: load_test_case_file(test_case, '1-text.txt')
620+
})
621+
expect(result[1]).toMatchObject({
622+
type: 'file',
623+
file_path: 'src/main.py',
624+
content: load_test_case_file(test_case, '2-file.txt')
625+
})
626+
})
627+
561628
it('handles path duplicated in empty code block', () => {
562629
const test_case = 'path-duplicated-in-empty-code-block'
563630
const text = load_test_case_file(test_case, `${test_case}.txt`)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
2-
// `src/hello-world.ts`
1+
### New File: `src/hello-world.ts`
32

43
This new file
54

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Some other text here.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("hello")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// `src/main.py`
2+
Some other text here.
3+
```python
4+
print("hello")
5+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("hello")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
`src/main.py`
2+
```python
3+
print("hello")
4+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("hello")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
`src/main.py`
2+
3+
4+
```python
5+
print("hello")
6+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
`src/main.py`
2+
Some other text here.
3+
```python
4+
print("hello")
5+
```

0 commit comments

Comments
 (0)