mirror of
https://github.com/voideditor/void
synced 2026-05-24 09:58:23 +00:00
fixing bugs
This commit is contained in:
parent
84d866205b
commit
878ec1e782
4 changed files with 33 additions and 24 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
import React, { FormEvent, useCallback, useRef, useState } from 'react';
|
import React, { FormEvent, useCallback, useRef, useState } from 'react';
|
||||||
|
|
||||||
|
|
||||||
import { useConfigState, useService, useSidebarState, useThreadsState } from '../util/services.js';
|
import { useConfigState, useService, useThreadsState } from '../util/services.js';
|
||||||
import { URI } from '../../../../../../../base/common/uri.js';
|
import { URI } from '../../../../../../../base/common/uri.js';
|
||||||
import { VSReadFile } from '../../../registerInlineDiffs.js';
|
import { VSReadFile } from '../../../registerInlineDiffs.js';
|
||||||
import { sendLLMMessage } from '../util/sendLLMMessage.js';
|
import { sendLLMMessage } from '../util/sendLLMMessage.js';
|
||||||
|
|
@ -128,6 +128,7 @@ export const SidebarChat = () => {
|
||||||
const { voidConfig } = configState
|
const { voidConfig } = configState
|
||||||
|
|
||||||
// threads state
|
// threads state
|
||||||
|
const threadsState = useThreadsState()
|
||||||
const threadsStateService = useService('threadsStateService')
|
const threadsStateService = useService('threadsStateService')
|
||||||
|
|
||||||
// ----- SIDEBAR CHAT state (local) -----
|
// ----- SIDEBAR CHAT state (local) -----
|
||||||
|
|
@ -180,7 +181,7 @@ export const SidebarChat = () => {
|
||||||
const newHistoryElt: ChatMessage = { role: 'user', content: userContent, displayContent: instructions, selection, files }
|
const newHistoryElt: ChatMessage = { role: 'user', content: userContent, displayContent: instructions, selection, files }
|
||||||
threadsStateService.addMessageToCurrentThread(newHistoryElt)
|
threadsStateService.addMessageToCurrentThread(newHistoryElt)
|
||||||
|
|
||||||
const currentThread = threadsStateService.getCurrentThread()
|
const currentThread = threadsStateService.getCurrentThread(threadsStateService.state) // the the instant state right now, don't wait for the React state
|
||||||
|
|
||||||
|
|
||||||
// send message to LLM
|
// send message to LLM
|
||||||
|
|
@ -229,7 +230,7 @@ export const SidebarChat = () => {
|
||||||
}, [messageStream, threadsStateService])
|
}, [messageStream, threadsStateService])
|
||||||
|
|
||||||
|
|
||||||
const currentThread = threadsStateService.getCurrentThread()
|
const currentThread = threadsStateService.getCurrentThread(threadsState)
|
||||||
return <>
|
return <>
|
||||||
<div className="overflow-x-hidden space-y-4">
|
<div className="overflow-x-hidden space-y-4">
|
||||||
{/* previous messages */}
|
{/* previous messages */}
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ export const SidebarThreadSelector = () => {
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
key={pastThread.id}
|
key={pastThread.id}
|
||||||
className={`btn btn-sm rounded-sm ${pastThread.id === threadsStateService.getCurrentThread()?.id ? "btn-primary" : "btn-secondary"}`}
|
className={`btn btn-sm rounded-sm ${pastThread.id === threadsStateService.getCurrentThread(threadsState)?.id ? "btn-primary" : "btn-secondary"}`}
|
||||||
onClick={() => threadsStateService.switchToThread(pastThread.id)}
|
onClick={() => threadsStateService.switchToThread(pastThread.id)}
|
||||||
title={new Date(pastThread.createdAt).toLocaleString()}
|
title={new Date(pastThread.createdAt).toLocaleString()}
|
||||||
>
|
>
|
||||||
|
|
|
||||||
|
|
@ -157,8 +157,7 @@ class InlineDiffsService extends Disposable implements IInlineDiffsService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}];
|
}];
|
||||||
const decorationIds = editor.deltaDecorations([], greenDecoration)
|
const decorationsCollection = editor.createDecorationsCollection(greenDecoration)
|
||||||
|
|
||||||
|
|
||||||
// red in a view zone
|
// red in a view zone
|
||||||
let zoneId: string | null = null
|
let zoneId: string | null = null
|
||||||
|
|
@ -212,7 +211,7 @@ class InlineDiffsService extends Disposable implements IInlineDiffsService {
|
||||||
|
|
||||||
|
|
||||||
const dispose = () => {
|
const dispose = () => {
|
||||||
editor.deltaDecorations(decorationIds, []);
|
decorationsCollection.clear()
|
||||||
editor.changeViewZones(accessor => {
|
editor.changeViewZones(accessor => {
|
||||||
if (zoneId) accessor.removeZone(zoneId);
|
if (zoneId) accessor.removeZone(zoneId);
|
||||||
});
|
});
|
||||||
|
|
@ -250,6 +249,16 @@ class InlineDiffsService extends Disposable implements IInlineDiffsService {
|
||||||
|
|
||||||
let afterSnapshot: HistorySnapshot | null = null
|
let afterSnapshot: HistorySnapshot | null = null
|
||||||
|
|
||||||
|
const replaceDiffAreas = (newDiffAreaOfId: typeof this.diffAreaOfId) => {
|
||||||
|
this.diffAreaOfId = structuredClone(newDiffAreaOfId)
|
||||||
|
this.diffAreasOfModelId[model.id].clear()
|
||||||
|
for (let diffareaid in beforeSnapshot.diffAreaOfId) {
|
||||||
|
this.diffAreasOfModelId[model.id].add(diffareaid)
|
||||||
|
}
|
||||||
|
this._refreshAllDiffsAndStyles(model)
|
||||||
|
this._refreshSweepStyles(model)
|
||||||
|
}
|
||||||
|
|
||||||
const elt: IUndoRedoElement = {
|
const elt: IUndoRedoElement = {
|
||||||
type: UndoRedoElementType.Resource,
|
type: UndoRedoElementType.Resource,
|
||||||
resource: uri,
|
resource: uri,
|
||||||
|
|
@ -258,16 +267,12 @@ class InlineDiffsService extends Disposable implements IInlineDiffsService {
|
||||||
// called when undoing this state
|
// called when undoing this state
|
||||||
undo: () => {
|
undo: () => {
|
||||||
// when the user undoes this element, revert to oldSnapshot
|
// when the user undoes this element, revert to oldSnapshot
|
||||||
this.diffAreaOfId = structuredClone(beforeSnapshot.diffAreaOfId)
|
replaceDiffAreas(beforeSnapshot.diffAreaOfId)
|
||||||
this._refreshAllDiffsAndStyles(model)
|
|
||||||
this._refreshSweepStyles(model)
|
|
||||||
},
|
},
|
||||||
// called when restoring this state
|
// called when restoring this state
|
||||||
redo: () => {
|
redo: () => {
|
||||||
if (afterSnapshot === null) return
|
if (afterSnapshot === null) return
|
||||||
this.diffAreaOfId = structuredClone(afterSnapshot.diffAreaOfId)
|
replaceDiffAreas(afterSnapshot.diffAreaOfId)
|
||||||
this._refreshAllDiffsAndStyles(model)
|
|
||||||
this._refreshSweepStyles(model)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const editGroup = new UndoRedoGroup()
|
const editGroup = new UndoRedoGroup()
|
||||||
|
|
@ -315,7 +320,7 @@ class InlineDiffsService extends Disposable implements IInlineDiffsService {
|
||||||
|
|
||||||
// ------------ recompute all diffs in each diffarea ------------
|
// ------------ recompute all diffs in each diffarea ------------
|
||||||
// for each diffArea
|
// for each diffArea
|
||||||
for (const diffareaid of this.diffAreasOfModelId[modelid] || new Set()) {
|
for (const diffareaid of this.diffAreasOfModelId[modelid]) {
|
||||||
|
|
||||||
const diffArea = this.diffAreaOfId[diffareaid]
|
const diffArea = this.diffAreaOfId[diffareaid]
|
||||||
|
|
||||||
|
|
@ -331,7 +336,7 @@ class InlineDiffsService extends Disposable implements IInlineDiffsService {
|
||||||
|
|
||||||
for (let computedDiff of computedDiffs) {
|
for (let computedDiff of computedDiffs) {
|
||||||
// add the view zone
|
// add the view zone
|
||||||
const greenRange: IRange = { startLineNumber: diffArea.startLine, startColumn: 0, endLineNumber: diffArea.endLine, endColumn: Number.MAX_SAFE_INTEGER, }
|
const greenRange: IRange = { startLineNumber: computedDiff.startLine, startColumn: 0, endLineNumber: computedDiff.endLine, endColumn: Number.MAX_SAFE_INTEGER, }
|
||||||
const dispose = this._addInlineDiffZone(model, computedDiff.originalCode, greenRange)
|
const dispose = this._addInlineDiffZone(model, computedDiff.originalCode, greenRange)
|
||||||
|
|
||||||
// create a Diff of it
|
// create a Diff of it
|
||||||
|
|
@ -590,7 +595,6 @@ class InlineDiffsService extends Disposable implements IInlineDiffsService {
|
||||||
_diffs: [], // added later
|
_diffs: [], // added later
|
||||||
}
|
}
|
||||||
|
|
||||||
// add `diffArea` to storage
|
|
||||||
this.diffAreasOfModelId[model.id].add(diffArea.diffareaid.toString())
|
this.diffAreasOfModelId[model.id].add(diffArea.diffareaid.toString())
|
||||||
this.diffAreaOfId[diffArea.diffareaid] = diffArea
|
this.diffAreaOfId[diffArea.diffareaid] = diffArea
|
||||||
|
|
||||||
|
|
@ -620,12 +624,12 @@ Please finish writing the new file by applying the diff to the original file. Re
|
||||||
],
|
],
|
||||||
onText: (newText: string, fullText: string) => {
|
onText: (newText: string, fullText: string) => {
|
||||||
this._updateDiffAreaText(diffArea, fullText, editGroup)
|
this._updateDiffAreaText(diffArea, fullText, editGroup)
|
||||||
this._refreshAllDiffsAndStyles(model)
|
// this._refreshAllDiffsAndStyles(model)
|
||||||
this._refreshSweepStyles(model)
|
this._refreshSweepStyles(model)
|
||||||
},
|
},
|
||||||
onFinalMessage: (fullText: string) => {
|
onFinalMessage: (fullText: string) => {
|
||||||
this._updateDiffAreaText(diffArea, fullText, editGroup)
|
this._updateDiffAreaText(diffArea, fullText, editGroup)
|
||||||
this._refreshAllDiffsAndStyles(model)
|
// this._refreshAllDiffsAndStyles(model)
|
||||||
this._refreshSweepStyles(model)
|
this._refreshSweepStyles(model)
|
||||||
resolve();
|
resolve();
|
||||||
},
|
},
|
||||||
|
|
@ -658,9 +662,11 @@ Please finish writing the new file by applying the diff to the original file. Re
|
||||||
const originalFileStr = await VSReadFile(this._fileService, model.uri)
|
const originalFileStr = await VSReadFile(this._fileService, model.uri)
|
||||||
if (originalFileStr === null) return
|
if (originalFileStr === null) return
|
||||||
this.originalFileStrOfModelId[model.id] = originalFileStr
|
this.originalFileStrOfModelId[model.id] = originalFileStr
|
||||||
this.streamingStateOfModelId[model.id] = { type: 'streaming' }
|
|
||||||
this.diffAreasOfModelId[model.id] = new Set()
|
|
||||||
|
|
||||||
|
if (!(model.id in this.diffAreasOfModelId))
|
||||||
|
this.diffAreasOfModelId[model.id] = new Set()
|
||||||
|
|
||||||
|
this.streamingStateOfModelId[model.id] = { type: 'streaming' }
|
||||||
|
|
||||||
// initialize stream
|
// initialize stream
|
||||||
await this._initializeStream(model, userMessage)
|
await this._initializeStream(model, userMessage)
|
||||||
|
|
@ -781,8 +787,9 @@ Please finish writing the new file by applying the diff to the original file. Re
|
||||||
this._deleteDiffArea(diffArea)
|
this._deleteDiffArea(diffArea)
|
||||||
}
|
}
|
||||||
const editor = this._editorService.getActiveCodeEditor()
|
const editor = this._editorService.getActiveCodeEditor()
|
||||||
if (editor?.getModel()?.id === modelid)
|
if (editor?.getModel()?.id === modelid) {
|
||||||
this._refreshAllDiffsAndStyles(model)
|
this._refreshAllDiffsAndStyles(model)
|
||||||
|
}
|
||||||
|
|
||||||
onFinishEdit()
|
onFinishEdit()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ export interface IThreadHistoryService {
|
||||||
readonly state: ThreadsState;
|
readonly state: ThreadsState;
|
||||||
onDidChangeCurrentThread: Event<void>;
|
onDidChangeCurrentThread: Event<void>;
|
||||||
|
|
||||||
getCurrentThread(): ChatThreads[string] | null;
|
getCurrentThread(state: ThreadsState): ChatThreads[string] | null;
|
||||||
startNewThread(): void;
|
startNewThread(): void;
|
||||||
switchToThread(threadId: string): void;
|
switchToThread(threadId: string): void;
|
||||||
startNewThread(): void;
|
startNewThread(): void;
|
||||||
|
|
@ -108,8 +108,9 @@ class ThreadHistoryService extends Disposable implements IThreadHistoryService {
|
||||||
if (affectsCurrent) this._onDidChangeCurrentThread.fire()
|
if (affectsCurrent) this._onDidChangeCurrentThread.fire()
|
||||||
}
|
}
|
||||||
|
|
||||||
getCurrentThread(): ChatThreads[string] | null {
|
// must "prove" that you have access to the current state by providing it
|
||||||
return this.state._currentThreadId ? this.state.allThreads[this.state._currentThreadId] ?? null : null;
|
getCurrentThread(state: ThreadsState): ChatThreads[string] | null {
|
||||||
|
return state._currentThreadId ? state.allThreads[state._currentThreadId] ?? null : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
switchToThread(threadId: string) {
|
switchToThread(threadId: string) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue