Skip to content

Commit 1f924d1

Browse files
Use new isTransient API to prevent duplicate integrated consoles (#3854)
This new API available today in VS Code 1.65.0 prevents Code from saving and reloading the integrated console when the extension is reloaded. This is necessary because the extension always spawns a new terminal to host PowerShell Editor Services when it starts, and Code's newish feature to save and restore terminals caused these to be duplicated. When we update the VS Code engine, we can remove the cast to `any`.
1 parent 571abbf commit 1f924d1

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

src/process.ts

+15-11
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
// Licensed under the MIT License.
33

44
import cp = require("child_process");
5-
import fs = require("fs");
6-
import net = require("net");
7-
import os = require("os");
5+
import * as semver from "semver";
86
import path = require("path");
97
import vscode = require("vscode");
108
import { Logger } from "./logging";
@@ -104,14 +102,20 @@ export class PowerShellProcess {
104102
utils.deleteSessionFile(this.sessionFilePath);
105103

106104
// Launch PowerShell in the integrated terminal
107-
this.consoleTerminal =
108-
vscode.window.createTerminal({
109-
name: this.title,
110-
shellPath: this.exePath,
111-
shellArgs: powerShellArgs,
112-
hideFromUser: !this.sessionSettings.integratedConsole.showOnStartup,
113-
cwd: this.sessionSettings.cwd
114-
});
105+
const terminalOptions: vscode.TerminalOptions = {
106+
name: this.title,
107+
shellPath: this.exePath,
108+
shellArgs: powerShellArgs,
109+
hideFromUser: !this.sessionSettings.integratedConsole.showOnStartup,
110+
cwd: this.sessionSettings.cwd,
111+
};
112+
113+
// This API is available only in newer versions of VS Code.
114+
if (semver.gte(vscode.version, "1.65.0")) {
115+
(terminalOptions as any).isTransient = true;
116+
}
117+
118+
this.consoleTerminal = vscode.window.createTerminal(terminalOptions);
115119

116120
const pwshName = path.basename(this.exePath);
117121
this.log.write(`${pwshName} started.`);

src/session.ts

+2-10
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,6 @@ export class SessionManager implements Middleware {
660660
case SessionStatus.Running:
661661
case SessionStatus.NeverStarted:
662662
case SessionStatus.NotStarted:
663-
// This icon is available since 1.56, now our current engine version.
664663
this.statusBarItem.text = "$(terminal-powershell)";
665664
// These have to be reset because this function mutates state.
666665
this.statusBarItem.color = undefined;
@@ -669,18 +668,11 @@ export class SessionManager implements Middleware {
669668
case SessionStatus.Initializing:
670669
case SessionStatus.Stopping:
671670
this.statusBarItem.text = "$(sync)";
672-
// The warning colors were added later than our current engine version.
673-
// https://code.visualstudio.com/api/references/theme-color#status-bar-colors
674-
this.statusBarItem.color = (semver.gte(vscode.version, "1.59.0"))
675-
? new vscode.ThemeColor("statusBarItem.warningForeground")
676-
: new vscode.ThemeColor("statusBarItem.errorForeground");
677-
this.statusBarItem.backgroundColor = (semver.gte(vscode.version, "1.59.0"))
678-
? new vscode.ThemeColor("statusBarItem.warningBackground")
679-
: new vscode.ThemeColor("statusBarItem.errorBackground");
671+
this.statusBarItem.color = new vscode.ThemeColor("statusBarItem.warningForeground");
672+
this.statusBarItem.backgroundColor = new vscode.ThemeColor("statusBarItem.warningBackground");
680673
break;
681674
case SessionStatus.Failed:
682675
this.statusBarItem.text = "$(alert)";
683-
// The error colors have been available since 1.53.
684676
this.statusBarItem.color = new vscode.ThemeColor("statusBarItem.errorForeground");
685677
this.statusBarItem.backgroundColor = new vscode.ThemeColor("statusBarItem.errorBackground");
686678
break;

0 commit comments

Comments
 (0)