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 2 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
34 changes: 16 additions & 18 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -729,12 +729,11 @@ export class SessionManager implements Middleware {
}

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

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

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.

if (this.sessionStatus === SessionStatus.Running) {
const currentPowerShellExe =
availablePowerShellExes
Expand All @@ -747,21 +746,10 @@ export class SessionManager implements Middleware {
`(${this.versionDetails.architecture}) ${this.versionDetails.edition} Edition ` +
`[${this.versionDetails.version}]`;

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

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"); }),
];
sessionText = "Session initialization failed, click here to show PowerShell extension logs";
}

const powerShellItems =
Expand All @@ -773,12 +761,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