From 06688228ae934082d0f61cf7c8e955c3e58fbdbd Mon Sep 17 00:00:00 2001 From: Andrew Pareles Date: Sun, 12 Jan 2025 18:57:28 -0800 Subject: [PATCH] notif details --- .../platform/void/common/llmMessageService.ts | 1 + .../platform/void/common/llmMessageTypes.ts | 13 ++++++++ .../void/browser/inlineDiffsService.ts | 31 +++++++++++++------ .../react/src/sidebar-tsx/ErrorDisplay.tsx | 13 ++------ 4 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/vs/platform/void/common/llmMessageService.ts b/src/vs/platform/void/common/llmMessageService.ts index 9cd97573..9fd039c6 100644 --- a/src/vs/platform/void/common/llmMessageService.ts +++ b/src/vs/platform/void/common/llmMessageService.ts @@ -52,6 +52,7 @@ export class LLMMessageService extends Disposable implements ILLMMessageService super() // const service = ProxyChannel.toService(mainProcessService.getChannel('void-channel-sendLLMMessage')); // lets you call it like a service + // see llmMessageChannel.ts this.channel = this.mainProcessService.getChannel('void-channel-llmMessageService') // .listen sets up an IPC channel and takes a few ms, so we set up listeners immediately and add hooks to them instead diff --git a/src/vs/platform/void/common/llmMessageTypes.ts b/src/vs/platform/void/common/llmMessageTypes.ts index 0509aa37..db560ab9 100644 --- a/src/vs/platform/void/common/llmMessageTypes.ts +++ b/src/vs/platform/void/common/llmMessageTypes.ts @@ -7,6 +7,19 @@ import { IRange } from '../../../editor/common/core/range' import { ProviderName, SettingsOfProvider } from './voidSettingsTypes.js' +export const errorDetails = (fullError: Error | null): string | null => { + if (fullError === null) { + return null + } + else if (typeof fullError === 'object') { + return JSON.stringify(fullError, null, 2) + } + else if (typeof fullError === 'string') { + return null + } + return null +} + export type OnText = (p: { newText: string, fullText: string }) => void export type OnFinalMessage = (p: { fullText: string }) => void export type OnError = (p: { message: string, fullError: Error | null }) => void diff --git a/src/vs/workbench/contrib/void/browser/inlineDiffsService.ts b/src/vs/workbench/contrib/void/browser/inlineDiffsService.ts index f32d37cd..d4dea3e4 100644 --- a/src/vs/workbench/contrib/void/browser/inlineDiffsService.ts +++ b/src/vs/workbench/contrib/void/browser/inlineDiffsService.ts @@ -33,7 +33,7 @@ import { ILLMMessageService } from '../../../../platform/void/common/llmMessageS import { mountCtrlK } from '../browser/react/out/quick-edit-tsx/index.js' import { QuickEditPropsType } from './quickEditActions.js'; import { InputBox } from '../../../../base/browser/ui/inputbox/inputBox.js'; -import { LLMMessage } from '../../../../platform/void/common/llmMessageTypes.js'; +import { errorDetails, LLMMessage } from '../../../../platform/void/common/llmMessageTypes.js'; import { IModelContentChangedEvent } from '../../../../editor/common/textModelEvents.js'; import { extractCodeFromFIM, extractCodeFromRegular } from './helpers/extractCodeFromResult.js'; import { IMetricsService } from '../../../../platform/void/common/metricsService.js'; @@ -43,6 +43,7 @@ import { BaseEditorSimpleWorker } from '../../../../editor/common/services/edito import { Action2, registerAction2 } from '../../../../platform/actions/common/actions.js'; import { ServicesAccessor } from '../../../../editor/browser/editorExtensions.js'; import { localize2 } from '../../../../nls.js'; +import { INotificationService, Severity } from '../../../../platform/notification/common/notification.js'; const configOfBG = (color: Color) => { return { dark: color, light: color, hcDark: color, hcLight: color, } @@ -207,6 +208,7 @@ class InlineDiffsService extends Disposable implements IInlineDiffsService { @IInstantiationService private readonly _instantiationService: IInstantiationService, @IConsistentEditorItemService private readonly _consistentEditorItemService: IConsistentEditorItemService, @IMetricsService private readonly _metricsService: IMetricsService, + @INotificationService private readonly _notificationService: INotificationService, ) { super(); @@ -1119,16 +1121,19 @@ class InlineDiffsService extends Disposable implements IInlineDiffsService { else { throw new Error(`featureName ${featureName} is invalid`) } - const onDone = () => { + const onDone = (hadError: boolean) => { diffZone._streamState = { isStreaming: false, } - if (featureName === 'Ctrl+K') { const ctrlKZone = this.diffAreaOfId[opts.diffareaid] as CtrlKZone this._deleteCtrlKZone(ctrlKZone) } this._refreshStylesAndDiffsInURI(uri) - onFinishEdit() + + // if had error, revert! + if (hadError) { + this._undoHistory(diffZone._URI) + } } // refresh now in case onText takes a while to get 1st message @@ -1161,14 +1166,17 @@ class InlineDiffsService extends Disposable implements IInlineDiffsService { { startLineNumber: diffZone.startLine, startColumn: 1, endLineNumber: diffZone.endLine, endColumn: Number.MAX_SAFE_INTEGER }, // 1-indexed { shouldRealignDiffAreas: true } ) - onDone() + onDone(false) }, onError: (e) => { console.error('Error rewriting file with diff', e); - // TODO indicate there was an error - if (streamRequestIdRef.current) - this._llmMessageService.abort(streamRequestIdRef.current) - onDone() + const details = errorDetails(e.fullError) + this._notificationService.notify({ + severity: Severity.Warning, + message: `Void Error: ${e.message}`, + source: details ?? undefined + }) + onDone(true) }, range: { startLineNumber: startLine, endLineNumber: endLine, startColumn: 1, endColumn: Number.MAX_SAFE_INTEGER }, @@ -1232,6 +1240,9 @@ if (x > 0) { } + _undoHistory(uri: URI) { + this._undoRedoService.undo(uri) + } // call this outside undo/redo (it calls undo). this is only for aborting a diffzone stream interruptStreaming(diffareaid: number) { @@ -1242,7 +1253,7 @@ if (x > 0) { if (!diffArea._streamState.isStreaming) return this._stopIfStreaming(diffArea) - this._undoRedoService.undo(diffArea._URI) + this._undoHistory(diffArea._URI) } diff --git a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/ErrorDisplay.tsx b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/ErrorDisplay.tsx index 811804ed..f10cd035 100644 --- a/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/ErrorDisplay.tsx +++ b/src/vs/workbench/contrib/void/browser/react/src/sidebar-tsx/ErrorDisplay.tsx @@ -5,6 +5,7 @@ import React, { useState } from 'react'; import { AlertCircle, ChevronDown, ChevronUp, X } from 'lucide-react'; +import { errorDetails } from '../../../../../../../platform/void/common/llmMessageTypes.js'; export const ErrorDisplay = ({ @@ -20,17 +21,7 @@ export const ErrorDisplay = ({ }) => { const [isExpanded, setIsExpanded] = useState(false); - let details: string | null = null; - - if (fullError === null) { - details = null - } - else if (typeof fullError === 'object') { - details = JSON.stringify(fullError, null, 2) - } - else if (typeof fullError === 'string') { - details = null - } + const details = errorDetails(fullError) return (