Skip to content

Commit f5a66f0

Browse files
committed
Enhance clipboard parsing to recognize file paths placed above markdown code blocks
1 parent 40ef788 commit f5a66f0

6 files changed

Lines changed: 44 additions & 18 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Generate meaningful summaries of changes adhering to your style.
131131

132132
## Enterprise security
133133

134-
**Code Web Chat operates exclusively on your machine and does not collect telemetry.** Your code and instructions are sent directly to chatbots via editor-browser communication channel run on local Websockets. For API tools, model providers are called directly.
134+
**Code Web Chat operates exclusively on your machine.** Your code and instructions are sent directly to chatbots via editor-browser communication channel run on local Websockets. For API tools, model providers are called directly.
135135

136136
## Community
137137

‎packages/vscode/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
"visibility": "collapsed"
9090
},
9191
{
92-
"id": "codeWebChatViewCheckpoint",
92+
"id": "codeWebChatViewCheckpoints",
9393
"name": "Checkpoints",
9494
"icon": "resources/activity-bar-icon.svg",
9595
"visibility": "collapsed"
@@ -546,7 +546,7 @@
546546
"scope": "resource",
547547
"description": "Style of generated code blocks in \"Edit context\" mode.",
548548
"default": {
549-
"whole": "Whenever proposing a new or updated file use the Markdown Code Block syntax. It's very important to place a file path in a comment on the top of the code block. Please show me the full code of the changed files because I have a disability which means I can't type and need to be able to copy and paste the full code. Don't use XML for files.",
549+
"whole": "Whenever proposing a new or updated file use the Markdown Code Block syntax. It's very important to place a file path in a comment on the top of the code block. Please show me the full code of the proposed files because I have a disability which means I can't type and need to be able to just copy and paste. Don't use XML for files.",
550550
"truncated": "Whenever proposing a new or updated file use the Markdown Code Block syntax. It's very important to place a full file path in a comment on the top of the code block. Use ellipsis comments, e.g. \"// ...\", when appropriate. Don't use XML for files.",
551551
"diff": "Whenever proposing a new or updated file use the Markdown Code Block syntax. Each code block should be a diff patch. Don't use XML for files."
552552
},

‎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
@@ -372,6 +372,23 @@ describe('clipboard-parser', () => {
372372
load_test_case_file('path-in-markdown-argument', 'file-1.txt')
373373
)
374374
})
375+
376+
it('should parse path from above code block', () => {
377+
const text = load_test_case_file(
378+
'path-above-code-block',
379+
'path-above-code-block.txt'
380+
)
381+
const result = parse_multiple_files({
382+
response: text,
383+
is_single_root_folder_workspace: true
384+
})
385+
386+
expect(result).toHaveLength(1)
387+
expect(result[0].file_path).toBe('src/hello-world.ts')
388+
expect(result[0].content).toBe(
389+
load_test_case_file('path-above-code-block', 'file-1.txt')
390+
)
391+
})
375392
})
376393

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

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -255,22 +255,22 @@ export const parse_multiple_files = (params: {
255255
continue
256256
}
257257
}
258-
const trimmed_line = line.trim()
259-
const is_comment =
260-
trimmed_line.startsWith('//') ||
261-
trimmed_line.startsWith('#') ||
262-
trimmed_line.startsWith('/*') ||
263-
trimmed_line.startsWith('*') ||
264-
trimmed_line.startsWith('--') ||
265-
trimmed_line.startsWith('<!--')
266-
267-
if (is_comment) {
268-
const extracted_filename = extract_path_from_line_of_code(line)
269-
if (extracted_filename) {
270-
last_seen_file_path_comment = extracted_filename
258+
let extracted_filename = extract_path_from_line_of_code(line)
259+
if (!extracted_filename) {
260+
const match = line.match(/`([^`]+)`/)
261+
if (match && match[1]) {
262+
const potential_path = match[1]
263+
if (
264+
potential_path.includes('/') ||
265+
potential_path.includes('\\') ||
266+
potential_path.includes('.')
267+
) {
268+
extracted_filename = potential_path
269+
}
271270
}
272-
} else if (trimmed_line !== '') {
273-
last_seen_file_path_comment = null
271+
}
272+
if (extracted_filename) {
273+
last_seen_file_path_comment = extracted_filename
274274
}
275275
} else if (state == 'CONTENT') {
276276
if (top_level_xml_file_mode) {
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,8 @@
1+
2+
### New File: `src/hello-world.ts`
3+
4+
This new file
5+
6+
```typescript
7+
console.log('Hello world!')
8+
```

0 commit comments

Comments
 (0)