Skip to content

Commit

Permalink
Fix PowerShellProcess.dipose() to fire the onExited event
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
andyleejordan committed Jan 24, 2024
1 parent 2397932 commit 98960f4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class PowerShellProcess {
private static warnUserThreshold = 30;

public onExited: vscode.Event<void>;
private onExitedEmitter = new vscode.EventEmitter<void>();
private onExitedEmitter?: vscode.EventEmitter<void>;

private consoleTerminal?: vscode.Terminal;
private consoleCloseSubscription?: vscode.Disposable;
Expand All @@ -31,6 +31,7 @@ export class PowerShellProcess {
private sessionFilePath: vscode.Uri,
private sessionSettings: Settings) {

this.onExitedEmitter = new vscode.EventEmitter<void>();
this.onExited = this.onExitedEmitter.event;
}

Expand Down Expand Up @@ -149,6 +150,9 @@ export class PowerShellProcess {

void this.deleteSessionFile(this.sessionFilePath);

this.onExitedEmitter?.fire();
this.onExitedEmitter = undefined;

this.consoleTerminal?.dispose();
this.consoleTerminal = undefined;

Expand Down Expand Up @@ -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();
}
}
4 changes: 2 additions & 2 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});

Expand Down

0 comments on commit 98960f4

Please sign in to comment.