From f2c74a1cf91a0196d526620d3ceda947d4b09373 Mon Sep 17 00:00:00 2001 From: liurenfeng94-ops <279598012+liurenfeng94-ops@users.noreply.github.com> Date: Tue, 28 Jul 2026 21:11:04 +0800 Subject: [PATCH] Auto-refresh trace files from disk --- src/appState.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/appState.ts b/src/appState.ts index b37c324..02b1d0e 100644 --- a/src/appState.ts +++ b/src/appState.ts @@ -1,8 +1,9 @@ import { mkdirSync, readdirSync, statSync } from 'node:fs' import { basename, dirname, join, relative } from 'node:path' import { log } from 'node:console' +import { debounce } from 'perfect-debounce' import { type Ref, type ShallowRef, type UnwrapRef, nextTick, watch as plainWatch, ref, shallowRef } from '@vue/runtime-core' -import type * as vscode from 'vscode' +import * as vscode from 'vscode' import type { TraceData } from '../shared/src/traceData' import { getTracePanel, isTraceViewAlive, postMessage } from './webview' import { getProjectName, getWorkspacePath } from './storage' @@ -43,6 +44,12 @@ type StateType = State[K] extends Ref ? UnwrapRef { + if (tracePath.value) + await sendTraceDir(tracePath.value) +}, 500) + export async function initAppState(extensionContext: vscode.ExtensionContext) { context = extensionContext storagePath = context.globalStorageUri.fsPath @@ -101,6 +108,12 @@ export async function initAppState(extensionContext: vscode.ExtensionContext) { return mkdirSync(path, { recursive: true }) + tracePathWatcher?.dispose() + tracePathWatcher = vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(path, '*.json')) + tracePathWatcher.onDidCreate(refreshTraceDir) + tracePathWatcher.onDidChange(refreshTraceDir) + tracePathWatcher.onDidDelete(refreshTraceDir) + context.subscriptions.push(tracePathWatcher) }, noop) watchT('saveName', (name) => {