Skip to content

Commit e43ade8

Browse files
committed
Support parsing file paths specified in bolded markdown text immediately preceding a code block
1 parent 0c302dd commit e43ade8

4 files changed

Lines changed: 30 additions & 0 deletions

File tree

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,22 @@ describe('clipboard-parser', () => {
538538
})
539539
})
540540

541+
it('parses file path from bolded text above a code block', () => {
542+
const test_case = 'path-above-code-block-bold'
543+
const text = load_test_case_file(test_case, `${test_case}.txt`)
544+
const result = parse_multiple_files({
545+
response: text,
546+
is_single_root_folder_workspace: true
547+
})
548+
549+
expect(result).toHaveLength(1)
550+
expect(result[0]).toMatchObject({
551+
type: 'file',
552+
file_path: 'src/hello-world.ts',
553+
content: load_test_case_file(test_case, '1-file.txt')
554+
})
555+
})
556+
541557
it('handles path duplicated in empty code block', () => {
542558
const test_case = 'path-duplicated-in-empty-code-block'
543559
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,14 @@ export const parse_multiple_files = (params: {
255255
if (!last_seen_file_path_comment) {
256256
let trimmed = line.trim()
257257

258+
const markdown_markers = ['***', '**', '*']
259+
for (const marker of markdown_markers) {
260+
if (trimmed.startsWith(marker) && trimmed.endsWith(marker)) {
261+
trimmed = trimmed.slice(marker.length, -marker.length)
262+
break
263+
}
264+
}
265+
258266
if (trimmed.endsWith(':')) {
259267
trimmed = trimmed.slice(0, -1)
260268
}
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+
**src/hello-world.ts**
2+
3+
```typescript
4+
console.log('Hello world!')
5+
```

0 commit comments

Comments
 (0)