Skip to content

Commit 04189b9

Browse files
committed
Enhance the clipboard parser to correctly handle filenames and opening backticks appearing on the same line
1 parent 91846f4 commit 04189b9

4 files changed

Lines changed: 35 additions & 1 deletion

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
@@ -333,6 +333,26 @@ describe('clipboard-parser', () => {
333333
load_test_case_file('php-opening-tag', 'file-1.txt')
334334
)
335335
})
336+
337+
it('should handle filename comment and backticks on the same line', () => {
338+
const text = load_test_case_file(
339+
'filename-comment-and-backticks-on-same-line',
340+
'filename-comment-and-backticks-on-same-line.txt'
341+
)
342+
const result = parse_multiple_files({
343+
response: text,
344+
is_single_root_folder_workspace: true
345+
})
346+
347+
expect(result).toHaveLength(1)
348+
expect(result[0].file_path).toBe('src/index.ts')
349+
expect(result[0].content).toBe(
350+
load_test_case_file(
351+
'filename-comment-and-backticks-on-same-line',
352+
'file-1.txt'
353+
)
354+
)
355+
})
336356
})
337357

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

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,16 @@ export const parse_multiple_files = (params: {
178178
const line = lines[i]
179179

180180
if (state == 'TEXT') {
181-
if (line.trim().startsWith('```')) {
181+
const backtick_index = line.indexOf('```')
182+
if (backtick_index != -1) {
183+
const before_backticks = line.substring(0, backtick_index)
184+
if (before_backticks.trim()) {
185+
const extracted_filename =
186+
extract_path_from_line_of_code(before_backticks)
187+
if (extracted_filename) {
188+
last_seen_file_path_comment = extracted_filename
189+
}
190+
}
182191
state = 'CONTENT'
183192
backtick_nesting_level = 1
184193
current_workspace_name = undefined
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+
Some introductory text.
2+
3+
<!-- src/index.ts -->```typescript
4+
console.log("hello");

0 commit comments

Comments
 (0)