Skip to content

Commit e439b64

Browse files
committed
Enhance the clipboard parser to extract file paths specified via or arguments in markdown code block headers, and add corresponding test cases
1 parent 3ce98e2 commit e439b64

5 files changed

Lines changed: 47 additions & 10 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
@@ -355,6 +355,23 @@ describe('clipboard-parser', () => {
355355
load_test_case_file('language-and-path', 'file-1.txt')
356356
)
357357
})
358+
359+
it('should parse path from markdown argument', () => {
360+
const text = load_test_case_file(
361+
'path-in-markdown-argument',
362+
'path-in-markdown-argument.txt'
363+
)
364+
const result = parse_multiple_files({
365+
response: text,
366+
is_single_root_folder_workspace: true
367+
})
368+
369+
expect(result).toHaveLength(1)
370+
expect(result[0].file_path).toBe('src/index.js')
371+
expect(result[0].content).toBe(
372+
load_test_case_file('path-in-markdown-argument', 'file-1.txt')
373+
)
374+
})
358375
})
359376

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

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,25 @@ export const parse_multiple_files = (params: {
191191

192192
const after_backticks = line.substring(backtick_index + 3).trim()
193193
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
194+
const name_match = after_backticks.match(
195+
/(?:path|name)=(?:"([^"]+)"|'([^']+)'|(\S+))/
196+
)
197+
if (name_match) {
198+
const path = name_match[1] || name_match[2] || name_match[3]
199+
if (path) {
200+
last_seen_file_path_comment = path
201+
}
202+
} else {
203+
const parts = after_backticks.split(':')
204+
if (parts.length > 1) {
205+
const potential_path = parts.slice(1).join(':').trim()
206+
if (
207+
potential_path.includes('/') ||
208+
potential_path.includes('\\') ||
209+
potential_path.includes('.')
210+
) {
211+
last_seen_file_path_comment = potential_path
212+
}
203213
}
204214
}
205215
}
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 name=src/index.js
4+
const message = "hello world";
5+
console.log(message);
6+
```
7+
8+
Some text after.

‎packages/vscode/src/views/panel/backend/panel-provider.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ export class ViewProvider implements vscode.WebviewViewProvider {
306306
if (
307307
clipboard_text.trim() &&
308308
last_applied_content &&
309-
clipboard_text === last_applied_content
309+
clipboard_text == last_applied_content
310310
) {
311311
this.send_message({
312312
command: 'CAN_APPLY_CLIPBOARD_CHANGED',

0 commit comments

Comments
 (0)