From 8642025b223b0f7d881eb59521e13a3a792e8f16 Mon Sep 17 00:00:00 2001 From: Dervex Date: Tue, 6 Aug 2024 22:13:40 -0400 Subject: [PATCH] Make sure session IDs are always unique after restoring --- src/argon.ts | 22 +++++++++++++++++++--- src/state.ts | 3 ++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/argon.ts b/src/argon.ts index adf98b6..a5b6edb 100644 --- a/src/argon.ts +++ b/src/argon.ts @@ -3,6 +3,8 @@ import * as logger from "./logger" import * as config from "./config" import { getCurrentDir } from "./util" +let lastId = 0 + function log(data: string, silent?: boolean) { let output = undefined @@ -65,11 +67,23 @@ async function spawn(args: string[], silent?: boolean) { : Promise.reject(firstOutput) } +function generateId() { + let id = Date.now() + + if (id === lastId) { + id++ + } + + lastId = id + + return id +} + export async function serve( project: string, options: string[], ): Promise<[number, string]> { - const id = Date.now() + const id = generateId() const message = await spawn(["serve", project, id.toString(), ...options]) return [id, message] @@ -77,8 +91,9 @@ export async function serve( export async function build(project: string, options: string[]) { if (options.includes("--watch")) { - const id = Date.now() + const id = generateId() await spawn(["build", project, id.toString(), ...options]) + return id } @@ -87,8 +102,9 @@ export async function build(project: string, options: string[]) { export async function sourcemap(project: string, options: string[]) { if (options.includes("--watch")) { - const id = Date.now() + const id = generateId() await spawn(["sourcemap", project, id.toString(), ...options]) + return id } diff --git a/src/state.ts b/src/state.ts index 50ec9d4..44c61ed 100644 --- a/src/state.ts +++ b/src/state.ts @@ -57,8 +57,9 @@ export class State { return !matches }) - this.context.workspaceState.update("lastSessions", lastSessions) this.updateItem() + + this.context.workspaceState.update("lastSessions", lastSessions) } public getSessions() {