Fixed issues

This commit is contained in:
2026-02-08 18:13:15 +01:00
parent 7983775492
commit 2622651dc3
+28 -8
View File
@@ -6,6 +6,24 @@ export function startMonitoring(runId: string) {
let moveId = 0; let moveId = 0;
let moves: LiveRunMove[] = []; let moves: LiveRunMove[] = [];
let lastLatency = Date.now(); let lastLatency = Date.now();
let idleTimeout: NodeJS.Timeout | undefined;
let isSending = false;
const SEND_IDLE_MS = 350;
const flushMoves = async () => {
if (!moves.length || isSending) return;
isSending = true;
const toSend = moves;
moves = [];
try {
await addRunMoves(runId, toSend);
} finally {
isSending = false;
}
};
const docSub = vscode.workspace.onDidChangeTextDocument((e) => { const docSub = vscode.workspace.onDidChangeTextDocument((e) => {
const editor = vscode.window.activeTextEditor; const editor = vscode.window.activeTextEditor;
@@ -15,7 +33,7 @@ export function startMonitoring(runId: string) {
if (!edit) return; if (!edit) return;
const now = Date.now(); const now = Date.now();
const latency = capToZeroAbove(now - lastLatency, 350); const latency = capToZeroAbove(now - lastLatency, SEND_IDLE_MS);
lastLatency = now; lastLatency = now;
const cursorOffset = editor.document.offsetAt(editor.selection.active); const cursorOffset = editor.document.offsetAt(editor.selection.active);
@@ -30,18 +48,20 @@ export function startMonitoring(runId: string) {
}, },
moveId: moveId++, moveId: moveId++,
}); });
});
const sendInterval = setInterval(() => { if (idleTimeout) {
if (moves.length) { clearTimeout(idleTimeout);
addRunMoves(runId, moves);
moves = [];
} }
}, 3000);
idleTimeout = setTimeout(() => {
flushMoves();
}, SEND_IDLE_MS);
});
return () => { return () => {
docSub.dispose(); docSub.dispose();
clearInterval(sendInterval); if (idleTimeout) clearTimeout(idleTimeout);
flushMoves();
}; };
} }