@@ -70,8 +70,7 @@ export class SessionManager implements Middleware {
70
70
private languageServerClient : LanguageClient = undefined ;
71
71
private sessionSettings : Settings . ISettings = undefined ;
72
72
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 ;
75
74
private bundledModulesPath : string ;
76
75
private started : boolean = false ;
77
76
@@ -86,6 +85,12 @@ export class SessionManager implements Middleware {
86
85
version : string ,
87
86
private telemetryReporter : TelemetryReporter ) {
88
87
88
+ if ( extensionContext . storageUri !== undefined ) {
89
+ this . sessionsFolder = extensionContext . storageUri ;
90
+ } else {
91
+ this . sessionsFolder = vscode . Uri . file ( path . resolve ( __dirname , "../sessions" ) ) ;
92
+ }
93
+
89
94
this . platformDetails = getPlatformDetails ( ) ;
90
95
91
96
this . HostName = hostName ;
@@ -275,39 +280,35 @@ export class SessionManager implements Middleware {
275
280
return this . versionDetails ;
276
281
}
277
282
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" ) ;
284
286
}
285
287
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 ) ;
288
290
289
- const writeStream = fs . createWriteStream ( sessionFilePath ) ;
291
+ const writeStream = fs . createWriteStream ( sessionFilePath . fsPath ) ;
290
292
writeStream . write ( JSON . stringify ( sessionDetails ) ) ;
291
293
writeStream . close ( ) ;
292
294
}
293
295
294
- public static readSessionFile ( sessionFilePath : string ) : IEditorServicesSessionDetails {
296
+ public static readSessionFile ( sessionFilePath : vscode . Uri ) : IEditorServicesSessionDetails {
295
297
// 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" ) ;
297
299
return JSON . parse ( fileContents ) ;
298
300
}
299
301
300
- public static async deleteSessionFile ( sessionFilePath : string ) {
302
+ public static async deleteSessionFile ( sessionFilePath : vscode . Uri ) {
301
303
try {
302
- await vscode . workspace . fs . delete ( vscode . Uri . file ( sessionFilePath ) ) ;
303
- // fs.unlinkSync(sessionFilePath);
304
+ await vscode . workspace . fs . delete ( sessionFilePath ) ;
304
305
} catch ( e ) {
305
306
// TODO: Be more specific about what we're catching
306
307
}
307
308
}
308
309
309
310
public createDebugSessionProcess (
310
- sessionPath : string ,
311
+ sessionPath : vscode . Uri ,
311
312
sessionSettings : Settings . ISettings ) : PowerShellProcess {
312
313
313
314
// NOTE: We only support one temporary integrated console at a time. To
@@ -492,9 +493,7 @@ export class SessionManager implements Middleware {
492
493
private startPowerShell ( ) {
493
494
this . setSessionStatus ( "Starting..." , SessionStatus . Initializing ) ;
494
495
495
- const sessionFilePath =
496
- this . getSessionFilePath (
497
- Math . floor ( 100000 + Math . random ( ) * 900000 ) ) ;
496
+ const sessionFilePath = this . getNewSessionFilePath ( ) ;
498
497
499
498
this . languageServerProcess =
500
499
new PowerShellProcess (
0 commit comments