Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8d10aa3

Browse files
Use storageUri for session file
Note that we seemed to be unnecessarily writing a new debug session file for the `RunCode` and `PesterTests` features; they work fine without that logic as the debugger itself handles the session file.
1 parent 80c10d3 commit 8d10aa3

File tree

5 files changed

+23
-34
lines changed

5 files changed

+23
-34
lines changed

‎src/features/DebugSession.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
309309
// Create or show the interactive console
310310
vscode.commands.executeCommand("PowerShell.ShowSessionConsole", true);
311311

312-
const sessionFilePath = this.sessionManager.getDebugSessionFilePath();
312+
const sessionFilePath = this.sessionManager.getNewSessionFilePath();
313313

314314
if (config.createTemporaryIntegratedConsole) {
315315
this.tempDebugProcess = this.sessionManager.createDebugSessionProcess(sessionFilePath, settings);

‎src/features/PesterTests.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,6 @@ export class PesterTestsFeature implements vscode.Disposable {
130130
// TODO: #367 Check if "newSession" mode is configured
131131
await vscode.commands.executeCommand("PowerShell.ShowSessionConsole", true);
132132

133-
// Write out temporary debug session file
134-
await this.sessionManager.writeSessionFile(
135-
this.sessionManager.getDebugSessionFilePath(),
136-
this.sessionManager.getSessionDetails());
137-
138133
// TODO: Update to handle multiple root workspaces.
139134
//
140135
// Ensure the necessary script exists (for testing). The debugger will

‎src/features/RunCode.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@ export class RunCodeFeature implements vscode.Disposable {
4343
// TODO: #367: Check if "newSession" mode is configured
4444
await vscode.commands.executeCommand("PowerShell.ShowSessionConsole", true);
4545

46-
// Write out temporary debug session file
47-
await this.sessionManager.writeSessionFile(
48-
this.sessionManager.getDebugSessionFilePath(),
49-
this.sessionManager.getSessionDetails());
50-
5146
// TODO: Update to handle multiple root workspaces.
5247
await vscode.debug.startDebugging(vscode.workspace.workspaceFolders?.[0], launchConfig);
5348
}

‎src/process.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class PowerShellProcess {
3131
private title: string,
3232
private log: Logger,
3333
private startPsesArgs: string,
34-
private sessionFilePath: string,
34+
private sessionFilePath: vscode.Uri,
3535
private sessionSettings: Settings.ISettings) {
3636

3737
this.onExited = this.onExitedEmitter.event;
@@ -53,7 +53,7 @@ export class PowerShellProcess {
5353

5454
this.startPsesArgs +=
5555
`-LogPath '${PowerShellProcess.escapeSingleQuotes(editorServicesLogPath.fsPath)}' ` +
56-
`-SessionDetailsPath '${PowerShellProcess.escapeSingleQuotes(this.sessionFilePath)}' ` +
56+
`-SessionDetailsPath '${PowerShellProcess.escapeSingleQuotes(this.sessionFilePath.fsPath)}' ` +
5757
`-FeatureFlags @(${featureFlags}) `;
5858

5959
if (this.sessionSettings.integratedConsole.useLegacyReadLine) {
@@ -197,7 +197,7 @@ export class PowerShellProcess {
197197

198198
// Check every 2 seconds
199199
for (let i = numOfTries; i > 0; i--) {
200-
if (utils.checkIfFileExists(this.sessionFilePath)) {
200+
if (utils.checkIfFileExists(this.sessionFilePath.fsPath)) {
201201
this.log.write("Session file found");
202202
const sessionDetails = SessionManager.readSessionFile(this.sessionFilePath);
203203
SessionManager.deleteSessionFile(this.sessionFilePath);

‎src/session.ts‎

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ export class SessionManager implements Middleware {
7070
private languageServerClient: LanguageClient = undefined;
7171
private sessionSettings: Settings.ISettings = undefined;
7272
private sessionDetails: IEditorServicesSessionDetails;
73-
private sessionsFolder = path.resolve(__dirname, "../sessions");
74-
private sessionFilePathPrefix = path.resolve(this.sessionsFolder, "PSES-VSCode-" + process.env.VSCODE_PID);
73+
private sessionsFolder: vscode.Uri;
7574
private bundledModulesPath: string;
7675
private started: boolean = false;
7776

@@ -86,6 +85,12 @@ export class SessionManager implements Middleware {
8685
version: string,
8786
private telemetryReporter: TelemetryReporter) {
8887

88+
if (extensionContext.storageUri !== undefined) {
89+
this.sessionsFolder = extensionContext.storageUri;
90+
} else {
91+
this.sessionsFolder = vscode.Uri.file(path.resolve(__dirname, "../sessions"));
92+
}
93+
8994
this.platformDetails = getPlatformDetails();
9095

9196
this.HostName = hostName;
@@ -275,39 +280,35 @@ export class SessionManager implements Middleware {
275280
return this.versionDetails;
276281
}
277282

278-
private getSessionFilePath(uniqueId: number): string {
279-
return `${this.sessionFilePathPrefix}-${uniqueId}`;
280-
}
281-
282-
public getDebugSessionFilePath(): string {
283-
return `${this.sessionFilePathPrefix}-Debug`;
283+
public getNewSessionFilePath(): vscode.Uri {
284+
const uniqueId: number = Math.floor(100000 + Math.random() * 900000);
285+
return vscode.Uri.joinPath(this.sessionsFolder, "PSES-VSCode-" + process.env.VSCODE_PID + "-" + uniqueId + ".json");
284286
}
285287

286-
public async writeSessionFile(sessionFilePath: string, sessionDetails: IEditorServicesSessionDetails) {
287-
await vscode.workspace.fs.createDirectory(vscode.Uri.file(this.sessionsFolder));
288+
public async writeSessionFile(sessionFilePath: vscode.Uri, sessionDetails: IEditorServicesSessionDetails) {
289+
await vscode.workspace.fs.createDirectory(this.sessionsFolder);
288290

289-
const writeStream = fs.createWriteStream(sessionFilePath);
291+
const writeStream = fs.createWriteStream(sessionFilePath.fsPath);
290292
writeStream.write(JSON.stringify(sessionDetails));
291293
writeStream.close();
292294
}
293295

294-
public static readSessionFile(sessionFilePath: string): IEditorServicesSessionDetails {
296+
public static readSessionFile(sessionFilePath: vscode.Uri): IEditorServicesSessionDetails {
295297
// TODO: Use vscode.workspace.fs.readFile instead of fs.readFileSync.
296-
const fileContents = fs.readFileSync(sessionFilePath, "utf-8");
298+
const fileContents = fs.readFileSync(sessionFilePath.fsPath, "utf-8");
297299
return JSON.parse(fileContents);
298300
}
299301

300-
public static async deleteSessionFile(sessionFilePath: string) {
302+
public static async deleteSessionFile(sessionFilePath: vscode.Uri) {
301303
try {
302-
await vscode.workspace.fs.delete(vscode.Uri.file(sessionFilePath));
303-
// fs.unlinkSync(sessionFilePath);
304+
await vscode.workspace.fs.delete(sessionFilePath);
304305
} catch (e) {
305306
// TODO: Be more specific about what we're catching
306307
}
307308
}
308309

309310
public createDebugSessionProcess(
310-
sessionPath: string,
311+
sessionPath: vscode.Uri,
311312
sessionSettings: Settings.ISettings): PowerShellProcess {
312313

313314
// NOTE: We only support one temporary integrated console at a time. To
@@ -492,9 +493,7 @@ export class SessionManager implements Middleware {
492493
private startPowerShell() {
493494
this.setSessionStatus("Starting...", SessionStatus.Initializing);
494495

495-
const sessionFilePath =
496-
this.getSessionFilePath(
497-
Math.floor(100000 + Math.random() * 900000));
496+
const sessionFilePath = this.getNewSessionFilePath();
498497

499498
this.languageServerProcess =
500499
new PowerShellProcess(

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /