Skip to content

Commit c22e533

Browse files
committed
Enable the clipboard parser to extract file paths embedded within multi-line comments
1 parent 0024690 commit c22e533

5 files changed

Lines changed: 38 additions & 4 deletions

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
@@ -492,6 +492,26 @@ describe('clipboard-parser', () => {
492492
}
493493
})
494494

495+
it('parses file content when file path is in a multi-line comment', () => {
496+
const test_case = 'path-in-multi-line-comment'
497+
const text = load_test_case_file(
498+
test_case,
499+
`path-in-multi-line-comment.txt`
500+
)
501+
const result = parse_file_content_only({
502+
response: text,
503+
is_single_root_folder_workspace: true
504+
})
505+
506+
expect(result).not.toBeNull()
507+
if (result) {
508+
expect(result.file_path).toBe('src/index.ts')
509+
expect(result.content).toBe(
510+
load_test_case_file(test_case, '1-file.txt')
511+
)
512+
}
513+
})
514+
495515
it('returns null when response is just text and not a file', () => {
496516
const text = 'This is just regular text without a file path'
497517
const result = parse_file_content_only({

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,18 @@ export const parse_multiple_files = (params: {
186186
!potential_path.includes(' ') &&
187187
/[a-zA-Z0-9]/.test(potential_path)
188188
) {
189-
extracted_filename = potential_path
189+
let is_followed_by_code_block = false
190+
for (let j = i + 1; j < lines.length; j++) {
191+
const next_line = lines[j].trim()
192+
if (next_line.startsWith('```')) {
193+
is_followed_by_code_block = true
194+
break
195+
}
196+
}
197+
198+
if (is_followed_by_code_block) {
199+
extracted_filename = potential_path
200+
}
190201
}
191202
}
192203
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
/**
2-
* src/index.ts
3-
*/
1+
// src/index.ts
42
console.log("hello")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("hello")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* src/index.ts
3+
*/
4+
console.log("hello")

0 commit comments

Comments
 (0)