Skip to content

Commit 0239991

Browse files
committed
Merge branch 'dev'
2 parents ffe6542 + d93c34c commit 0239991

5 files changed

Lines changed: 67 additions & 12 deletions

File tree

‎packages/vscode/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "gemini-coder",
33
"displayName": "Code Web Chat",
44
"description": "AI coding without agents (CWC)",
5-
"version": "1.529.0",
5+
"version": "1.530.0",
66
"scripts": {
77
"build": "npx vsce package --no-dependencies",
88
"vscode:prepublish": "rimraf out && npm run compile",

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,7 @@ export const parse_response = (params: {
101101
is_single_root: is_single_root_folder_workspace
102102
})
103103
if (patches_or_text.length) {
104-
return patches_or_text.map((item) => {
105-
if ('type' in item && item.type == 'text') {
106-
return item
107-
}
108-
return { type: 'diff', ...item }
109-
})
104+
return patches_or_text
110105
}
111106
}
112107

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

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { extract_path_from_line_of_code } from '@shared/utils/extract-path-from-
33
import { extract_workspace_and_path } from '../clipboard-parser'
44

55
export type Diff = {
6+
type: 'diff'
67
file_path: string
78
content: string
89
workspace_name?: string
@@ -133,6 +134,7 @@ const process_collected_patch_lines = (params: {
133134
})
134135

135136
const patch: Diff = {
137+
type: 'diff',
136138
file_path: relative_path,
137139
workspace_name,
138140
content: content_str.endsWith('\n') ? content_str : content_str + '\n'
@@ -176,7 +178,12 @@ const convert_code_block_to_new_file_diff = (params: {
176178
const xml_match = first_line.match(xml_path_regex)
177179

178180
if (xml_match && xml_match[1]) {
179-
file_path = xml_match[1].replace(/\\/g, '/')
181+
const potential_path = xml_match[1].replace(/\\/g, '/')
182+
if (potential_path.endsWith('/')) {
183+
// This is a directory, not a file.
184+
return null
185+
}
186+
file_path = potential_path
180187

181188
const file_tag_start = params.lines.findIndex((l) =>
182189
l.trim().startsWith('<file')
@@ -226,8 +233,11 @@ const convert_code_block_to_new_file_diff = (params: {
226233
const potential_path = match[1]
227234

228235
if (
236+
!potential_path.endsWith('/') &&
237+
!potential_path.endsWith('\\') &&
229238
(potential_path.includes('.') || potential_path.includes('/')) &&
230-
!potential_path.includes(' ')
239+
!potential_path.includes(' ') &&
240+
/[a-zA-Z0-9]/.test(potential_path)
231241
) {
232242
const rest_of_line = line
233243
.substring(line.indexOf(potential_path) + potential_path.length)
@@ -279,6 +289,7 @@ const convert_code_block_to_new_file_diff = (params: {
279289
].join('\n')
280290

281291
return {
292+
type: 'diff',
282293
file_path: relative_path,
283294
workspace_name,
284295
content: patch_content + '\n'
@@ -299,6 +310,7 @@ const convert_code_block_to_new_file_diff = (params: {
299310
].join('\n')
300311

301312
return {
313+
type: 'diff',
302314
file_path: relative_path,
303315
workspace_name,
304316
content: patch_content + '\n'
@@ -417,13 +429,30 @@ const extract_all_code_block_patches = (params: {
417429
// Process each found code block in order of appearance.
418430
for (let i = 0; i < code_blocks.length; i++) {
419431
const block = code_blocks[i]
432+
const block_lines = lines.slice(block.start + 1, block.end)
433+
434+
if (block.type != 'diff' && block.type != 'patch') {
435+
const has_truncation_comment = block_lines.some((line) => {
436+
const trimmed = line.trim()
437+
return (
438+
trimmed.startsWith('// ...') ||
439+
trimmed.startsWith('# ...') ||
440+
trimmed.startsWith('/* ...') ||
441+
trimmed.startsWith('* ...') ||
442+
trimmed.startsWith('-- ...') ||
443+
trimmed.startsWith('<!-- ...')
444+
)
445+
})
446+
if (has_truncation_comment) {
447+
continue
448+
}
449+
}
420450

421451
const text_before = lines.slice(last_block_end + 1, block.start).join('\n')
422452
if (text_before.trim()) {
423453
items.push({ type: 'text', content: text_before.trim() })
424454
}
425455

426-
const block_lines = lines.slice(block.start + 1, block.end) // Exclude the ``` lines
427456
if (block.type == 'diff' || block.type == 'patch') {
428457
items.push(...(diff_block_patches.get(block.start) || []))
429458
} else {
@@ -468,6 +497,10 @@ const extract_all_code_block_patches = (params: {
468497
}
469498

470499
if (extracted) {
500+
if (extracted.endsWith('/') || extracted.endsWith('\\')) {
501+
continue
502+
}
503+
471504
file_path_hint = extracted
472505
const { workspace_name } = extract_workspace_and_path({
473506
raw_file_path: extracted,
@@ -485,6 +518,17 @@ const extract_all_code_block_patches = (params: {
485518
})
486519

487520
if (patch) {
521+
const last_item = items.length > 0 ? items[items.length - 1] : undefined
522+
if (
523+
file_path_hint &&
524+
last_item &&
525+
last_item.type == 'text' &&
526+
(last_item.content.trim() == file_path_hint ||
527+
last_item.content.trim() == `\`${file_path_hint}\``)
528+
) {
529+
items.pop()
530+
}
531+
488532
const file_key = `${patch.workspace_name || ''}:${patch.file_path}`
489533

490534
if (!files_with_diffs.has(file_key)) {
@@ -493,6 +537,11 @@ const extract_all_code_block_patches = (params: {
493537
}
494538
items.push(patch)
495539
}
540+
} else {
541+
const block_content = lines.slice(block.start, block.end + 1).join('\n')
542+
if (block_lines.join('').trim()) {
543+
items.push({ type: 'text', content: block_content })
544+
}
496545
}
497546
}
498547
last_block_end = block.end
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
Top.
1+
Lorem ipsum `src/index.ts`
2+
3+
```ts
4+
console.log();
5+
// ...
6+
```

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
Top.
1+
Lorem ipsum `src/index.ts`
2+
3+
```ts
4+
console.log();
5+
// ...
6+
```
7+
28

39
```diff
410
--- a/src/lorem.ts

0 commit comments

Comments
 (0)