@@ -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 = vscode . Uri . joinPath ( extensionContext . storageUri , "sessions" ) ;
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