From 98960f40d77a3a6e4ab02faf003d411aa75e3c04 Mon Sep 17 00:00:00 2001 From: Andy Jordan <2226434+andyleejordan@users.noreply.github.com> Date: Wed, 24 Jan 2024 13:43:44 -0800 Subject: [PATCH] Fix `PowerShellProcess.dipose()` to fire the `onExited` event It was only firing when the terminal was closed, not whenever the process exited (which didn't make sense given its name and how we were using it). Also had to be idempotent. --- src/process.ts | 7 +++++-- src/session.ts | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/process.ts b/src/process.ts index 824c7740ca..6cc291e977 100644 --- a/src/process.ts +++ b/src/process.ts @@ -15,7 +15,7 @@ export class PowerShellProcess { private static warnUserThreshold = 30; public onExited: vscode.Event; - private onExitedEmitter = new vscode.EventEmitter(); + private onExitedEmitter?: vscode.EventEmitter; private consoleTerminal?: vscode.Terminal; private consoleCloseSubscription?: vscode.Disposable; @@ -31,6 +31,7 @@ export class PowerShellProcess { private sessionFilePath: vscode.Uri, private sessionSettings: Settings) { + this.onExitedEmitter = new vscode.EventEmitter(); this.onExited = this.onExitedEmitter.event; } @@ -149,6 +150,9 @@ export class PowerShellProcess { void this.deleteSessionFile(this.sessionFilePath); + this.onExitedEmitter?.fire(); + this.onExitedEmitter = undefined; + this.consoleTerminal?.dispose(); this.consoleTerminal = undefined; @@ -230,7 +234,6 @@ export class PowerShellProcess { } this.logger.writeWarning(`PowerShell process terminated or Extension Terminal was closed, PID: ${this.pid}`); - this.onExitedEmitter.fire(); this.dispose(); } } diff --git a/src/session.ts b/src/session.ts index 866117316a..3123792a51 100644 --- a/src/session.ts +++ b/src/session.ts @@ -530,13 +530,13 @@ export class SessionManager implements Middleware { this.sessionSettings); languageServerProcess.onExited( - async () => { + () => { LanguageClientConsumer.onLanguageClientExited(); if (this.sessionStatus === SessionStatus.Running || this.sessionStatus === SessionStatus.Busy) { this.setSessionStatus("Session Exited!", SessionStatus.Failed); - await this.promptForRestart(); + void this.promptForRestart(); } });