Skip to content

Commit 01b8733

Browse files
committed
Add support for parsing text content immediately following a closing code block
1 parent 7b8d606 commit 01b8733

7 files changed

Lines changed: 32 additions & 1 deletion

File tree

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,26 @@ describe('clipboard-parser', () => {
734734
content: load_test_case_file(test_case, '2-file.txt')
735735
})
736736
})
737+
738+
it('parses text that appears immediately after a closing code block', () => {
739+
const test_case = 'text-below-code-block'
740+
const text = load_test_case_file(test_case, `${test_case}.txt`)
741+
const result = parse_multiple_files({
742+
response: text,
743+
is_single_root_folder_workspace: true
744+
})
745+
746+
expect(result).toHaveLength(2)
747+
expect(result[0]).toMatchObject({
748+
type: 'file',
749+
file_path: 'src/hello-world.ts',
750+
content: load_test_case_file(test_case, '1-file.txt')
751+
})
752+
expect(result[1]).toMatchObject({
753+
type: 'text',
754+
content: 'Lorem ipsum.'
755+
})
756+
})
737757
})
738758

739759
describe('parse_file_content_only', () => {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ export const parse_multiple_files = (params: {
590590
trimmed_line === '```' &&
591591
backtick_nesting_level === 1 &&
592592
current_file_name &&
593+
current_content.trim() === '' &&
593594
i + 1 < lines.length &&
594595
lines[i + 1].trim() !== '' &&
595596
!lines[i + 1].trim().startsWith('```')
@@ -605,6 +606,8 @@ export const parse_multiple_files = (params: {
605606
) {
606607
is_first_content_line = true
607608
}
609+
} else {
610+
backtick_nesting_level++
608611
}
609612
}
610613

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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
### **src/hello-world.ts**
1+
### `src/hello-world.ts`
22

33
Lorem ipsum `src/welcome.ts`.
44

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 @@
1+
Lorem ipsum.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
### `src/hello-world.ts`
2+
3+
```typescript
4+
console.log('Hello world!')
5+
```
6+
Lorem ipsum.

src/index.js

Whitespace-only changes.

0 commit comments

Comments
 (0)