From 6e8498414c98393c6470d3efe943aa712dbe136c Mon Sep 17 00:00:00 2001 From: Andrew Pareles Date: Sun, 12 Jan 2025 03:49:35 -0800 Subject: [PATCH] add ability to test diffs --- .../void/browser/inlineDiffsService.ts | 47 ++++++++++++++++++- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/contrib/void/browser/inlineDiffsService.ts b/src/vs/workbench/contrib/void/browser/inlineDiffsService.ts index be7f075f..dabf64af 100644 --- a/src/vs/workbench/contrib/void/browser/inlineDiffsService.ts +++ b/src/vs/workbench/contrib/void/browser/inlineDiffsService.ts @@ -42,6 +42,7 @@ import { filenameToVscodeLanguage } from './helpers/detectLanguage.js'; import { BaseEditorSimpleWorker } from '../../../../editor/common/services/editorSimpleWorker.js'; import { Action2, registerAction2 } from '../../../../platform/actions/common/actions.js'; import { ServicesAccessor } from '../../../../editor/browser/editorExtensions.js'; +import { localize2 } from '../../../../nls.js'; const configOfBG = (color: Color) => { return { dark: color, light: color, hcDark: color, hcLight: color, } @@ -178,6 +179,8 @@ export interface IInlineDiffsService { interruptStreaming(diffareaid: number): void; addCtrlKZone(opts: AddCtrlKOpts): number | undefined; removeCtrlKZone(opts: { diffareaid: number }): void; + + testDiffs(): void; } export const IInlineDiffsService = createDecorator('inlineDiffAreasService'); @@ -1176,6 +1179,45 @@ class InlineDiffsService extends Disposable implements IInlineDiffsService { } + testDiffs(): DiffZone | undefined { + const uri = this._getActiveEditorURI() + if (!uri) return + + const startLine = 1 + const endLine = 4 + + const currentFileStr = this._readURI(uri) + if (currentFileStr === null) return + const originalCode = currentFileStr.split('\n').slice((startLine - 1), (endLine - 1) + 1).join('\n') + + const { onFinishEdit } = this._addToHistory(uri) + const adding: Omit = { + type: 'DiffZone', + originalCode, + startLine, + endLine, + _URI: uri, + _streamState: { isStreaming: false, }, + _diffOfId: {}, // added later + _removeStylesFns: new Set(), + } + const diffZone = this._addDiffArea(adding) + const endResult = `\ +const x = 1; +if (x > 0) { + console.log('hi!') +}` + this._writeText(uri, endResult, + { startLineNumber: diffZone.startLine, startColumn: 1, endLineNumber: diffZone.endLine, endColumn: Number.MAX_SAFE_INTEGER }, // 1-indexed + { shouldRealignDiffAreas: true } + ) + diffZone._streamState = { isStreaming: false, } + this._refreshStylesAndDiffsInURI(uri) + onFinishEdit() + + return diffZone + } + private _stopIfStreaming(diffZone: DiffZone) { @@ -1511,12 +1553,13 @@ registerAction2(class extends Action2 { constructor() { super({ id: 'void.testDiff', - title: 'Void Test Diff', + title: localize2('voidTestDiff', 'Void Test Diff'), + f1: true, }); } async run(accessor: ServicesAccessor): Promise { const inlineDiffsService = accessor.get(IInlineDiffsService) - inlineDiffsService.startApplying + inlineDiffsService.testDiffs() } })