Skip to content

Commit 4add766

Browse files
committed
Improve clipboard parsing logic to correctly extract file paths from various markdown and XML formats, especially when processing code blocks and surrounding text
1 parent f81ac36 commit 4add766

4 files changed

Lines changed: 34 additions & 49 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": "Superfast AI coding (CWC)",
5-
"version": "1.625.0",
5+
"version": "1.626.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/extract-diff-patches/extract-diffs.ts

Lines changed: 28 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,22 @@ const is_valid_file_path = (potential_path: string): boolean => {
4141
const extract_path_from_potential_string = (line: string) => {
4242
let extracted = extract_path_from_line_of_code(line)
4343

44+
if (!extracted) {
45+
const xml_match = line.match(/^<[^>]+>([^<]+)<\/[^>]+>$/)
46+
if (xml_match && xml_match[1]) {
47+
const potential_path = xml_match[1].trim()
48+
if (
49+
potential_path &&
50+
(potential_path.includes('/') ||
51+
potential_path.includes('\\') ||
52+
potential_path.includes('.')) &&
53+
!potential_path.includes(' ')
54+
) {
55+
extracted = potential_path
56+
}
57+
}
58+
}
59+
4460
if (!extracted) {
4561
let potential_path = line
4662
if (potential_path.endsWith(':')) {
@@ -125,21 +141,11 @@ const find_file_path_before_block = (params: {
125141
continue
126142
}
127143

128-
let all_intermediate_lines_empty = true
129-
for (let k = j + 1; k < params.block_start; k++) {
130-
if (params.lines[k].trim() !== '') {
131-
all_intermediate_lines_empty = false
132-
break
133-
}
134-
}
135-
136-
if (all_intermediate_lines_empty) {
137-
const { workspace_name } = extract_workspace_and_path({
138-
raw_file_path: extracted,
139-
is_single_root_folder_workspace: params.is_single_root
140-
})
141-
return { file_path: extracted, workspace_name }
142-
}
144+
const { workspace_name } = extract_workspace_and_path({
145+
raw_file_path: extracted,
146+
is_single_root_folder_workspace: params.is_single_root
147+
})
148+
return { file_path: extracted, workspace_name }
143149
}
144150
}
145151

@@ -687,39 +693,14 @@ const extract_all_code_block_patches = (params: {
687693
if (patch) {
688694
const last_item = items.length > 0 ? items[items.length - 1] : undefined
689695
if (last_item && last_item.type == 'text') {
690-
const content_lines = last_item.content.split('\n')
691-
let last_non_empty_line_index = -1
692-
let last_non_empty_line = ''
693-
for (let i = content_lines.length - 1; i >= 0; i--) {
694-
if (content_lines[i].trim() !== '') {
695-
last_non_empty_line_index = i
696-
last_non_empty_line = content_lines[i].trim()
697-
break
698-
}
699-
}
696+
remove_path_line_from_text_block({
697+
text_item: last_item,
698+
target_file_path: patch.file_path,
699+
is_single_root: params.is_single_root
700+
})
700701

701-
if (last_non_empty_line) {
702-
const extracted =
703-
extract_path_with_xml_fallback(last_non_empty_line)
704-
705-
if (extracted) {
706-
const { relative_path } = extract_workspace_and_path({
707-
raw_file_path: extracted,
708-
is_single_root_folder_workspace: params.is_single_root
709-
})
710-
if (relative_path === patch.file_path) {
711-
const new_content = content_lines
712-
.slice(0, last_non_empty_line_index)
713-
.join('\n')
714-
.trim()
715-
716-
if (new_content) {
717-
last_item.content = new_content
718-
} else {
719-
items.pop()
720-
}
721-
}
722-
}
702+
if (!last_item.content) {
703+
items.pop()
723704
}
724705
}
725706

Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
Lorem ipsum.
2+
13
Lorem ipsum.

packages/vscode/src/commands/apply-chat-response-command/utils/clipboard-parser/test-cases/diff-mix-new-file-from-heading-and-diff/diff-mix-new-file-from-heading-and-diff.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Lorem ipsum.
22

3-
### New file: `src/lorem.html`
3+
### New file: `src/lorem.html` (Nuovo File)
4+
5+
Lorem ipsum.
46

57
```html
68
<div>lorem ipsum</div>

0 commit comments

Comments
 (0)