Skip to content

Commit 3e2f57a

Browse files
committed
Remove validation for zero-context hunks to allow applying diffs that contain only additions
1 parent 5073c49 commit 3e2f57a

1 file changed

Lines changed: 0 additions & 24 deletions

File tree

‎packages/vscode/src/commands/apply-chat-response-command/utils/diff-processor.ts‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,6 @@ export const apply_diff = (params: {
139139

140140
if (line.startsWith('@@')) {
141141
if (search_chunks.length > 0 || replace_chunks.length > 0) {
142-
// Validate that the hunk has context before adding it
143-
if (
144-
!has_context_lines &&
145-
search_chunks.length === 0 &&
146-
replace_chunks.length > 0
147-
) {
148-
throw new Error(
149-
'Zero-context hunk detected: hunks with only additions and no context lines cannot be reliably applied. ' +
150-
'The diff must include surrounding unchanged lines for proper placement.'
151-
)
152-
}
153-
154142
search_replace_blocks.push(
155143
new SearchBlock(search_chunks, replace_chunks, -1)
156144
)
@@ -220,18 +208,6 @@ export const apply_diff = (params: {
220208
}
221209

222210
if (search_chunks.length != 0 || replace_chunks.length != 0) {
223-
// Final validation for zero-context hunks
224-
if (
225-
!has_context_lines &&
226-
search_chunks.length === 0 &&
227-
replace_chunks.length > 0
228-
) {
229-
throw new Error(
230-
'Zero-context hunk detected: hunks with only additions and no context lines cannot be reliably applied. ' +
231-
'The diff must include surrounding unchanged lines for proper placement.'
232-
)
233-
}
234-
235211
// This is crucial for diffs that only have deletions
236212
search_replace_blocks.push(
237213
new SearchBlock(search_chunks, replace_chunks, -1)

0 commit comments

Comments
 (0)