Skip to content

Commit ddacc2e

Browse files
committed
add early returns
1 parent 2aa51a4 commit ddacc2e

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

packages/amazonq/src/lsp/chat/diffAnimation/streamingDiffController.ts

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -221,32 +221,35 @@ export class StreamingDiffController implements vscode.Disposable {
221221
}
222222
session.streamedLines = accumulatedLines
223223

224-
if (isFinal) {
225-
if (session.streamedLines.length < document.lineCount) {
226-
const edit = new vscode.WorkspaceEdit()
227-
edit.delete(document.uri, new vscode.Range(session.streamedLines.length, 0, document.lineCount, 0))
228-
await vscode.workspace.applyEdit(edit)
229-
}
230-
231-
try {
232-
await document.save()
233-
} catch (saveError) {
234-
getLogger().error(`Failed to save temp file ${session.tempFilePath}: ${saveError}`)
235-
}
224+
if (!isFinal) {
225+
return
226+
}
236227

237-
session.fadedOverlayController.clear()
238-
session.activeLineController.clear()
228+
// Final cleanup when streaming is complete
229+
if (session.streamedLines.length < document.lineCount) {
230+
const edit = new vscode.WorkspaceEdit()
231+
edit.delete(document.uri, new vscode.Range(session.streamedLines.length, 0, document.lineCount, 0))
232+
await vscode.workspace.applyEdit(edit)
233+
}
239234

240-
setTimeout(async () => {
241-
try {
242-
await this.cleanupTempFile(session.tempFilePath)
243-
session.disposed = true
244-
this.activeStreamingSessions.delete(toolUseId)
245-
} catch (error) {
246-
getLogger().warn(`Failed to auto-cleanup temp file ${session.tempFilePath}: ${error}`)
247-
}
248-
}, 500)
235+
try {
236+
await document.save()
237+
} catch (saveError) {
238+
getLogger().error(`Failed to save temp file ${session.tempFilePath}: ${saveError}`)
249239
}
240+
241+
session.fadedOverlayController.clear()
242+
session.activeLineController.clear()
243+
244+
setTimeout(async () => {
245+
try {
246+
await this.cleanupTempFile(session.tempFilePath)
247+
session.disposed = true
248+
this.activeStreamingSessions.delete(toolUseId)
249+
} catch (error) {
250+
getLogger().warn(`Failed to auto-cleanup temp file ${session.tempFilePath}: ${error}`)
251+
}
252+
}, 500)
250253
} catch (error) {
251254
getLogger().error(
252255
`[StreamingDiffController] ❌ Failed to stream animation update for ${toolUseId}: ${error}`
@@ -334,9 +337,10 @@ export class StreamingDiffController implements vscode.Disposable {
334337
`[StreamingDiffController] ❌ Failed to save fsReplace diffPair temp file: ${saveError}`
335338
)
336339
}
337-
if (isFinal) {
338-
await this.handleFsReplaceCompletion(session, pairIndex || 0, totalPairs || 1)
340+
if (!isFinal) {
341+
return
339342
}
343+
await this.handleFsReplaceCompletion(session, pairIndex || 0, totalPairs || 1)
340344
} catch (error) {
341345
getLogger().error(`[StreamingDiffController] ❌ Failed to handle fsReplace diffPair: ${error}`)
342346
}

0 commit comments

Comments
 (0)