Skip to content

Commit 8438973

Browse files
committed
Remove support for parsing diffs inside non-diff code blocks
- simplify `apps/editor/src/commands/apply-response-command/utils/response-parser/parsers/diff-parser/diff-parser.ts` by not handling paths plased inside code blocks (don't touch tests) └── apps └── editor └── src └── commands └── apply-response-command └── utils └── response-parser └── parsers └── diff-parser ├── diff-parser.ts ├── helpers │ ├── block-utils.ts │ ├── index.ts │ ├── patch-utils.ts │ └── path-utils.ts ├── index.ts └── test ├── cases │ ├── deletion-via-header │ │ ├── 1-file.txt │ │ ├── 2-file.txt │ │ └── deletion-via-header.txt │ ├── deletion-via-redundant-header │ │ ├── 1-file.txt │ │ └── deletion-via-redundant-header.txt │ ├── file-deletion │ │ ├── 1-file.txt │ │ └── file-deletion.txt │ ├── git-and-hunk-header-same-line │ │ ├── 1-file.txt │ │ └── git-and-hunk-header-same-line.txt │ ├── git-broken-hunk-header │ │ ├── 1-file.txt │ │ └── git-broken-hunk-header.txt │ ├── git-two-header-types │ │ ├── 1-file.txt │ │ └── git-two-header-types.txt │ ├── ignore-ellipsis │ │ ├── 1-file.txt │ │ ├── 2-file.txt │ │ └── ignore-ellipsis.txt │ ├── inner-backticks │ │ ├── 1-file.txt │ │ └── inner-backticks.txt │ ├── inner-triple-backticks │ │ ├── 1-file.txt │ │ └── inner-triple-backticks.txt │ ├── markdown-missing-ending │ │ ├── 1-file.txt │ │ └── markdown-missing-ending.txt │ ├── markdown-path-above │ │ ├── 1-file.txt │ │ └── markdown-path-above.txt │ ├── markdown-path-above-no-hunk-header │ │ ├── 1-file.txt │ │ └── markdown-path-above-no-hunk-header.txt │ ├── markdown-path-above-with-text-containing-path │ │ ├── 1-text.txt │ │ ├── 2-file.txt │ │ └── markdown-path-above-with-text-containing-path.txt │ ├── markdown-redundant-closing-backticks │ │ ├── 1-file.txt │ │ └── markdown-redundant-closing-backticks.txt │ ├── markdown-repeated-path-above │ │ ├── 1-text.txt │ │ ├── 2-file.txt │ │ └── markdown-repeated-path-above.txt │ ├── markdown-unnecessary-empty-lines │ │ ├── 1-file.txt │ │ └── markdown-path-above.txt │ ├── mix-delete-and-new-file │ │ ├── 1-file.txt │ │ ├── 2-file.txt │ │ └── mix-delete-and-new-file.txt │ ├── mix-new-file-from-heading-and-diff │ │ ├── 1-text.txt │ │ ├── 2-file.txt │ │ ├── 3-file.txt │ │ └── mix-new-file-from-heading-and-diff.txt │ ├── mix-new-file-from-xml-tag-heading-and-diff │ │ ├── 1-text.txt │ │ ├── 2-file.txt │ │ ├── 3-file.txt │ │ └── mix-new-file-from-xml-tag-heading-and-diff.txt │ ├── mix-new-file-xml-and-diff-variant-1 │ │ ├── 1-file.txt │ │ ├── 2-file.txt │ │ └── mix-new-file-xml-and-diff-variant-1.txt │ ├── mix-new-file-xml-and-diff-variant-2 │ │ ├── 1-file.txt │ │ ├── 2-file.txt │ │ └── mix-new-file-xml-and-diff-variant-2.txt │ ├── mix-rename-and-update │ │ ├── 1-file.txt │ │ └── mix-rename-and-update.txt │ ├── mix-rename-one-liner-and-diff │ │ ├── 1-file.txt │ │ ├── 2-file.txt │ │ └── mix-rename-one-liner-and-diff.txt │ ├── multiple-edits-for-the-same-file │ │ ├── 1-text.txt │ │ ├── 2-file.txt │ │ └── multiple-edits-for-the-same-file.txt │ ├── multiple-files-git-and-hunk-header-same-line │ │ ├── 1-file.txt │ │ ├── 2-file.txt │ │ └── multiple-files-git-and-hunk-header-same-line.txt │ ├── multiple-files-no-markdown-block │ │ ├── 1-file.txt │ │ ├── 2-file.txt │ │ └── multiple-files-no-markdown-block.txt │ ├── multiple-files-no-prefix-single-markdown-block │ │ ├── 1-file.txt │ │ ├── 2-file.txt │ │ └── multiple-files-no-prefix-single-markdown-block.txt │ ├── multiple-files-same-line-backticks │ │ ├── 1-file.txt │ │ ├── 2-file.txt │ │ └── multiple-files-same-line-backticks.txt │ ├── multiple-files-separate-markdown-blocks │ │ ├── 1-file.txt │ │ ├── 2-file.txt │ │ └── multiple-files-separate-markdown-blocks.txt │ ├── multiple-files-single-markdown-block │ │ ├── 1-file.txt │ │ ├── 2-file.txt │ │ └── multiple-files-single-markdown-block.txt │ ├── multiple-files-text-between │ │ ├── 1-text.txt │ │ ├── 2-file.txt │ │ ├── 3-text.txt │ │ ├── 4-file.txt │ │ ├── 5-text.txt │ │ └── multiple-files-text-between.txt │ ├── multiple-files-with-git-headers-no-file-lines │ │ ├── 1-file.txt │ │ ├── 2-file.txt │ │ └── multiple-files-with-git-headers-no-file-lines.txt │ ├── multiple-files-with-git-headers-separate-markdown-blocks │ │ ├── 1-file.txt │ │ ├── 2-file.txt │ │ └── multiple-files-with-git-headers-separate-markdown-blocks.txt │ ├── multiple-files-with-quoted-paths │ │ ├── 1-file.txt │ │ ├── 2-file.txt │ │ └── multiple-files-with-quoted-paths.txt │ ├── multiple-files-with-timestamps │ │ ├── 1-file.txt │ │ ├── 2-file.txt │ │ └── multiple-files-with-timestamps.txt │ ├── multiple-new-files-separate-markdown-blocks │ │ ├── 1-file.txt │ │ ├── 2-file.txt │ │ └── multiple-new-files-separate-markdown-blocks.txt │ ├── new-file-with-git-header │ │ ├── 1-file.txt │ │ └── new-file-with-git-header.txt │ ├── no-markdown-or-git-header │ │ ├── 1-file.txt │ │ └── no-markdown-or-git-header.txt │ ├── no-prefix │ │ ├── 1-file.txt │ │ └── no-prefix.txt │ ├── non-diff-code-blocks │ │ ├── 1-text.txt │ │ ├── 2-inline-file.txt │ │ ├── 3-file.txt │ │ └── non-diff-code-blocks.txt │ ├── rename │ │ ├── 1-file.txt │ │ └── rename.txt │ ├── with-empty-lines-between │ │ ├── 1-file.txt │ │ └── with-empty-lines-between.txt │ ├── with-git-header-no-file-lines │ │ ├── 1-file.txt │ │ └── with-git-header-no-file-lines.txt │ ├── with-git-header-no-markdown │ │ ├── 1-file.txt │ │ └── with-git-header-no-markdown.txt │ ├── with-quoted-paths │ │ ├── 1-file.txt │ │ └── with-quoted-paths.txt │ ├── with-timestamps │ │ ├── 1-file.txt │ │ └── with-timestamps.txt │ ├── with-xml-file-path │ │ ├── 1-file.txt │ │ └── with-xml-file-path.txt │ ├── within-xml-tags │ │ ├── 1-file.txt │ │ └── within-xml-tags.txt │ ├── within-xml-tags-unquoted-path │ │ ├── 1-file.txt │ │ └── within-xml-tags-unquoted-path.txt │ └── within-xml-tags-with-cdata │ ├── 1-file.txt │ └── within-xml-tags-with-cdata.txt └── diff-parser.spec.ts
1 parent 7d604de commit 8438973

7 files changed

Lines changed: 1 addition & 111 deletions

File tree

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

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
} from '../../response-parser'
88
import {
99
normalize_path,
10-
is_valid_file_path,
1110
find_file_path_before_block,
1211
remove_path_line_from_text_block,
1312
normalize_header_line,
@@ -113,11 +112,9 @@ const convert_code_block_to_new_file_diff = (params: {
113112
return null
114113
}
115114

116-
const path_regex = /(?:(?:\/\/|#|--|<!--)\s*)?([\w./\\-]+)/
117115
const xml_path_regex = /<([\w-]+)\s+path=(?:["']([^"']+)["']|([^>\s]+))/
118116

119117
let file_path: string | undefined = params.file_path_hint
120-
let path_line_index = -1
121118
let content_lines: string[] = []
122119

123120
const first_line = params.lines.length > 0 ? params.lines[0].trim() : ''
@@ -168,48 +165,14 @@ const convert_code_block_to_new_file_diff = (params: {
168165
}
169166
continue
170167
}
171-
172-
const match = line.match(path_regex)
173-
174-
if (match && match[1]) {
175-
const potential_path = match[1]
176-
177-
if (is_valid_file_path(potential_path)) {
178-
const rest_of_line = line
179-
.substring(line.indexOf(potential_path) + potential_path.length)
180-
.trim()
181-
// e.g. `25:5` for line and column, or `-->` for html comments
182-
const is_just_path_and_location = /^(?:\d+:\d+)?\s*(-->)?\s*$/.test(
183-
rest_of_line
184-
)
185-
186-
if (is_just_path_and_location) {
187-
if (params.file_path_hint) {
188-
if (
189-
normalize_path(potential_path) ==
190-
normalize_path(params.file_path_hint)
191-
) {
192-
path_line_index = i
193-
}
194-
break
195-
}
196-
197-
file_path = normalize_path(potential_path)
198-
path_line_index = i
199-
break
200-
}
201-
}
202-
}
203168
}
204169
}
205170

206171
if (!file_path) {
207172
file_path = params.file_path_hint
208173
}
209174

210-
if (path_line_index != -1) {
211-
content_lines = params.lines.filter((_, index) => index != path_line_index)
212-
} else if (file_path && content_lines.length == 0) {
175+
if (file_path && content_lines.length == 0) {
213176
content_lines = params.lines
214177
}
215178

‎apps/editor/src/commands/apply-response-command/utils/response-parser/parsers/diff-parser/test/cases/in-non-diff-code-block/1-file.txt‎

Lines changed: 0 additions & 6 deletions
This file was deleted.

‎apps/editor/src/commands/apply-response-command/utils/response-parser/parsers/diff-parser/test/cases/in-non-diff-code-block/in-non-diff-code-block.txt‎

Lines changed: 0 additions & 7 deletions
This file was deleted.

‎apps/editor/src/commands/apply-response-command/utils/response-parser/parsers/diff-parser/test/cases/mix-new-file-and-diff/1-file.txt‎

Lines changed: 0 additions & 4 deletions
This file was deleted.

‎apps/editor/src/commands/apply-response-command/utils/response-parser/parsers/diff-parser/test/cases/mix-new-file-and-diff/2-file.txt‎

Lines changed: 0 additions & 6 deletions
This file was deleted.

‎apps/editor/src/commands/apply-response-command/utils/response-parser/parsers/diff-parser/test/cases/mix-new-file-and-diff/mix-new-file-and-diff.txt‎

Lines changed: 0 additions & 13 deletions
This file was deleted.

‎apps/editor/src/commands/apply-response-command/utils/response-parser/parsers/diff-parser/test/diff-parser.spec.ts‎

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -138,22 +138,6 @@ describe('diff-parser', () => {
138138
})
139139
})
140140

141-
it('parses a diff inside a non-diff code block', () => {
142-
const test_case = 'in-non-diff-code-block'
143-
const text = load_test_case_file(test_case, `${test_case}.txt`)
144-
const result = parse_response({
145-
response: text,
146-
is_single_root_folder_workspace: true
147-
})
148-
149-
expect(result).toHaveLength(1)
150-
expect(result[0]).toMatchObject({
151-
type: 'diff',
152-
file_path: 'src/index.ts',
153-
content: load_test_case_file(test_case, '1-file.txt')
154-
})
155-
})
156-
157141
it('parses diff format for a file deletion', () => {
158142
const test_case = 'file-deletion'
159143
const text = load_test_case_file(test_case, `${test_case}.txt`)
@@ -438,27 +422,6 @@ describe('diff-parser', () => {
438422
})
439423
})
440424

441-
it('parses a mix of a new file in a code block and a diff in a diff block', () => {
442-
const test_case = 'mix-new-file-and-diff'
443-
const text = load_test_case_file(test_case, `${test_case}.txt`)
444-
const result = parse_response({
445-
response: text,
446-
is_single_root_folder_workspace: true
447-
})
448-
449-
expect(result).toHaveLength(2)
450-
expect(result[0]).toMatchObject({
451-
type: 'diff',
452-
file_path: 'src/lorem.html',
453-
content: load_test_case_file(test_case, '1-file.txt')
454-
})
455-
expect(result[1]).toMatchObject({
456-
type: 'diff',
457-
file_path: 'src/ipsum.ts',
458-
content: load_test_case_file(test_case, '2-file.txt')
459-
})
460-
})
461-
462425
it('parses a mix of a new file in file-xml format and a diff in a diff block variant-1', () => {
463426
const test_case = 'mix-new-file-xml-and-diff-variant-1'
464427
const text = load_test_case_file(test_case, `${test_case}.txt`)

0 commit comments

Comments
 (0)