Skip to content

Commit 20828ac

Browse files
committed
Replace strict equality checks with loose equality checks and remove redundant comments
1 parent 75eed64 commit 20828ac

1 file changed

Lines changed: 21 additions & 35 deletions

File tree

‎packages/vscode/src/commands/apply-chat-response-command/handlers/conflict-markers-handler.ts‎

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ export const handle_conflict_markers = async (
9595
}
9696
}
9797

98-
// Case 0: Rename operation (with or without markers)
9998
if (rename_source_path && rename_source_content !== undefined) {
10099
try {
101100
let new_content = rename_source_content
@@ -132,7 +131,7 @@ export const handle_conflict_markers = async (
132131
workspace_root
133132
})
134133

135-
if (new_content.trim() === '') {
134+
if (new_content.trim() == '') {
136135
original_states.push({
137136
file_path: file.file_path,
138137
content: rename_source_content,
@@ -161,9 +160,7 @@ export const handle_conflict_markers = async (
161160
} catch (error) {
162161
failed_files.push(file)
163162
}
164-
}
165-
// Case 1: Existing file with conflict markers (The core "Compared" logic)
166-
else if (file_exists && has_markers) {
163+
} else if (file_exists && has_markers) {
167164
try {
168165
const document = await vscode.workspace.openTextDocument(safe_path)
169166
const original_content = document.getText()
@@ -172,7 +169,7 @@ export const handle_conflict_markers = async (
172169
file.content
173170
)
174171

175-
if (current_content.trim() === '') {
172+
if (current_content.trim() == '') {
176173
const tabs_to_close: vscode.Tab[] = []
177174
for (const tab_group of vscode.window.tabGroups.all) {
178175
tabs_to_close.push(
@@ -231,9 +228,7 @@ export const handle_conflict_markers = async (
231228
})
232229
failed_files.push(file)
233230
}
234-
}
235-
// Case 2: New file (regardless of markers, usually won't have them)
236-
else if (!file_exists) {
231+
} else if (!file_exists) {
237232
if (file.content == '') {
238233
original_states.push({
239234
file_path: file.file_path,
@@ -250,17 +245,12 @@ export const handle_conflict_markers = async (
250245
await fs.promises.mkdir(directory, { recursive: true })
251246
}
252247

253-
// For new files, if markers exist, we probably just want the "UPDATED" part,
254-
// but typically new files shouldn't have conflicts compared to "empty".
255-
// We'll write content as is, assuming LLM provided full content for new file.
256-
// If it used markers relative to empty string, it's weird, but parse_compared_content
257-
// would reduce it to just the new content if search text is empty.
258248
let content_to_write = file.content
259249
if (has_markers) {
260250
const segments = parse_conflict_segments(file.content)
261251
content_to_write = segments
262252
.map((s) =>
263-
s.type === 'common'
253+
s.type == 'common'
264254
? s.lines.join('\n')
265255
: s.updated_lines.join('\n')
266256
)
@@ -281,14 +271,12 @@ export const handle_conflict_markers = async (
281271
} catch (error) {
282272
failed_files.push(file)
283273
}
284-
}
285-
// Case 3: Existing file but NO markers (Fallback to Fast Replace behavior)
286-
else if (file_exists && !has_markers) {
274+
} else if (file_exists && !has_markers) {
287275
try {
288276
const document = await vscode.workspace.openTextDocument(safe_path)
289277
const original_content = document.getText()
290278

291-
if (file.content.trim() === '') {
279+
if (file.content.trim() == '') {
292280
const tabs_to_close: vscode.Tab[] = []
293281
for (const tab_group of vscode.window.tabGroups.all) {
294282
tabs_to_close.push(
@@ -382,7 +370,7 @@ function parse_conflict_segments(content: string): Segment[] {
382370

383371
for (const line of lines) {
384372
if (line.trim().startsWith('<<<<<<<')) {
385-
if (state === 'NORMAL') {
373+
if (state == 'NORMAL') {
386374
if (current_lines.length > 0) {
387375
segments.push({ type: 'common', lines: [...current_lines] })
388376
current_lines = []
@@ -391,17 +379,16 @@ function parse_conflict_segments(content: string): Segment[] {
391379
original_buffer = []
392380
updated_buffer = []
393381
} else {
394-
// Nested or malformed? Treat as content of current state
395-
if (state === 'ORIGINAL') original_buffer.push(line)
396-
if (state === 'UPDATED') updated_buffer.push(line)
382+
if (state == 'ORIGINAL') original_buffer.push(line)
383+
if (state == 'UPDATED') updated_buffer.push(line)
397384
}
398385
continue
399386
}
400387

401388
if (line.trim().startsWith('=======')) {
402-
if (state === 'ORIGINAL') {
389+
if (state == 'ORIGINAL') {
403390
state = 'UPDATED'
404-
} else if (state === 'NORMAL') {
391+
} else if (state == 'NORMAL') {
405392
current_lines.push(line)
406393
} else {
407394
updated_buffer.push(line)
@@ -410,7 +397,7 @@ function parse_conflict_segments(content: string): Segment[] {
410397
}
411398

412399
if (line.trim().startsWith('>>>>>>>')) {
413-
if (state === 'UPDATED') {
400+
if (state == 'UPDATED') {
414401
segments.push({
415402
type: 'conflict',
416403
original_lines: original_buffer,
@@ -419,7 +406,7 @@ function parse_conflict_segments(content: string): Segment[] {
419406
state = 'NORMAL'
420407
original_buffer = []
421408
updated_buffer = []
422-
} else if (state === 'ORIGINAL') {
409+
} else if (state == 'ORIGINAL') {
423410
segments.push({
424411
type: 'conflict',
425412
original_lines: original_buffer,
@@ -434,16 +421,16 @@ function parse_conflict_segments(content: string): Segment[] {
434421
continue
435422
}
436423

437-
if (state === 'NORMAL') {
424+
if (state == 'NORMAL') {
438425
current_lines.push(line)
439-
} else if (state === 'ORIGINAL') {
426+
} else if (state == 'ORIGINAL') {
440427
original_buffer.push(line)
441-
} else if (state === 'UPDATED') {
428+
} else if (state == 'UPDATED') {
442429
updated_buffer.push(line)
443430
}
444431
}
445432

446-
if (state === 'NORMAL' && current_lines.length > 0) {
433+
if (state == 'NORMAL' && current_lines.length > 0) {
447434
segments.push({ type: 'common', lines: current_lines })
448435
}
449436

@@ -459,12 +446,12 @@ function apply_conflict_markers_to_content(
459446

460447
for (let i = 0; i < segments.length; i++) {
461448
const segment = segments[i]
462-
if (segment.type === 'conflict') {
449+
if (segment.type == 'conflict') {
463450
const prev = i > 0 ? segments[i - 1] : undefined
464451
const next = i < segments.length - 1 ? segments[i + 1] : undefined
465452

466-
const context_before = prev && prev.type === 'common' ? prev.lines : []
467-
const context_after = next && next.type === 'common' ? next.lines : []
453+
const context_before = prev && prev.type == 'common' ? prev.lines : []
454+
const context_after = next && next.type == 'common' ? next.lines : []
468455

469456
const clean = (lines: string[]) =>
470457
lines.filter((l) => {
@@ -486,7 +473,6 @@ function apply_conflict_markers_to_content(
486473
...after_clean
487474
].join('\n')
488475

489-
// We generate a patch where context is maximized so apply_diff has enough info to fuzzy match
490476
const patch = createTwoFilesPatch(
491477
'a',
492478
'b',

0 commit comments

Comments
 (0)