mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58:23 +00:00
update
This commit is contained in:
parent
1259e71589
commit
83f9ff54ab
4 changed files with 40 additions and 30 deletions
|
|
@ -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<string, DiffAreaSnapshot> = {}
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -767,7 +767,6 @@ const toolResultToComponent: { [T in ToolName]: (props: { message: ToolMessage<T
|
|||
<ToolResult
|
||||
toolName='delete_uri'
|
||||
actionParam={getBasename(params.uri.fsPath) + ' (deleted)'}
|
||||
onClick={() => { commandService.executeCommand('vscode.open', params.uri, { preview: true }) }}
|
||||
>
|
||||
<div className="text-void-fg-4 px-2 py-1 bg-black bg-opacity-20 border border-void-border-4 border-opacity-50 rounded-sm">
|
||||
<div
|
||||
|
|
@ -1034,10 +1033,12 @@ const ChatBubble = ({ chatMessage, isLoading, messageIdx }: { chatMessage: ChatM
|
|||
console.log('tool result:', chatMessage.name, chatMessage.paramsStr, chatMessage.result)
|
||||
|
||||
}
|
||||
else if (role === 'tool_request'){
|
||||
else if (role === 'tool_request') {
|
||||
chatbubbleContents = <>
|
||||
<div className='text-void-fg-4 italic' onClick={() => {chatThreadsService.approveTool(chatMessage.voidToolId)}}>Accept</div>
|
||||
<div className='text-void-fg-4 italic' onClick={() => {chatThreadsService.rejectTool(chatMessage.voidToolId)}}>Reject</div>
|
||||
{JSON.stringify(chatMessage.name, null, 2)} <br />
|
||||
{JSON.stringify(chatMessage.params, null, 2)}
|
||||
<div className='text-void-fg-4 italic' onClick={() => { chatThreadsService.approveTool(chatMessage.voidToolId) }}>Accept</div>
|
||||
<div className='text-void-fg-4 italic' onClick={() => { chatThreadsService.rejectTool(chatMessage.voidToolId) }}>Reject</div>
|
||||
</>
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -449,13 +449,13 @@ export class ToolsService implements IToolsService {
|
|||
},
|
||||
|
||||
edit: async ({ uri, changeDescription }) => {
|
||||
const p = new Promise((res, rej) => {
|
||||
const p = new Promise<void>((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) },
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue