add throttling

This commit is contained in:
Andrew 2024-10-28 03:52:19 -07:00
parent eae1af331f
commit 6d12737fda
2 changed files with 8 additions and 5 deletions

View file

@ -2,8 +2,10 @@ import * as vscode from 'vscode';
import { findDiffs } from './findDiffs';
import { Diff, DiffArea, BaseDiff, } from './common/shared_types';
import { readFileContentOfUri } from './common/readFileContentOfUri';
import { throttle } from 'lodash';
const THROTTLE_TIME = 100
// TODO in theory this should be disposed
const greenDecoration = vscode.window.createTextEditorDecorationType({
@ -377,7 +379,7 @@ export class DiffProvider implements vscode.CodeLensProvider {
// used by us only
public async updateStream(docUriStr: string, diffArea: DiffArea, newDiffAreaCode: string) {
public updateStream = throttle(async (docUriStr: string, diffArea: DiffArea, newDiffAreaCode: string) => {
const editor = vscode.window.activeTextEditor // TODO the editor should be that of `docUri` and not necessarily the current editor
if (!editor) {
@ -432,12 +434,13 @@ export class DiffProvider implements vscode.CodeLensProvider {
const diffareaRange = new vscode.Range(diffArea.startLine, 0, diffArea.endLine, Number.MAX_SAFE_INTEGER)
workspaceEdit.replace(editor.document.uri, diffareaRange, newCode)
await vscode.workspace.applyEdit(workspaceEdit)
}
}, THROTTLE_TIME)
}
/*
import * as vscode from 'vscode';
import { SuggestedEdit } from './findDiffs';

View file

@ -1,5 +1,5 @@
import * as vscode from 'vscode';
import { OnFinalMessage, OnText, sendLLMMessage, SetAbort } from "./sendLLMMessage"
import { AbortRef, OnFinalMessage, OnText, sendLLMMessage } from "./sendLLMMessage"
import { VoidConfig } from '../sidebar/contextForConfig';
import { findDiffs } from '../findDiffs';
import { searchDiffChunkInstructions, writeFileWithDiffInstructions } from './systemPrompts';
@ -31,7 +31,7 @@ const applyCtrlLChangesToFile = throttle(
)
const applyCtrlK = async ({ fileUri, startLine, endLine, instructions, voidConfig, setAbort }: { fileUri: vscode.Uri, startLine: number, endLine: number, instructions: string, voidConfig: VoidConfig, setAbort: SetAbort }) => {
const applyCtrlK = async ({ fileUri, startLine, endLine, instructions, voidConfig, abortRef }: { fileUri: vscode.Uri, startLine: number, endLine: number, instructions: string, voidConfig: VoidConfig, abortRef: AbortRef }) => {
const fileStr = await readFileContentOfUri(fileUri)
const fileLines = fileStr.split('\n')
@ -91,7 +91,7 @@ Complete the following:
console.error('Error rewriting file with diff', e);
},
voidConfig,
setAbort,
abortRef,
})
}