Skip to content

Commit e89b513

Browse files
committed
Replace ensurePathExists with fs.createDirectory
1 parent 84fa978 commit e89b513

File tree

5 files changed

+10
-28
lines changed

5 files changed

+10
-28
lines changed

src/features/DebugSession.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,9 @@ export class DebugSessionFeature extends LanguageClientConsumer
317317
// TODO: This should be cleaned up to support multiple temporary consoles.
318318
this.tempDebugProcess = this.sessionManager.createDebugSessionProcess(sessionFilePath, settings);
319319
this.tempSessionDetails = await this.tempDebugProcess.start(`DebugSession-${this.sessionCount++}`);
320-
utils.writeSessionFile(sessionFilePath, this.tempSessionDetails);
320+
await utils.writeSessionFile(sessionFilePath, this.tempSessionDetails);
321321
} else {
322-
utils.writeSessionFile(sessionFilePath, this.sessionManager.getSessionDetails());
322+
await utils.writeSessionFile(sessionFilePath, this.sessionManager.getSessionDetails());
323323
}
324324

325325
return config;

src/features/PesterTests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export class PesterTestsFeature implements vscode.Disposable {
131131
vscode.commands.executeCommand("PowerShell.ShowSessionConsole", true);
132132

133133
// Write out temporary debug session file
134-
utils.writeSessionFile(
134+
await utils.writeSessionFile(
135135
utils.getDebugSessionFilePath(),
136136
this.sessionManager.getSessionDetails());
137137

src/features/RunCode.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@ export class RunCodeFeature implements vscode.Disposable {
3535

3636
const launchType = runInDebugger ? LaunchType.Debug : LaunchType.Run;
3737
const launchConfig = createLaunchConfig(launchType, scriptToRun, args);
38-
this.launch(launchConfig);
38+
await this.launch(launchConfig);
3939
}
4040

41-
private launch(launchConfig) {
41+
private async launch(launchConfig: string | vscode.DebugConfiguration) {
4242
// Create or show the interactive console
4343
// TODO #367: Check if "newSession" mode is configured
44-
vscode.commands.executeCommand("PowerShell.ShowSessionConsole", true);
44+
await vscode.commands.executeCommand("PowerShell.ShowSessionConsole", true);
4545

4646
// Write out temporary debug session file
47-
utils.writeSessionFile(
47+
await utils.writeSessionFile(
4848
utils.getDebugSessionFilePath(),
4949
this.sessionManager.getSessionDetails());
5050

5151
// TODO: Update to handle multiple root workspaces.
52-
vscode.debug.startDebugging(vscode.workspace.workspaceFolders?.[0], launchConfig);
52+
await vscode.debug.startDebugging(vscode.workspace.workspaceFolders?.[0], launchConfig);
5353
}
5454
}
5555

src/logging.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import fs = require("fs");
55
import os = require("os");
66
import path = require("path");
77
import vscode = require("vscode");
8-
import utils = require("./utils");
98

109
export enum LogLevel {
1110
Diagnostic,
@@ -44,7 +43,6 @@ export class Logger implements ILogger {
4443
if (logBasePath === undefined) {
4544
// No workspace, we have to use another folder.
4645
this.logBasePath = vscode.Uri.file(path.resolve(__dirname, "../logs"));
47-
utils.ensurePathExists(this.logBasePath.fsPath);
4846
} else {
4947
this.logBasePath = vscode.Uri.joinPath(logBasePath, "logs");
5048
}

src/utils.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,6 @@ import vscode = require("vscode");
1010

1111
export const PowerShellLanguageId = "powershell";
1212

13-
export function ensurePathExists(targetPath: string): void {
14-
// Ensure that the path exists
15-
try {
16-
// TODO: Use vscode.workspace.fs
17-
fs.mkdirSync(targetPath);
18-
} catch (e) {
19-
// If the exception isn't to indicate that the folder exists already, rethrow it.
20-
if (e.code !== "EEXIST") {
21-
throw e;
22-
}
23-
}
24-
}
25-
2613
// Check that the file exists in an asynchronous manner that relies solely on the VS Code API, not Node's fs library.
2714
export async function fileExists(targetPath: string | vscode.Uri): Promise<boolean> {
2815
try {
@@ -67,9 +54,6 @@ export type IReadSessionFileCallback = (details: IEditorServicesSessionDetails)
6754
const sessionsFolder = path.resolve(__dirname, "../sessions");
6855
const sessionFilePathPrefix = path.resolve(sessionsFolder, "PSES-VSCode-" + process.env.VSCODE_PID);
6956

70-
// Create the sessions path if it doesn't exist already
71-
ensurePathExists(sessionsFolder);
72-
7357
export function getSessionFilePath(uniqueId: number) {
7458
return `${sessionFilePathPrefix}-${uniqueId}`;
7559
}
@@ -78,8 +62,8 @@ export function getDebugSessionFilePath() {
7862
return `${sessionFilePathPrefix}-Debug`;
7963
}
8064

81-
export function writeSessionFile(sessionFilePath: string, sessionDetails: IEditorServicesSessionDetails) {
82-
ensurePathExists(sessionsFolder);
65+
export async function writeSessionFile(sessionFilePath: string, sessionDetails: IEditorServicesSessionDetails) {
66+
await vscode.workspace.fs.createDirectory(vscode.Uri.file(sessionsFolder));
8367

8468
const writeStream = fs.createWriteStream(sessionFilePath);
8569
writeStream.write(JSON.stringify(sessionDetails));

0 commit comments

Comments
 (0)