| 1 | export interface WorkspaceTreeMemorySnapshot { |
| 2 | openDirs: Set<string>; |
| 3 | visitId: number; |
| 4 | } |
| 5 | |
| 6 | const workspaceTreeMemory = new Map<string, WorkspaceTreeMemorySnapshot>(); |
| 7 | let activeWorkspaceTreeKey = ""; |
| 8 | let workspaceTreeVisitSequence = 0; |
| 9 | |
| 10 | export function workspaceTreeVisitId(memoryKey: string): number { |
| 11 | if (activeWorkspaceTreeKey !== memoryKey) { |
| 12 | activeWorkspaceTreeKey = memoryKey; |
| 13 | workspaceTreeVisitSequence += 1; |
| 14 | } |
| 15 | return workspaceTreeVisitSequence; |
| 16 | } |
| 17 | |
| 18 | export function readWorkspaceTreeMemory(memoryKey: string): WorkspaceTreeMemorySnapshot | null { |
| 19 | const snapshot = workspaceTreeMemory.get(memoryKey); |
| 20 | if (!snapshot) return null; |
| 21 | return { |
| 22 | openDirs: new Set(snapshot.openDirs), |
| 23 | visitId: snapshot.visitId, |
| 24 | }; |
| 25 | } |
| 26 | |
| 27 | export function rememberWorkspaceTreeOpenDirs(memoryKey: string, openDirs: ReadonlySet<string>, visitId: number): void { |
| 28 | workspaceTreeMemory.set(memoryKey, { |
| 29 | openDirs: new Set(openDirs), |
| 30 | visitId, |
| 31 | }); |
| 32 | } |
| 33 | |
| 34 | export function touchWorkspaceTreeVisit(memoryKey: string, visitId: number): void { |
| 35 | const snapshot = workspaceTreeMemory.get(memoryKey); |
| 36 | workspaceTreeMemory.set(memoryKey, { |
| 37 | openDirs: new Set(snapshot?.openDirs ?? [""]), |
| 38 | visitId, |
| 39 | }); |
| 40 | } |
| 41 | |
| 42 | export function resetWorkspaceTreeMemoryForTests(): void { |
| 43 | workspaceTreeMemory.clear(); |
| 44 | activeWorkspaceTreeKey = ""; |
| 45 | workspaceTreeVisitSequence = 0; |
| 46 | } |
| 47 |