Skip to content

Commit

Permalink
chore: append activation timestamp to output channel names (#505)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhedger authored Feb 24, 2025
1 parent 84ecc43 commit 097735e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
12 changes: 12 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
11 changes: 8 additions & 3 deletions src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { LogLevel, window } from "vscode";
import { displayName } from "../package.json";
import { activationTimestamp } from "./constants";

/**
* Logger
Expand All @@ -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<string, unknown>;

Expand Down
21 changes: 14 additions & 7 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
},
Expand All @@ -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,
},
);
};

/**
Expand All @@ -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,
},
Expand All @@ -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,
},
Expand Down

0 comments on commit 097735e

Please sign in to comment.