Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export class PowerShellProcess {
// This is used to warn the user that the extension is taking longer than expected to startup.
private static warnUserThreshold = 30;

private static title = "PowerShell Extension";

public onExited: vscode.Event<void>;
private onExitedEmitter?: vscode.EventEmitter<void>;

Expand All @@ -25,7 +27,7 @@ export class PowerShellProcess {
constructor(
public exePath: string,
private bundledModulesPath: string,
private title: string,
private isTemp: boolean,
private logger: ILogger,
private startPsesArgs: string,
private sessionFilePath: vscode.Uri,
Expand Down Expand Up @@ -99,7 +101,7 @@ export class PowerShellProcess {

// Launch PowerShell in the integrated terminal
const terminalOptions: vscode.TerminalOptions = {
name: this.title,
name: this.isTemp ? `${PowerShellProcess.title} (TEMP)` : PowerShellProcess.title,
shellPath: this.exePath,
shellArgs: powerShellArgs,
cwd: await validateCwdSetting(this.logger),
Expand Down Expand Up @@ -127,6 +129,17 @@ export class PowerShellProcess {
return await this.waitForSessionFile(cancellationToken);
}

// This function is used to clean-up stale PowerShell Extension terminals,
// which can happen with `restartExtensionHost` is called because we are
// unable to finish diposing before we're gone.
public static cleanUpTerminals(): void {
for (const terminal of vscode.window.terminals) {
if (terminal.name.startsWith(PowerShellProcess.title)) {
terminal.dispose();
}
}
}

// This function should only be used after a failure has occurred because it is slow!
public async getVersionCli(): Promise<string> {
const exec = promisify(cp.execFile);
Expand Down
7 changes: 5 additions & 2 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ export class SessionManager implements Middleware {
new PowerShellProcess(
this.PowerShellExeDetails.exePath,
bundledModulesPath,
"[TEMP] PowerShell Extension",
true,
this.logger,
this.getEditorServicesArgs(bundledModulesPath, this.PowerShellExeDetails) + "-DebugServiceOnly ",
this.getNewSessionFilePath(),
Expand Down Expand Up @@ -528,11 +528,14 @@ export class SessionManager implements Middleware {
cancellationToken: vscode.CancellationToken): Promise<PowerShellProcess> {

const bundledModulesPath = await this.getBundledModulesPath();

// Dispose any stale terminals from previous killed sessions.
PowerShellProcess.cleanUpTerminals();
const languageServerProcess =
new PowerShellProcess(
powerShellExeDetails.exePath,
bundledModulesPath,
"PowerShell Extension",
false,
this.logger,
this.getEditorServicesArgs(bundledModulesPath, powerShellExeDetails),
this.getNewSessionFilePath(),
Expand Down