Skip to content

Commit 88a3324

Browse files
authored
Workaround for terminal PID freeze (#2498)
* Move terminal PID log to a non-awaited callback * Add logging to startup
1 parent 17d9a59 commit 88a3324

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/process.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,25 @@ export class PowerShellProcess {
110110
hideFromUser: !this.sessionSettings.integratedConsole.showOnStartup,
111111
});
112112

113+
const pwshName = path.basename(this.exePath);
114+
this.log.write(`${pwshName} started.`);
115+
113116
if (this.sessionSettings.integratedConsole.showOnStartup) {
114117
// We still need to run this to set the active terminal to the Integrated Console.
115118
this.consoleTerminal.show(true);
116119
}
117120

118121
// Start the language client
122+
this.log.write("Waiting for session file");
119123
const sessionDetails = await this.waitForSessionFile();
120124

121125
// Subscribe a log event for when the terminal closes
126+
this.log.write("Registering terminal close callback");
122127
this.consoleCloseSubscription = vscode.window.onDidCloseTerminal((terminal) => this.onTerminalClose(terminal));
123128

124129
// Log that the PowerShell terminal process has been started
125-
const terminalPid = await this.consoleTerminal.processId;
126-
const pwshName = path.basename(this.exePath);
127-
this.log.write(`${pwshName} started, pid: ${terminalPid}`);
130+
this.log.write("Registering terminal PID log callback");
131+
this.consoleTerminal.processId.then((pid) => this.logTerminalPid(pid, pwshName));
128132

129133
return sessionDetails;
130134
}
@@ -152,6 +156,10 @@ export class PowerShellProcess {
152156
}
153157
}
154158

159+
private logTerminalPid(pid: number, exeName: string) {
160+
this.log.write(`${exeName} PID: ${pid}`);
161+
}
162+
155163
private isLoginShell(pwshPath: string): boolean {
156164
try {
157165
// We can't know what version of PowerShell we have without running it
@@ -172,9 +180,11 @@ export class PowerShellProcess {
172180
utils.deleteSessionFile(this.sessionFilePath);
173181

174182
if (error) {
183+
this.log.write("Error occurred retrieving session file");
175184
return reject(error);
176185
}
177186

187+
this.log.write("Session file found");
178188
resolve(sessionDetails);
179189
});
180190
});

src/session.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,11 @@ export class SessionManager implements Middleware {
458458
this.log.write("Language server startup failed.");
459459
this.setSessionFailure("The language service could not be started: ", error);
460460
},
461-
);
461+
)
462+
.catch((error) => {
463+
this.log.write("Language server startup failed.");
464+
this.setSessionFailure("The language server could not be started: ", error);
465+
});
462466
}
463467

464468
private promptForRestart() {

0 commit comments

Comments
 (0)