Skip to content

Commit 2527449

Browse files
committed
Ensure the clipboard parser correctly handles and applies files containing empty content blocks
1 parent 252d88a commit 2527449

6 files changed

Lines changed: 35 additions & 1 deletion

File tree

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,25 @@ describe('clipboard-parser', () => {
3131
})
3232
})
3333

34+
it('parses multiple files including one with empty content', () => {
35+
const test_case = 'empty-file'
36+
const text = load_test_case_file(test_case, `${test_case}.txt`)
37+
const result = parse_multiple_files({
38+
response: text,
39+
is_single_root_folder_workspace: true
40+
})
41+
42+
expect(result).toHaveLength(2)
43+
expect(result[0]).toMatchObject({
44+
file_path: 'src/index.ts',
45+
content: load_test_case_file(test_case, '1-file.txt')
46+
})
47+
expect(result[1]).toMatchObject({
48+
file_path: 'src/hello.ts',
49+
content: load_test_case_file(test_case, '2-file.txt')
50+
})
51+
})
52+
3453
it('parses file when using file-xml format within a markdown code block', () => {
3554
const test_case = 'file-xml'
3655
const text = load_test_case_file(test_case, `${test_case}.txt`)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ export const extract_workspace_and_path = (params: {
6767
}
6868

6969
export const has_real_code = (content: string): boolean => {
70+
if (content.trim() === '') {
71+
return true
72+
}
7073
const lines = content.split('\n')
7174
const non_comment_lines = lines.filter((line) => {
7275
const trimmed = line.trim()

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,9 @@ export const parse_multiple_files = (params: {
265265
} else if (
266266
trimmed_line == '```' &&
267267
backtick_nesting_level == 1 &&
268-
(current_content.trim() == '' ||
268+
((current_content.trim() == '' &&
269+
i > 0 &&
270+
lines[i - 1].trim() !== '') ||
269271
((current_language == 'markdown' || current_language == 'md') &&
270272
i > 0 &&
271273
(lines[i - 1].trim() == '' ||

‎packages/vscode/src/commands/apply-chat-response-command/utils/clipboard-parser/test-cases/empty-file/1-file.txt‎

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("hello")
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
```typescript
2+
// src/index.ts
3+
4+
```
5+
6+
```typescript
7+
// src/hello.ts
8+
console.log("hello")
9+
```

0 commit comments

Comments
 (0)