Skip to content

Commit 89321dc

Browse files
committed
Refine text block handling in multiple-files-parser to preserve leading/trailing whitespace around code blocks and ensure final text items are trimmed
1 parent 28dac5c commit 89321dc

3 files changed

Lines changed: 62 additions & 8 deletions

File tree

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export const parse_multiple_files = (params: {
6868
}
6969

7070
if (current_text_block.trim()) {
71-
results.push({ type: 'text', content: current_text_block.trim() })
71+
results.push({ type: 'text', content: current_text_block })
7272
}
7373
current_text_block = ''
7474

@@ -368,8 +368,8 @@ export const parse_multiple_files = (params: {
368368

369369
const last_result =
370370
results.length > 0 ? results[results.length - 1] : null
371-
if (last_result && last_result.type === 'text') {
372-
last_result.content += '\n' + raw_code_block
371+
if (last_result && last_result.type == 'text') {
372+
last_result.content += raw_code_block
373373
} else {
374374
results.push({ type: 'text', content: raw_code_block })
375375
}
@@ -381,7 +381,7 @@ export const parse_multiple_files = (params: {
381381
current_workspace_name = undefined
382382
xml_file_mode = false
383383
in_cdata = false
384-
if (last_backticks_index !== -1) {
384+
if (last_backticks_index != -1) {
385385
current_text_block = line.substring(last_backticks_index + 3)
386386
}
387387
} else {
@@ -551,7 +551,8 @@ export const parse_multiple_files = (params: {
551551
!lang_is_markdown ||
552552
is_markdown_file ||
553553
backtick_nesting_level > 1 ||
554-
(current_file_name && !is_markdown_container_block)
554+
(current_file_name && !is_markdown_container_block) ||
555+
!current_file_name
555556
) {
556557
if (current_content) {
557558
current_content += '\n' + line
@@ -605,9 +606,16 @@ export const parse_multiple_files = (params: {
605606
results.push(new_file)
606607
}
607608
}
608-
} else if (state === 'TEXT' && current_text_block.trim()) {
609+
} else if (state == 'TEXT' && current_text_block.trim()) {
609610
results.push({ type: 'text', content: current_text_block.trim() })
610611
}
611612

613+
// Trim text items at the end to ensure clean output
614+
for (const result of results) {
615+
if (result.type == 'text') {
616+
result.content = result.content.trim()
617+
}
618+
}
619+
612620
return results
613621
}
Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
1-
Bottom `test test`.
1+
---
2+
3+
### List of removed comments (one per line)
4+
5+
```markdown
6+
// 1 minute in milliseconds
7+
// Get unstitched images from API
8+
// No unstitched scenes available.
9+
// Processing scene ${data.scene_id} from tour ${data.tour_id}
10+
// Create temporary directory
11+
// Download all images
12+
// Download hugin project if available
13+
// Clear and prepare working directory
14+
// Copy files to working directory
15+
// Run stitcher
16+
// Append the file buffer directly - form-data package handles this properly
17+
// If layer_name exists
18+
// Clean up temp directory
19+
// Indicate successful processing
20+
// Error processing unstitched images
21+
// Starting unstitched images checker...
22+
// If no images were available or processing failed, wait for the interval
23+
// If processing was successful, immediately try processing the next image
24+
```

‎packages/vscode/src/commands/apply-chat-response-command/utils/clipboard-parser/test-cases/text-between/text-between.txt‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,27 @@ console.log('some inline code');
1515
console.log('ipsum');
1616
```
1717

18-
Bottom `test test`.
18+
---
19+
20+
### List of removed comments (one per line)
21+
22+
```markdown
23+
// 1 minute in milliseconds
24+
// Get unstitched images from API
25+
// No unstitched scenes available.
26+
// Processing scene ${data.scene_id} from tour ${data.tour_id}
27+
// Create temporary directory
28+
// Download all images
29+
// Download hugin project if available
30+
// Clear and prepare working directory
31+
// Copy files to working directory
32+
// Run stitcher
33+
// Append the file buffer directly - form-data package handles this properly
34+
// If layer_name exists
35+
// Clean up temp directory
36+
// Indicate successful processing
37+
// Error processing unstitched images
38+
// Starting unstitched images checker...
39+
// If no images were available or processing failed, wait for the interval
40+
// If processing was successful, immediately try processing the next image
41+
```

0 commit comments

Comments
 (0)