Skip to content

Commit a271019

Browse files
committed
Update extension version to 1.73.0 and fix diff parsing to keep only the last patch per file
1 parent 433277b commit a271019

3 files changed

Lines changed: 56 additions & 52 deletions

File tree

packages/browser/src/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"name": "Code Web Chat Connector",
55
"short_name": "CWC",
66
"description": "Connect your editor with free chatbots. Parse websites for context.",
7-
"version": "1.72.0",
7+
"version": "1.73.0",
88
"homepage_url": "https://github.com/robertpiosik/CodeWebChat",
99
"icons": {
1010
"16": "icons/icon-16.png",

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

Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,6 @@ const extract_all_code_block_patches = (params: {
640640
}
641641
code_blocks.push(...xml_blocks)
642642
code_blocks.sort((a, b) => a.start - b.start)
643-
const files_with_diffs = new Set<string>()
644643
const diff_block_patches = new Map<number, Diff[]>()
645644

646645
for (let i = 0; i < code_blocks.length; i++) {
@@ -692,10 +691,6 @@ const extract_all_code_block_patches = (params: {
692691
})
693692
if (parsed_patches.length > 0) {
694693
diff_block_patches.set(block.start, parsed_patches)
695-
for (const p of parsed_patches) {
696-
const file_key = `${p.workspace_name || ''}:${p.file_path}`
697-
files_with_diffs.add(file_key)
698-
}
699694
}
700695
}
701696
}
@@ -717,19 +712,7 @@ const extract_all_code_block_patches = (params: {
717712
})
718713
items.push(...preceding_items)
719714

720-
let patches = diff_block_patches.get(block.start) || []
721-
722-
if (patches.length > 0) {
723-
patches = patches.filter((p) => {
724-
const is_redundant = preceding_items.some(
725-
(item) =>
726-
item.type == 'diff' &&
727-
item.file_path == p.file_path &&
728-
item.workspace_name == p.workspace_name
729-
)
730-
return !is_redundant
731-
})
732-
}
715+
const patches = diff_block_patches.get(block.start) || []
733716

734717
if (patches.length > 0) {
735718
const last_item = items.length > 0 ? items[items.length - 1] : undefined
@@ -786,36 +769,32 @@ const extract_all_code_block_patches = (params: {
786769
})
787770

788771
if (patch) {
789-
const file_key = `${patch.workspace_name || ''}:${patch.file_path}`
790-
if (!files_with_diffs.has(file_key)) {
791-
const text_before_lines = lines.slice(last_block_end + 1, block.start)
792-
items.push(
793-
...process_text_for_deleted_files({
794-
lines: text_before_lines,
795-
is_single_root: params.is_single_root
796-
})
797-
)
772+
const text_before_lines = lines.slice(last_block_end + 1, block.start)
773+
items.push(
774+
...process_text_for_deleted_files({
775+
lines: text_before_lines,
776+
is_single_root: params.is_single_root
777+
})
778+
)
798779

799-
const last_item =
800-
items.length > 0 ? items[items.length - 1] : undefined
801-
if (last_item && last_item.type == 'text') {
802-
remove_path_line_from_text_block({
803-
text_item: last_item,
804-
target_file_path: patch.file_path,
805-
is_single_root: params.is_single_root
806-
})
807-
808-
if (!last_item.content) {
809-
items.pop()
810-
}
811-
}
780+
const last_item = items.length > 0 ? items[items.length - 1] : undefined
781+
if (last_item && last_item.type == 'text') {
782+
remove_path_line_from_text_block({
783+
text_item: last_item,
784+
target_file_path: patch.file_path,
785+
is_single_root: params.is_single_root
786+
})
812787

813-
if (hint_result.workspace_name && !patch.workspace_name) {
814-
patch.workspace_name = hint_result.workspace_name
788+
if (!last_item.content) {
789+
items.pop()
815790
}
816-
items.push(patch)
817-
last_block_end = block.end
818791
}
792+
793+
if (hint_result.workspace_name && !patch.workspace_name) {
794+
patch.workspace_name = hint_result.workspace_name
795+
}
796+
items.push(patch)
797+
last_block_end = block.end
819798
}
820799
}
821800
}
@@ -900,6 +879,27 @@ const parse_multiple_raw_patches = (params: {
900879
return patches
901880
}
902881

882+
const filter_last_diff_per_file = (
883+
items: DiffOrTextBlock[]
884+
): DiffOrTextBlock[] => {
885+
const seen_files = new Set<string>()
886+
const result: DiffOrTextBlock[] = []
887+
888+
for (let i = items.length - 1; i >= 0; i--) {
889+
const item = items[i]
890+
if (item.type === 'diff') {
891+
const file_key = `${item.workspace_name || ''}:${item.file_path}`
892+
if (!seen_files.has(file_key)) {
893+
seen_files.add(file_key)
894+
result.unshift(item)
895+
}
896+
} else {
897+
result.unshift(item)
898+
}
899+
}
900+
return result
901+
}
902+
903903
export const extract_diffs = (params: {
904904
clipboard_text: string
905905
is_single_root: boolean
@@ -918,17 +918,19 @@ export const extract_diffs = (params: {
918918
xml_file_tag_start_regex.test(line.trim())
919919
)
920920

921+
let items: DiffOrTextBlock[]
921922
if (uses_code_blocks || uses_xml_blocks) {
922-
return extract_all_code_block_patches({
923+
items = extract_all_code_block_patches({
923924
normalized_text,
924925
is_single_root: params.is_single_root
925926
})
927+
} else {
928+
items = parse_multiple_raw_patches({
929+
all_lines: lines,
930+
is_single_root: params.is_single_root
931+
})
926932
}
927-
928-
return parse_multiple_raw_patches({
929-
all_lines: lines,
930-
is_single_root: params.is_single_root
931-
})
933+
return filter_last_diff_per_file(items)
932934
}
933935

934936
export const extract_paths_from_lines = (
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
--- a/src/index.ts
22
+++ /dev/null
3-
@@ +0,0 +0,0 @@
3+
@@ -1,2 +0,0 @@
4+
-console.log("hello")
5+
-console.log("old message")

0 commit comments

Comments
 (0)