Skip to content

Commit 353322b

Browse files
committed
Add test case generic-4 and fix diff processor to preserve unmatched ~nnn lines
1 parent d993d8d commit 353322b

4 files changed

Lines changed: 30 additions & 14 deletions

File tree

‎apps/editor/src/commands/apply-chat-response-command/utils/diff-processor/diff-processor.spec.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,19 @@ describe('diff-processor', () => {
9898

9999
expect(result).toBe(expected)
100100
})
101+
102+
it('applies diff with generic test case 4 correctly', async () => {
103+
const test_case = 'generic-4'
104+
const original = load_test_case_file('', test_case, 'original.txt')
105+
const diff = load_test_case_file('', test_case, 'diff.txt')
106+
const expected = load_test_case_file('', test_case, 'expected.txt')
107+
108+
const result = apply_diff({
109+
original_code: original,
110+
diff_patch: diff
111+
})
112+
113+
expect(result).toBe(expected)
114+
})
101115
})
102116
})

‎apps/editor/src/commands/apply-chat-response-command/utils/diff-processor/diff-processor.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,19 @@ export const apply_diff = (params: {
295295
const replacement_content: string[] = []
296296
let last_original_idx = start_index - 1
297297

298+
const matched_original_indices = new Set(
299+
block.search_to_original_map.values()
300+
)
301+
298302
for (const line of block.replace_lines) {
299303
if (line.search_index != null) {
300304
const original_idx = block.search_to_original_map.get(line.search_index)
301305
if (original_idx != undefined) {
302306
for (let skip = last_original_idx + 1; skip < original_idx; skip++) {
303-
if (original_code_lines_normalized[skip].value == '~nnn') {
307+
if (
308+
original_code_lines_normalized[skip].value == '~nnn' &&
309+
!matched_original_indices.has(skip)
310+
) {
304311
replacement_content.push(original_code_lines[skip])
305312
}
306313
}
@@ -323,7 +330,10 @@ export const apply_diff = (params: {
323330
block.actual_original_line_count || block.search_lines.length
324331
const end_original_idx = start_index + search_count - 1
325332
for (let skip = last_original_idx + 1; skip <= end_original_idx; skip++) {
326-
if (original_code_lines_normalized[skip].value == '~nnn') {
333+
if (
334+
original_code_lines_normalized[skip].value == '~nnn' &&
335+
!matched_original_indices.has(skip)
336+
) {
327337
replacement_content.push(original_code_lines[skip])
328338
}
329339
}

‎apps/editor/src/commands/apply-chat-response-command/utils/diff-processor/test-cases/generic-4/diff.txt‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
Refactoring `search_files_for_context_command` to utilize `vscode.workspace.findFiles` significantly improves performance by leveraging VS Code's internal file indexing, replacing the previous manual `fs` iteration.
2-
3-
> **Note:** This change shifts the behavior to **filename-only search** (glob-based). It will no longer grep the content of files, as `vscode.workspace.findFiles` searches paths.
4-
5-
### Updated file: `apps/editor/src/commands/search-files-for-context.ts`
6-
7-
```diff
81
--- a/apps/editor/src/commands/search-files-for-context.ts
92
+++ b/apps/editor/src/commands/search-files-for-context.ts
103
@@ -2,5 +2,4 @@
@@ -150,7 +143,4 @@ Refactoring `search_files_for_context_command` to utilize `vscode.workspace.find
150143
-
151144
-
152145
- return matched_files
153-
-}
154-
155-
156-
```
146+
-}

‎apps/editor/src/commands/apply-chat-response-command/utils/diff-processor/test-cases/generic-4/expected.txt‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@ export const search_files_for_context_command = (
8686
initial_keywords = keywords_input
8787

8888
const term = keywords_input.trim()
89-
if (term.length == 0) return
89+
if (term.length === 0) return
9090

91+
// If the user input contains a wildcard, treat it as a glob.
92+
// Otherwise, wrap it to search for any file containing the term.
9193
const glob_pattern = term.includes('*') ? term : `**/*${term}*`
9294
let matched_uris: vscode.Uri[] = []
9395

0 commit comments

Comments
 (0)