From c889acadc0aaabc0b1846f81ad7d3258b1c8028f Mon Sep 17 00:00:00 2001 From: Andrew Pareles Date: Fri, 21 Mar 2025 06:44:04 -0700 Subject: [PATCH] interruption handling --- .../workbench/contrib/void/browser/editCodeService.ts | 11 ++--------- .../react/src/markdown/ApplyBlockHoverButtons.tsx | 2 ++ .../react/src/quick-edit-tsx/QuickEditChat.tsx | 10 +++++++--- .../browser/react/src/sidebar-tsx/SidebarChat.tsx | 2 +- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/vs/workbench/contrib/void/browser/editCodeService.ts b/src/vs/workbench/contrib/void/browser/editCodeService.ts index abb0bf24..8a589aa0 100644 --- a/src/vs/workbench/contrib/void/browser/editCodeService.ts +++ b/src/vs/workbench/contrib/void/browser/editCodeService.ts @@ -1245,18 +1245,11 @@ class EditCodeService extends Disposable implements IEditCodeService { // ctrlkzone should never have any conflicts } else { - // console.log('KEEPING CONFLICTS!!!!!!!!') // keep conflict on whole file - to keep conflict, revert the change and use those contents as original, then un-revert the file - // console.log('originalFile', originalFileStr) - // console.log('diffareas A', JSON.stringify(this.diffAreasOfURI, null, 2)) this.acceptOrRejectAllDiffAreas({ uri, removeCtrlKs: true, behavior: 'reject', _addToHistory: false }) - // console.log('diffareas B', JSON.stringify(this.diffAreasOfURI, null, 2)) const oldFileStr = model.getValue(EndOfLinePreference.LF) // use this as original code - // console.log('oldFileStr', { oldFileStr }) this._writeURIText(uri, originalFileStr, 'wholeFileRange', { shouldRealignDiffAreas: true }) // un-revert originalCode = oldFileStr - // console.log('originalCode', { originalCode }) - // console.log('NEW STR', { newStr: model.getValue(EndOfLinePreference.LF) }) } } @@ -1498,7 +1491,7 @@ class EditCodeService extends Disposable implements IEditCodeService { } // end while } // end writeover - const applyDonePromise = runWriteover() + const applyDonePromise = new Promise((res, rej) => { runWriteover().then(res).catch(rej) }) return [diffZone, applyDonePromise] } @@ -1865,7 +1858,7 @@ class EditCodeService extends Disposable implements IEditCodeService { } // end retryLoop - const applyDonePromise = runSearchReplace() + const applyDonePromise = new Promise((res, rej) => { runSearchReplace().then(res).catch(rej) }) return [diffZone, applyDonePromise] } diff --git a/src/vs/workbench/contrib/void/browser/react/src/markdown/ApplyBlockHoverButtons.tsx b/src/vs/workbench/contrib/void/browser/react/src/markdown/ApplyBlockHoverButtons.tsx index 0927ab5f..b37f4c69 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/markdown/ApplyBlockHoverButtons.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/markdown/ApplyBlockHoverButtons.tsx @@ -165,6 +165,8 @@ export const useApplyButtonHTML = ({ codeStr, applyBoxId, uri }: { codeStr: stri uri: uri, startBehavior: 'keep-conflicts', }) ?? [] + // catch any errors by interrupting the stream + applyDonePromise?.catch(e => { if (newApplyingUri) editCodeService.interruptURIStreaming({ uri: newApplyingUri }) }) applyingURIOfApplyBoxIdRef.current[applyBoxId] = newApplyingUri ?? undefined diff --git a/src/vs/workbench/contrib/void/browser/react/src/quick-edit-tsx/QuickEditChat.tsx b/src/vs/workbench/contrib/void/browser/react/src/quick-edit-tsx/QuickEditChat.tsx index d6ed8605..42e9b81b 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/quick-edit-tsx/QuickEditChat.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/quick-edit-tsx/QuickEditChat.tsx @@ -58,16 +58,20 @@ export const QuickEditChat = ({ className="@@codicon @@codicon-loading @@codicon-modifier-spin @@codicon-no-default-spin text-void-fg-3" /> - const onSubmit = useCallback(() => { + const onSubmit = useCallback(async () => { if (isDisabled) return if (isStreamingRef.current) return textAreaFnsRef.current?.disable() - const res = editCodeService.startApplying({ + const [newApplyingUri, applyDonePromise] = await editCodeService.startApplying({ from: 'QuickEdit', diffareaid, startBehavior: 'keep-conflicts', - }) + }) ?? [] + // catch any errors by interrupting the stream + applyDonePromise?.catch(e => { if (newApplyingUri) editCodeService.interruptCtrlKStreaming({ diffareaid }) }) + + }, [isStreamingRef, isDisabled, editCodeService, diffareaid]) const onInterrupt = useCallback(() => { diff --git a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx index b7fa8c45..c00cb058 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/SidebarChat.tsx @@ -1946,7 +1946,7 @@ export const SidebarChat = () => { const proposed = toolNameSoFar && toolNames.includes(toolNameSoFar as ToolName) ? titleOfToolName[toolNameSoFar as ToolName]?.proposed : toolNameSoFar const toolTitle = typeof proposed === 'function' ? proposed(null) : proposed const currStreamingToolHTML = toolIsLoading ? - } /> + writing} /> : null const allMessagesHTML = [...previousMessagesHTML, currStreamingMessageHTML, currStreamingToolHTML]