From 83f9ff54aba5c1747daae5cd94c3271e550459a6 Mon Sep 17 00:00:00 2001 From: Andrew Pareles Date: Mon, 3 Mar 2025 23:35:36 -0800 Subject: [PATCH] update --- .../contrib/void/browser/editCodeService.ts | 44 ++++++++++++------- .../void/browser/editCodeServiceInterface.ts | 11 +++-- .../react/src/sidebar-tsx/SidebarChat.tsx | 9 ++-- .../contrib/void/browser/toolsService.ts | 6 +-- 4 files changed, 40 insertions(+), 30 deletions(-) diff --git a/src/vs/workbench/contrib/void/browser/editCodeService.ts b/src/vs/workbench/contrib/void/browser/editCodeService.ts index 019b7887..9b55b75e 100644 --- a/src/vs/workbench/contrib/void/browser/editCodeService.ts +++ b/src/vs/workbench/contrib/void/browser/editCodeService.ts @@ -773,7 +773,7 @@ class EditCodeService extends Disposable implements IEditCodeService { - private _addToHistory(uri: URI) { + private _addToHistory(uri: URI, opts?: { onUndo?: () => void }) { const getCurrentSnapshot = (): HistorySnapshot => { const snapshottedDiffAreaOfId: Record = {} @@ -855,7 +855,7 @@ class EditCodeService extends Disposable implements IEditCodeService { resource: uri, label: 'Void Changes', code: 'undoredo.editCode', - undo: () => { restoreDiffAreas(beforeSnapshot) }, + undo: () => { restoreDiffAreas(beforeSnapshot); opts?.onUndo?.() }, redo: () => { if (afterSnapshot) restoreDiffAreas(afterSnapshot) } } this._undoRedoService.pushElement(elt) @@ -1223,7 +1223,7 @@ class EditCodeService extends Disposable implements IEditCodeService { private _initializeWriteoverStream(opts: StartApplyingOpts): DiffZone | undefined { - const { from } = opts + const { from, onFinalMessage: onFinalMessage_, onError: onError_, } = opts let startLine: number let endLine: number @@ -1268,7 +1268,9 @@ class EditCodeService extends Disposable implements IEditCodeService { // add to history - const { onFinishEdit } = this._addToHistory(uri) + const { onFinishEdit } = this._addToHistory(uri, { + onUndo: () => { onError_?.({ message: 'Edit was interrupted by pressing undo.', fullError: null }) } + }) // __TODO__ let users customize modelFimTags const quickEditFIMTags = defaultQuickEditFimTags @@ -1369,7 +1371,8 @@ class EditCodeService extends Disposable implements IEditCodeService { useProviderFor: opts.from === 'ClickApply' ? 'Apply' : 'Ctrl+K', logging: { loggingName: `startApplying - ${from}` }, messages, - onText: ({ fullText: fullText_ }) => { + onText: (params) => { + const { fullText: fullText_ } = params const newText_ = fullText_.substring(fullTextSoFar.length, Infinity) const newText = prevIgnoredSuffix + newText_ // add the previously ignored suffix because it's no longer the suffix! @@ -1383,7 +1386,8 @@ class EditCodeService extends Disposable implements IEditCodeService { prevIgnoredSuffix = croppedSuffix }, - onFinalMessage: ({ fullText }) => { + onFinalMessage: (params) => { + const { fullText } = params // console.log('DONE! FULL TEXT\n', extractText(fullText), diffZone.startLine, diffZone.endLine) // at the end, re-write whole thing to make sure no sync errors const [croppedText, _1, _2] = extractText(fullText, 0) @@ -1392,11 +1396,13 @@ class EditCodeService extends Disposable implements IEditCodeService { { shouldRealignDiffAreas: true } ) onDone() + onFinalMessage_?.() }, onError: (e) => { this._notifyError(e) onDone() this._undoHistory(uri) + onError_?.(e) }, }) @@ -1409,7 +1415,7 @@ class EditCodeService extends Disposable implements IEditCodeService { private _initializeSearchAndReplaceStream(opts: StartApplyingOpts & { from: 'ClickApply' }) { - const { applyStr, uri: givenURI, onText: onText_, onFinalMessage: onFinalMessage_, onError: onError_, } = opts + const { applyStr, uri: givenURI, onFinalMessage: onFinalMessage_, onError: onError_, } = opts let uri: URI if (givenURI === 'current') { @@ -1444,7 +1450,19 @@ class EditCodeService extends Disposable implements IEditCodeService { // can use this as a proxy to set the diffArea's stream state requestId let streamRequestIdRef: { current: string | null } = { current: null } - let { onFinishEdit } = this._addToHistory(uri) + const getOnFinishEdit = () => { + const { onFinishEdit } = this._addToHistory(uri, { + onUndo: () => { onError_?.({ message: 'Edit was interrupted by pressing undo.', fullError: null }) } + }) + return onFinishEdit + } + const revertAndContinueHistory = () => { + this._undoHistory(uri) + onFinishEdit = getOnFinishEdit() + } + + + let onFinishEdit = getOnFinishEdit() // TODO replace these with whatever block we're on initially if already started @@ -1474,12 +1492,6 @@ class EditCodeService extends Disposable implements IEditCodeService { this._onDidAddOrDeleteDiffZones.fire({ uri }) - const revertAndContinueHistory = () => { - this._undoHistory(uri) - const { onFinishEdit: onFinishEdit_ } = this._addToHistory(uri) - onFinishEdit = onFinishEdit_ - } - const convertOriginalRangeToFinalRange = (originalRange: readonly [number, number]): [number, number] => { // adjust based on the changes by computing line offset @@ -1638,8 +1650,6 @@ class EditCodeService extends Disposable implements IEditCodeService { } // end for this._refreshStylesAndDiffsInURI(uri) - - onText_?.(params) }, onFinalMessage: async (params) => { const { fullText } = params @@ -1679,7 +1689,7 @@ class EditCodeService extends Disposable implements IEditCodeService { onDone() - onFinalMessage_?.(params) + onFinalMessage_?.() }, onError: (e) => { this._notifyError(e) diff --git a/src/vs/workbench/contrib/void/browser/editCodeServiceInterface.ts b/src/vs/workbench/contrib/void/browser/editCodeServiceInterface.ts index 1d900ce7..2ea419be 100644 --- a/src/vs/workbench/contrib/void/browser/editCodeServiceInterface.ts +++ b/src/vs/workbench/contrib/void/browser/editCodeServiceInterface.ts @@ -7,12 +7,12 @@ import { Event } from '../../../../base/common/event.js'; import { URI } from '../../../../base/common/uri.js'; import { ICodeEditor } from '../../../../editor/browser/editorBrowser.js'; import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js'; -import { OnError, OnFinalMessage, OnText } from '../common/llmMessageTypes.js'; +import { OnError } from '../common/llmMessageTypes.js'; -export type StartApplyingOpts = { +export type StartApplyingOpts = ({ from: 'QuickEdit'; type: 'rewrite'; diffareaid: number; // id of the CtrlK area (contains text selection) @@ -21,11 +21,10 @@ export type StartApplyingOpts = { type: 'searchReplace' | 'rewrite'; applyStr: string; uri: 'current' | URI; - - onText?: OnText; - onFinalMessage?: OnFinalMessage; +}) & ({ + onFinalMessage?: () => void; onError?: OnError; -} +}) 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 23b14dc2..1feeee03 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 @@ -767,7 +767,6 @@ const toolResultToComponent: { [T in ToolName]: (props: { message: ToolMessage { commandService.executeCommand('vscode.open', params.uri, { preview: true }) }} >
-
{chatThreadsService.approveTool(chatMessage.voidToolId)}}>Accept
-
{chatThreadsService.rejectTool(chatMessage.voidToolId)}}>Reject
+ {JSON.stringify(chatMessage.name, null, 2)}
+ {JSON.stringify(chatMessage.params, null, 2)} +
{ chatThreadsService.approveTool(chatMessage.voidToolId) }}>Accept
+
{ chatThreadsService.rejectTool(chatMessage.voidToolId) }}>Reject
} diff --git a/src/vs/workbench/contrib/void/browser/toolsService.ts b/src/vs/workbench/contrib/void/browser/toolsService.ts index b78d0ed5..4e7deb30 100644 --- a/src/vs/workbench/contrib/void/browser/toolsService.ts +++ b/src/vs/workbench/contrib/void/browser/toolsService.ts @@ -449,13 +449,13 @@ export class ToolsService implements IToolsService { }, edit: async ({ uri, changeDescription }) => { - const p = new Promise((res, rej) => { + const p = new Promise((res, rej) => { editCodeService.startApplying({ uri, applyStr: changeDescription, from: 'ClickApply', - type: 'rewrite', - onFinalMessage: (p) => { res(p) }, + type: 'searchReplace', + onFinalMessage: () => { res() }, onError: (e) => { throw new Error(e.message) }, }) })