Skip to content

Commit e866a09

Browse files
committed
Improve diff parsing logic to handle new file modifications and filter out false-positive file paths in conversational text
1 parent b8b4b85 commit e866a09

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

apps/editor/src/commands/apply-chat-response-command/utils/clipboard-parser/parsers/diff-parser/diff-parser.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,16 @@ const merge_diffs_per_file = (items: DiffParserItem[]): DiffParserItem[] => {
748748
(l.startsWith(' ') && !l.startsWith(' '))
749749
)
750750

751-
if (!existing_has_real_hunks) {
751+
const existing_is_new_file = existing_lines.some(
752+
(l) => l === '--- /dev/null'
753+
)
754+
const incoming_is_modification =
755+
!item.content.includes('--- /dev/null') && item.content.includes('@@')
756+
757+
if (
758+
!existing_has_real_hunks ||
759+
(existing_is_new_file && incoming_is_modification)
760+
) {
752761
existing_diff.content = item.content
753762
} else {
754763
const new_lines = item.content.replace(/\n$/, '').split('\n')

apps/editor/src/commands/apply-chat-response-command/utils/clipboard-parser/parsers/diff-parser/helpers/block-utils.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ export const find_file_path_before_block = (params: {
2828
continue
2929
}
3030

31+
if (!prev_line.startsWith('###')) {
32+
const line_without_path = prev_line
33+
.replace('`' + extracted + '`', '')
34+
.replace(extracted, '')
35+
.trim()
36+
const remaining_words = line_without_path
37+
.split(/\s+/)
38+
.filter((w) => /[a-zA-Z]{2,}/.test(w))
39+
if (remaining_words.length >= 5) {
40+
continue
41+
}
42+
}
43+
3144
const { workspace_name } = extract_workspace_and_path({
3245
raw_file_path: extracted,
3346
is_single_root_folder_workspace: params.is_single_root

0 commit comments

Comments
 (0)