Skip to content

Commit f97ee10

Browse files
TylerLeonhardtrjmholt
authored andcommitted
Restart Current Session in every session quick pick (#1616)
* Restart Session in every dialog * always show "Switch to X"
1 parent f725c92 commit f97ee10

File tree

1 file changed

+38
-29
lines changed

1 file changed

+38
-29
lines changed

src/session.ts

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -729,39 +729,38 @@ export class SessionManager implements Middleware {
729729
}
730730

731731
private showSessionMenu() {
732-
let menuItems: SessionMenuItem[] = [];
733-
734732
const currentExePath = (this.powerShellExePath || "").toLowerCase();
735733
const availablePowerShellExes =
736734
getAvailablePowerShellExes(this.platformDetails, this.sessionSettings);
737735

738-
if (this.sessionStatus === SessionStatus.Running) {
739-
const currentPowerShellExe =
736+
let sessionText: string;
737+
738+
switch (this.sessionStatus) {
739+
case SessionStatus.Running:
740+
case SessionStatus.Initializing:
741+
case SessionStatus.NotStarted:
742+
case SessionStatus.NeverStarted:
743+
case SessionStatus.Stopping:
744+
const currentPowerShellExe =
740745
availablePowerShellExes
741746
.find((item) => item.exePath.toLowerCase() === currentExePath);
742747

743-
const powerShellSessionName =
744-
currentPowerShellExe ?
745-
currentPowerShellExe.versionName :
746-
`PowerShell ${this.versionDetails.displayVersion} ` +
747-
`(${this.versionDetails.architecture}) ${this.versionDetails.edition} Edition ` +
748-
`[${this.versionDetails.version}]`;
749-
750-
menuItems = [
751-
new SessionMenuItem(
752-
`Current session: ${powerShellSessionName}`,
753-
() => { vscode.commands.executeCommand("PowerShell.ShowLogs"); }),
754-
755-
new SessionMenuItem(
756-
"Restart Current Session",
757-
() => { this.restartSession(); }),
758-
];
759-
} else if (this.sessionStatus === SessionStatus.Failed) {
760-
menuItems = [
761-
new SessionMenuItem(
762-
`Session initialization failed, click here to show PowerShell extension logs`,
763-
() => { vscode.commands.executeCommand("PowerShell.ShowLogs"); }),
764-
];
748+
const powerShellSessionName =
749+
currentPowerShellExe ?
750+
currentPowerShellExe.versionName :
751+
`PowerShell ${this.versionDetails.displayVersion} ` +
752+
`(${this.versionDetails.architecture}) ${this.versionDetails.edition} Edition ` +
753+
`[${this.versionDetails.version}]`;
754+
755+
sessionText = `Current session: ${powerShellSessionName}`;
756+
break;
757+
758+
case SessionStatus.Failed:
759+
sessionText = "Session initialization failed, click here to show PowerShell extension logs";
760+
break;
761+
762+
default:
763+
throw new TypeError("Not a valid value for the enum 'SessionStatus'");
765764
}
766765

767766
const powerShellItems =
@@ -773,12 +772,22 @@ export class SessionManager implements Middleware {
773772
() => { this.changePowerShellExePath(item.exePath); });
774773
});
775774

776-
menuItems = menuItems.concat(powerShellItems);
775+
const menuItems: SessionMenuItem[] = [
776+
new SessionMenuItem(
777+
sessionText,
778+
() => { vscode.commands.executeCommand("PowerShell.ShowLogs"); }),
779+
780+
new SessionMenuItem(
781+
"Restart Current Session",
782+
() => { this.restartSession(); }),
783+
784+
// Add all of the different PowerShell options
785+
...powerShellItems,
777786

778-
menuItems.push(
779787
new SessionMenuItem(
780788
"Open Session Logs Folder",
781-
() => { vscode.commands.executeCommand("PowerShell.OpenLogFolder"); }));
789+
() => { vscode.commands.executeCommand("PowerShell.OpenLogFolder"); }),
790+
];
782791

783792
vscode
784793
.window

0 commit comments

Comments
 (0)