Skip to content

Commit c25adf3

Browse files
committed
Refactor file path detection logic to avoid duplicating checks for plain file paths followed by code blocks
1 parent de5e70b commit c25adf3

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,31 @@ export const parse_multiple_files = (params: {
243243
current_text_block += line + '\n'
244244
}
245245
} else {
246+
// Check if this line is a plain file path followed by a code block
247+
if (!last_seen_file_path_comment) {
248+
const trimmed = line.trim()
249+
// Check if it looks like a file path and if the next non-empty line is a code block
250+
if (
251+
trimmed &&
252+
(trimmed.includes('/') || trimmed.includes('\\') || trimmed.includes('.')) &&
253+
!trimmed.endsWith('.') &&
254+
/^[a-zA-Z0-9_./@-]+$/.test(trimmed)
255+
) {
256+
let is_followed_by_code_block = false
257+
for (let j = i + 1; j < lines.length; j++) {
258+
const next_line = lines[j].trim()
259+
if (next_line.startsWith('```')) {
260+
is_followed_by_code_block = true
261+
break
262+
} else if (next_line !== '') {
263+
break
264+
}
265+
}
266+
if (is_followed_by_code_block) {
267+
last_seen_file_path_comment = trimmed
268+
}
269+
}
270+
}
246271
if (!last_seen_file_path_comment) {
247272
current_text_block += line + '\n'
248273
}

0 commit comments

Comments
 (0)