Skip to content

Commit 5fc0d24

Browse files
committed
Add support for parsing file paths immediately following opening markdown code block backticks
1 parent ea6e395 commit 5fc0d24

4 files changed

Lines changed: 40 additions & 0 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
@@ -427,6 +427,21 @@ describe('clipboard-parser', () => {
427427
load_test_case_file(test_case, 'file-1.txt')
428428
)
429429
})
430+
431+
it('parses file path when it is included immediately after the opening code block backticks', () => {
432+
const test_case = 'markdown-backticks-file-path-in-one-line'
433+
const text = load_test_case_file(test_case, `${test_case}.txt`)
434+
const result = parse_multiple_files({
435+
response: text,
436+
is_single_root_folder_workspace: true
437+
})
438+
439+
expect(result).toHaveLength(1)
440+
expect(result[0].file_path).toBe('src/index.js')
441+
expect(result[0].content).toBe(
442+
load_test_case_file(test_case, 'file-1.txt')
443+
)
444+
})
430445
})
431446

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

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,21 @@ export const parse_multiple_files = (params: {
216216
) {
217217
last_seen_file_path_comment = potential_path
218218
}
219+
} else {
220+
let extracted_filename: string | null = null
221+
const lang_and_path = after_backticks.split(/\s+/)
222+
if (lang_and_path.length > 1) {
223+
const potential_path_part = lang_and_path.slice(1).join(' ')
224+
extracted_filename =
225+
extract_path_from_line_of_code(potential_path_part)
226+
}
227+
if (!extracted_filename) {
228+
extracted_filename =
229+
extract_path_from_line_of_code(after_backticks)
230+
}
231+
if (extracted_filename) {
232+
last_seen_file_path_comment = extracted_filename
233+
}
219234
}
220235
}
221236
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const message = "hello world";
2+
console.log(message);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Text before.
2+
3+
```// src/index.js
4+
const message = "hello world";
5+
console.log(message);
6+
```
7+
8+
Text after.

0 commit comments

Comments
 (0)