diff --git a/src/constants.ts b/src/constants.ts index 67371d3..eddc4a5 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -2,6 +2,18 @@ import { spawnSync } from "node:child_process"; import isWSL from "is-wsl"; import { workspace } from "vscode"; +/** + * Activation timestamp + * + * This constant contains the timestamp at which the extension was activated. + * + * We use this constant to generate unique identifiers for output channels to + * mitigate a bug in VS Code where the output channel is not cleared. + * + * @see https://github.com/microsoft/vscode/issues/204946 + */ +export const activationTimestamp = Date.now(); + /** * Whether the current platform uses musl */ diff --git a/src/logger.ts b/src/logger.ts index c1ef355..79264d4 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -1,5 +1,6 @@ import { LogLevel, window } from "vscode"; import { displayName } from "../package.json"; +import { activationTimestamp } from "./constants"; /** * Logger @@ -11,9 +12,13 @@ import { displayName } from "../package.json"; * logging verbosity, so only messages with the appropriate log level will be * displayed. */ -export const logger = window.createOutputChannel(displayName, { - log: true, -}); + +export const logger = window.createOutputChannel( + `${displayName} (${activationTimestamp})`, + { + log: true, + }, +); type LogArguments = Record; diff --git a/src/session.ts b/src/session.ts index 91d0ecb..b578a17 100644 --- a/src/session.ts +++ b/src/session.ts @@ -16,7 +16,11 @@ import { import { displayName } from "../package.json"; import { findBiomeGlobally, findBiomeLocally } from "./binary-finder"; import { isEnabledGlobally } from "./config"; -import { operatingMode, supportedLanguageIdentifiers } from "./constants"; +import { + activationTimestamp, + operatingMode, + supportedLanguageIdentifiers, +} from "./constants"; import { debug, error, info, error as logError, warn } from "./logger"; import { type Project, createProjects } from "./project"; import { state } from "./state"; @@ -294,7 +298,7 @@ const createLspLogger = (project?: Project): LogOutputChannel => { // logger name, so we just use the display name of the extension. if (!project?.folder) { return window.createOutputChannel( - `${displayName} LSP (global session)`, + `${displayName} LSP (global session) (${activationTimestamp})`, { log: true, }, @@ -309,9 +313,12 @@ const createLspLogger = (project?: Project): LogOutputChannel => { operatingMode === "multi-root" ? `${project.folder.name}::` : ""; const path = subtractURI(project.path, project.folder.uri).fsPath; - return window.createOutputChannel(`${displayName} LSP (${prefix}${path})`, { - log: true, - }); + return window.createOutputChannel( + `${displayName} LSP (${prefix}${path}) (${activationTimestamp})`, + { + log: true, + }, + ); }; /** @@ -323,7 +330,7 @@ const createLspTraceLogger = (project?: Project): LogOutputChannel => { // logger name, so we just use the display name of the extension. if (!project?.folder) { return window.createOutputChannel( - `${displayName} LSP trace (global session)`, + `${displayName} LSP trace (global session) (${activationTimestamp})`, { log: true, }, @@ -339,7 +346,7 @@ const createLspTraceLogger = (project?: Project): LogOutputChannel => { const path = subtractURI(project.path, project.folder.uri).fsPath; return window.createOutputChannel( - `${displayName} LSP trace (${prefix}${path})`, + `${displayName} LSP trace (${prefix}${path}) (${activationTimestamp})`, { log: true, },