Skip to content

Commit a4b1257

Browse files
committed
Add session management menu
This change completes the session management menu which allows the user to easily switch or restart their PowerShell session. It also improves log creation across sessions.
1 parent 7214908 commit a4b1257

File tree

4 files changed

+306
-116
lines changed

4 files changed

+306
-116
lines changed

package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
},
9292
{
9393
"command": "PowerShell.RestartSession",
94-
"title": "Restart PowerShell Session",
94+
"title": "Restart Current Session",
9595
"category": "PowerShell"
9696
},
9797
{
@@ -118,6 +118,11 @@
118118
"command": "PowerShell.ShowAdditionalCommands",
119119
"title": "Show additional commands from PowerShell modules",
120120
"category": "PowerShell"
121+
},
122+
{
123+
"command": "PowerShell.ShowSessionMenu",
124+
"title": "Show Session Menu",
125+
"category": "PowerShell"
121126
}
122127
],
123128
"snippets": [

src/logging.ts

+34-16
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,11 @@ export class Logger {
2222
private logFilePath: string;
2323

2424
public logBasePath: string;
25+
public MinimumLogLevel: LogLevel = LogLevel.Normal;
2526

26-
constructor(readonly MinimumLogLevel: LogLevel = LogLevel.Normal) {
27+
constructor() {
2728
this.logChannel = vscode.window.createOutputChannel("PowerShell Extension Logs");
2829

29-
this.logBasePath =
30-
path.resolve(
31-
__dirname,
32-
"../logs",
33-
`${Math.floor(Date.now() / 1000)}-${vscode.env.sessionId}`);
34-
this.logFilePath = this.getLogFilePath("vscode-powershell");
35-
36-
utils.ensurePathExists(this.logBasePath);
37-
3830
this.commands = [
3931
vscode.commands.registerCommand(
4032
'PowerShell.ShowLogs',
@@ -99,6 +91,30 @@ export class Logger {
9991
});
10092
}
10193

94+
public startNewLog(minimumLogLevel: string = "Normal") {
95+
this.MinimumLogLevel = this.logLevelNameToValue(minimumLogLevel.trim());
96+
97+
this.logBasePath =
98+
path.resolve(
99+
__dirname,
100+
"../logs",
101+
`${Math.floor(Date.now() / 1000)}-${vscode.env.sessionId}`);
102+
103+
this.logFilePath = this.getLogFilePath("vscode-powershell");
104+
105+
utils.ensurePathExists(this.logBasePath);
106+
}
107+
108+
private logLevelNameToValue(logLevelName: string): LogLevel {
109+
switch (logLevelName.toLowerCase()) {
110+
case "normal": return LogLevel.Normal;
111+
case "verbose": return LogLevel.Verbose;
112+
case "warning": return LogLevel.Warning;
113+
case "error": return LogLevel.Error;
114+
default: return LogLevel.Normal;
115+
}
116+
}
117+
102118
public dispose() {
103119
this.commands.forEach((command) => { command.dispose() });
104120
this.logChannel.dispose();
@@ -109,12 +125,14 @@ export class Logger {
109125
}
110126

111127
private openLogFolder() {
112-
// Open the folder in VS Code since there isn't an easy way to
113-
// open the folder in the platform's file browser
114-
vscode.commands.executeCommand(
115-
'vscode.openFolder',
116-
vscode.Uri.file(this.logBasePath),
117-
true);
128+
if (this.logBasePath) {
129+
// Open the folder in VS Code since there isn't an easy way to
130+
// open the folder in the platform's file browser
131+
vscode.commands.executeCommand(
132+
'vscode.openFolder',
133+
vscode.Uri.file(this.logBasePath),
134+
true);
135+
}
118136
}
119137
}
120138

src/main.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ export function activate(context: vscode.ExtensionContext): void {
6666
});
6767

6868
// Create the logger
69-
// TODO: Pull level from settings
70-
logger = new Logger(LogLevel.Verbose);
69+
logger = new Logger();
7170

7271
// Create features
7372
extensionFeatures = [

0 commit comments

Comments
 (0)