Skip to content

Commit e3d8e7d

Browse files
committed
Enhance to correctly extract file paths when they are specified immediately after the language identifier in a markdown code block (e.g., javascript:src/index.js)
1 parent 24e9d2c commit e3d8e7d

4 files changed

Lines changed: 43 additions & 0 deletions

File tree

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,23 @@ describe('clipboard-parser', () => {
338338
)
339339
)
340340
})
341+
342+
it('should parse language and path format', () => {
343+
const text = load_test_case_file(
344+
'language-and-path',
345+
'language-and-path.txt'
346+
)
347+
const result = parse_multiple_files({
348+
response: text,
349+
is_single_root_folder_workspace: true
350+
})
351+
352+
expect(result).toHaveLength(1)
353+
expect(result[0].file_path).toBe('src/index.js')
354+
expect(result[0].content).toBe(
355+
load_test_case_file('language-and-path', 'file-1.txt')
356+
)
357+
})
341358
})
342359

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

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,22 @@ export const parse_multiple_files = (params: {
188188
last_seen_file_path_comment = extracted_filename
189189
}
190190
}
191+
192+
const after_backticks = line.substring(backtick_index + 3).trim()
193+
if (after_backticks) {
194+
const parts = after_backticks.split(':')
195+
if (parts.length > 1) {
196+
const potential_path = parts.slice(1).join(':').trim()
197+
if (
198+
potential_path.includes('/') ||
199+
potential_path.includes('\\') ||
200+
potential_path.includes('.')
201+
) {
202+
last_seen_file_path_comment = potential_path
203+
}
204+
}
205+
}
206+
191207
state = 'CONTENT'
192208
backtick_nesting_level = 1
193209
current_workspace_name = undefined
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+
Some text before the code block.
2+
3+
```javascript:src/index.js
4+
const message = "hello world";
5+
console.log(message);
6+
```
7+
8+
Some text after.

0 commit comments

Comments
 (0)