Skip to content

Commit 9304905

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 745b96d commit 9304905

File tree

4 files changed

+316
-116
lines changed

4 files changed

+316
-116
lines changed

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"vscode.powershell"
4141
],
4242
"scripts": {
43-
"vscode:prepublish": "node ./node_modules/vscode/bin/compile",
43+
"vscode:prepublish": "tsc -p ./",
4444
"compile": "tsc -p ./",
4545
"compile-watch": "tsc -watch -p ./",
4646
"postinstall": "node ./node_modules/vscode/bin/install"
@@ -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

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,13 @@ export class Logger {
2222
private logFilePath: string;
2323

2424
public logBasePath: string;
25+
public logSessionPath: string;
26+
public MinimumLogLevel: LogLevel = LogLevel.Normal;
2527

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

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-
31+
this.logBasePath = path.resolve(__dirname, "../logs");
3632
utils.ensurePathExists(this.logBasePath);
3733

3834
this.commands = [
@@ -47,7 +43,7 @@ export class Logger {
4743
}
4844

4945
public getLogFilePath(baseName: string): string {
50-
return path.resolve(this.logBasePath, `${baseName}.log`);
46+
return path.resolve(this.logSessionPath, `${baseName}.log`);
5147
}
5248

5349
public writeAtLevel(logLevel: LogLevel, message: string, ...additionalMessages: string[]) {
@@ -99,6 +95,29 @@ export class Logger {
9995
});
10096
}
10197

98+
public startNewLog(minimumLogLevel: string = "Normal") {
99+
this.MinimumLogLevel = this.logLevelNameToValue(minimumLogLevel.trim());
100+
101+
this.logSessionPath =
102+
path.resolve(
103+
this.logBasePath,
104+
`${Math.floor(Date.now() / 1000)}-${vscode.env.sessionId}`);
105+
106+
this.logFilePath = this.getLogFilePath("vscode-powershell");
107+
108+
utils.ensurePathExists(this.logSessionPath);
109+
}
110+
111+
private logLevelNameToValue(logLevelName: string): LogLevel {
112+
switch (logLevelName.toLowerCase()) {
113+
case "normal": return LogLevel.Normal;
114+
case "verbose": return LogLevel.Verbose;
115+
case "warning": return LogLevel.Warning;
116+
case "error": return LogLevel.Error;
117+
default: return LogLevel.Normal;
118+
}
119+
}
120+
102121
public dispose() {
103122
this.commands.forEach((command) => { command.dispose() });
104123
this.logChannel.dispose();
@@ -109,12 +128,14 @@ export class Logger {
109128
}
110129

111130
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);
131+
if (this.logSessionPath) {
132+
// Open the folder in VS Code since there isn't an easy way to
133+
// open the folder in the platform's file browser
134+
vscode.commands.executeCommand(
135+
'vscode.openFolder',
136+
vscode.Uri.file(this.logSessionPath),
137+
true);
138+
}
118139
}
119140
}
120141

src/main.ts

Lines changed: 1 addition & 2 deletions
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)