From f4f29f0ae07cf163bdc0abd9a18a8f01a8b293e6 Mon Sep 17 00:00:00 2001 From: Andy Jordan <2226434+andyleejordan@users.noreply.github.com> Date: Wed, 28 Feb 2024 13:59:39 -0800 Subject: [PATCH] Fix how we pass the log directory to Editor Services Requires the related changes to Editor Services, and now our log files make sense, hooray! --- src/features/DebugSession.ts | 5 +---- src/logging.ts | 13 ++++--------- src/process.ts | 6 ++---- src/session.ts | 2 +- test/utils.ts | 4 +--- 5 files changed, 9 insertions(+), 21 deletions(-) diff --git a/src/features/DebugSession.ts b/src/features/DebugSession.ts index 6c51e8f2ab..1788ae7589 100644 --- a/src/features/DebugSession.ts +++ b/src/features/DebugSession.ts @@ -122,8 +122,6 @@ export const DebugConfigurations: Record = { export class DebugSessionFeature extends LanguageClientConsumer implements DebugConfigurationProvider, DebugAdapterDescriptorFactory { - - private sessionCount = 1; private tempDebugProcess: PowerShellProcess | undefined; private tempSessionDetails: IEditorServicesSessionDetails | undefined; private commands: Disposable[] = []; @@ -392,8 +390,7 @@ export class DebugSessionFeature extends LanguageClientConsumer this.tempDebugProcess = await this.sessionManager.createDebugSessionProcess(settings); // TODO: Maybe set a timeout on the cancellation token? const cancellationTokenSource = new CancellationTokenSource(); - this.tempSessionDetails = await this.tempDebugProcess.start( - `DebugSession-${this.sessionCount++}`, cancellationTokenSource.token); + this.tempSessionDetails = await this.tempDebugProcess.start(cancellationTokenSource.token); // NOTE: Dotnet attach debugging is only currently supported if a temporary debug terminal is used, otherwise we get lots of lock conflicts from loading the assemblies. if (session.configuration.attachDotnetDebugger) { diff --git a/src/logging.ts b/src/logging.ts index 846fcfc5b8..a7176c08ef 100644 --- a/src/logging.ts +++ b/src/logging.ts @@ -19,7 +19,7 @@ export enum LogLevel { * This will allow for easy mocking of the logger during unit tests. */ export interface ILogger { - getLogFilePath(baseName: string): vscode.Uri; + logDirectoryPath: vscode.Uri; updateLogLevel(logLevelName: string): void; write(message: string, ...additionalMessages: string[]): void; writeAndShowInformation(message: string, ...additionalMessages: string[]): Promise; @@ -35,12 +35,11 @@ export interface ILogger { } export class Logger implements ILogger { - public logDirectoryPath: vscode.Uri; - + public logDirectoryPath: vscode.Uri; // The folder for all the logs private logLevel: LogLevel; private commands: vscode.Disposable[]; private logChannel: vscode.OutputChannel; - private logFilePath: vscode.Uri; + private logFilePath: vscode.Uri; // The client's logs private logDirectoryCreated = false; private writingLog = false; @@ -53,7 +52,7 @@ export class Logger implements ILogger { globalStorageUri.with({ scheme: "file" }), "logs", `${Math.floor(Date.now() / 1000)}-${vscode.env.sessionId}`); - this.logFilePath = this.getLogFilePath("vscode-powershell"); + this.logFilePath = vscode.Uri.joinPath(this.logDirectoryPath, "vscode-powershell.log"); // Early logging of the log paths for debugging. if (LogLevel.Diagnostic >= this.logLevel) { @@ -79,10 +78,6 @@ export class Logger implements ILogger { } } - public getLogFilePath(baseName: string): vscode.Uri { - return vscode.Uri.joinPath(this.logDirectoryPath, `${baseName}.log`); - } - private writeAtLevel(logLevel: LogLevel, message: string, ...additionalMessages: string[]): void { if (logLevel >= this.logLevel) { void this.writeLine(message, logLevel); diff --git a/src/process.ts b/src/process.ts index 6cc291e977..8d36333121 100644 --- a/src/process.ts +++ b/src/process.ts @@ -35,9 +35,7 @@ export class PowerShellProcess { this.onExited = this.onExitedEmitter.event; } - public async start(logFileName: string, cancellationToken: vscode.CancellationToken): Promise { - const editorServicesLogPath = this.logger.getLogFilePath(logFileName); - + public async start(cancellationToken: vscode.CancellationToken): Promise { const psesModulePath = path.resolve( __dirname, @@ -50,7 +48,7 @@ export class PowerShellProcess { : ""; this.startPsesArgs += - `-LogPath '${utils.escapeSingleQuotes(editorServicesLogPath.fsPath)}' ` + + `-LogPath '${utils.escapeSingleQuotes(this.logger.logDirectoryPath.fsPath)}' ` + `-SessionDetailsPath '${utils.escapeSingleQuotes(this.sessionFilePath.fsPath)}' ` + `-FeatureFlags @(${featureFlags}) `; diff --git a/src/session.ts b/src/session.ts index 343d21f165..32ebe9ac74 100644 --- a/src/session.ts +++ b/src/session.ts @@ -540,7 +540,7 @@ export class SessionManager implements Middleware { } }); - this.sessionDetails = await languageServerProcess.start("EditorServices", cancellationToken); + this.sessionDetails = await languageServerProcess.start(cancellationToken); return languageServerProcess; } diff --git a/test/utils.ts b/test/utils.ts index d0beb09aac..a00e087230 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -15,9 +15,7 @@ const packageJSON: any = require(path.resolve(rootPath, "package.json")); export const extensionId = `${packageJSON.publisher}.${packageJSON.name}`; export class TestLogger implements ILogger { - getLogFilePath(_baseName: string): vscode.Uri { - return vscode.Uri.file(""); - } + logDirectoryPath: vscode.Uri = vscode.Uri.file(""); updateLogLevel(_logLevelName: string): void { return; }