Skip to content

Commit 85c2cf5

Browse files
committed
Enhance file parsing to correctly identify file paths provided as plain text followed by a colon immediately preceding a code block
1 parent e2a116f commit 85c2cf5

4 files changed

Lines changed: 29 additions & 2 deletions

File tree

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,21 @@ describe('clipboard-parser', () => {
487487
content: load_test_case_file(test_case, '1-file.txt')
488488
})
489489
})
490+
491+
it('parses file path from plain text with colon preceding a code block', () => {
492+
const test_case = 'path-above-code-block-raw'
493+
const text = load_test_case_file(test_case, `${test_case}.txt`)
494+
const result = parse_multiple_files({
495+
response: text,
496+
is_single_root_folder_workspace: true
497+
})
498+
499+
expect(result).toHaveLength(1)
500+
expect(result[0]).toMatchObject({
501+
file_path: 'src/hello-world.ts',
502+
content: load_test_case_file(test_case, '1-file.txt')
503+
})
504+
})
490505
})
491506

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

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,18 @@ export const parse_multiple_files = (params: {
245245
} else {
246246
// Check if this line is a plain file path followed by a code block
247247
if (!last_seen_file_path_comment) {
248-
const trimmed = line.trim()
248+
let trimmed = line.trim()
249+
250+
if (trimmed.endsWith(':')) {
251+
trimmed = trimmed.slice(0, -1)
252+
}
253+
249254
// Check if it looks like a file path and if the next non-empty line is a code block
250255
if (
251256
trimmed &&
252-
(trimmed.includes('/') || trimmed.includes('\\') || trimmed.includes('.')) &&
257+
(trimmed.includes('/') ||
258+
trimmed.includes('\\') ||
259+
trimmed.includes('.')) &&
253260
!trimmed.endsWith('.') &&
254261
/^[a-zA-Z0-9_./@-]+$/.test(trimmed)
255262
) {
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,4 @@
1+
src/hello-world.ts:
2+
```typescript
3+
console.log('Hello world!')
4+
```

0 commit comments

Comments
 (0)