Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/appState.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -43,6 +44,12 @@ type StateType<K extends keyof State> = State[K] extends Ref<any> ? UnwrapRef<St

let context: vscode.ExtensionContext
let storagePath: string
let tracePathWatcher: vscode.FileSystemWatcher | undefined
const refreshTraceDir = debounce(async () => {
if (tracePath.value)
await sendTraceDir(tracePath.value)
}, 500)

export async function initAppState(extensionContext: vscode.ExtensionContext) {
context = extensionContext
storagePath = context.globalStorageUri.fsPath
Expand Down Expand Up @@ -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) => {
Expand Down