Skip to content

Restart Current Session in every session quick pick #1616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 28, 2018
Merged
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
67 changes: 38 additions & 29 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -729,39 +729,38 @@ export class SessionManager implements Middleware {
}

private showSessionMenu() {
let menuItems: SessionMenuItem[] = [];

const currentExePath = (this.powerShellExePath || "").toLowerCase();
const availablePowerShellExes =
getAvailablePowerShellExes(this.platformDetails, this.sessionSettings);

if (this.sessionStatus === SessionStatus.Running) {
const currentPowerShellExe =
let sessionText: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this.sessionStatus is not SessionStatus.Running or SessionStatus.Failed, will this remain undefined? What will be shown in the menu?

If we're just branching on different values of an enum, maybe a switch block would be clearer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exhaustive switch statements FTW 👍 updated to a switch.


switch (this.sessionStatus) {
case SessionStatus.Running:
case SessionStatus.Initializing:
case SessionStatus.NotStarted:
case SessionStatus.NeverStarted:
case SessionStatus.Stopping:
const currentPowerShellExe =
availablePowerShellExes
.find((item) => item.exePath.toLowerCase() === currentExePath);

const powerShellSessionName =
currentPowerShellExe ?
currentPowerShellExe.versionName :
`PowerShell ${this.versionDetails.displayVersion} ` +
`(${this.versionDetails.architecture}) ${this.versionDetails.edition} Edition ` +
`[${this.versionDetails.version}]`;

menuItems = [
new SessionMenuItem(
`Current session: ${powerShellSessionName}`,
() => { vscode.commands.executeCommand("PowerShell.ShowLogs"); }),

new SessionMenuItem(
"Restart Current Session",
() => { this.restartSession(); }),
];
} else if (this.sessionStatus === SessionStatus.Failed) {
menuItems = [
new SessionMenuItem(
`Session initialization failed, click here to show PowerShell extension logs`,
() => { vscode.commands.executeCommand("PowerShell.ShowLogs"); }),
];
const powerShellSessionName =
currentPowerShellExe ?
currentPowerShellExe.versionName :
`PowerShell ${this.versionDetails.displayVersion} ` +
`(${this.versionDetails.architecture}) ${this.versionDetails.edition} Edition ` +
`[${this.versionDetails.version}]`;

sessionText = `Current session: ${powerShellSessionName}`;
break;

case SessionStatus.Failed:
sessionText = "Session initialization failed, click here to show PowerShell extension logs";
break;

default:
throw new TypeError("Not a valid value for the enum 'SessionStatus'");
}

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

menuItems = menuItems.concat(powerShellItems);
const menuItems: SessionMenuItem[] = [
new SessionMenuItem(
sessionText,
() => { vscode.commands.executeCommand("PowerShell.ShowLogs"); }),

new SessionMenuItem(
"Restart Current Session",
() => { this.restartSession(); }),

// Add all of the different PowerShell options
...powerShellItems,

menuItems.push(
new SessionMenuItem(
"Open Session Logs Folder",
() => { vscode.commands.executeCommand("PowerShell.OpenLogFolder"); }));
() => { vscode.commands.executeCommand("PowerShell.OpenLogFolder"); }),
];

vscode
.window
Expand Down