@@ -63,11 +63,11 @@ class AbstractSyncedDocument {
63
63
assertEqual ( this . _state , DocumentLinterState . NO_WASM_DOC ) ;
64
64
this . _state = DocumentLinterState . CREATING_WASM_DOC ;
65
65
this . _wasmDocPromise = ( async ( ) => {
66
- let process ;
67
66
let wasmDoc ;
68
67
try {
69
- process = await this . _documentProcessManager . getOrCreateProcessAsync ( ) ;
70
- wasmDoc = process . createDocumentForVSCode ( ) ;
68
+ let workspace =
69
+ await this . _documentProcessManager . getOrCreateWorkspaceAsync ( ) ;
70
+ wasmDoc = workspace . createDocument ( ) ;
71
71
} catch ( e ) {
72
72
if ( e instanceof ProcessCrashed ) {
73
73
throw new LintingCrashed ( e ) ;
@@ -250,11 +250,10 @@ class AbstractSyncedDocument {
250
250
) ;
251
251
this . _state = DocumentLinterState . RECOVERING ;
252
252
this . _recoveryPromise = ( async ( ) => {
253
- let diags ;
254
- let process ;
255
253
try {
256
- process = await this . _documentProcessManager . getOrCreateProcessAsync ( ) ;
257
- let wasmDoc = process . createDocumentForVSCode ( ) ;
254
+ let workspace =
255
+ await this . _documentProcessManager . getOrCreateWorkspaceAsync ( ) ;
256
+ let wasmDoc = workspace . createDocument ( ) ;
258
257
259
258
// BEGIN CRITICAL SECTION (no awaiting below)
260
259
assertEqual ( this . _state , DocumentLinterState . RECOVERING ) ;
@@ -332,32 +331,35 @@ class DocumentProcessManager {
332
331
// TODO(strager): Allow developers to reload the .wasm file.
333
332
this . _processFactoryPromise = createProcessFactoryAsync ( ) ;
334
333
this . _processesCreated = 0 ;
335
- this . _processPromise = null ;
334
+ this . _processAndWorkspacePromise = null ;
336
335
}
337
336
338
- async _createNewProcessAsync ( ) {
337
+ async _createNewProcessAndWorkspaceAsync ( ) {
339
338
let processFactory = await this . _processFactoryPromise ;
340
339
let process = await processFactory . createProcessAsync ( ) ;
341
340
this . _processesCreated += 1 ;
342
- return process ;
341
+ let workspace = process . createWorkspaceForVSCode ( ) ;
342
+ return { process, workspace } ;
343
343
}
344
344
345
- async getOrCreateProcessAsync ( ) {
345
+ async getOrCreateWorkspaceAsync ( ) {
346
346
// BEGIN CRITICAL SECTION (no awaiting below)
347
- if ( this . _processPromise === null ) {
348
- this . _processPromise = this . _createNewProcessAsync ( ) ;
347
+ if ( this . _processAndWorkspacePromise === null ) {
348
+ this . _processAndWorkspacePromise =
349
+ this . _createNewProcessAndWorkspaceAsync ( ) ;
349
350
// END CRITICAL SECTION (no awaiting above)
350
351
} else {
351
352
// END CRITICAL SECTION (no awaiting above)
352
353
}
353
- let process = await this . _processPromise ;
354
+ let { process, workspace } = await this . _processAndWorkspacePromise ;
354
355
// BEGIN CRITICAL SECTION (no awaiting below)
355
356
while ( process . isTainted ( ) ) {
356
- this . _processPromise = this . _createNewProcessAsync ( ) ;
357
+ this . _processAndWorkspacePromise =
358
+ this . _createNewProcessAndWorkspaceAsync ( ) ;
357
359
// END CRITICAL SECTION (no awaiting above)
358
- process = await this . _processPromise ;
360
+ ( { process, workspace } = await this . _processAndWorkspacePromise ) ;
359
361
}
360
- return process ;
362
+ return workspace ;
361
363
}
362
364
363
365
// For testing only.
@@ -546,21 +548,41 @@ class Process {
546
548
return `Process(id=${ this . _idForDebugging } )` ;
547
549
}
548
550
549
- createDocumentForVSCode ( ) {
550
- return new DocumentForVSCode ( this ) ;
551
+ createWorkspaceForVSCode ( ) {
552
+ return new WorkspaceForVSCode ( this ) ;
551
553
}
552
554
553
555
async createDocumentForWebDemoAsync ( ) {
554
556
return new DocumentForWebDemo ( this ) ;
555
557
}
556
558
}
557
559
558
- class DocumentForVSCode {
560
+ class WorkspaceForVSCode {
559
561
constructor ( process ) {
560
562
this . _process = process ;
561
563
this . _wasmWorkspace = this . _process . _vscodeCreateWorkspace ( ) ;
564
+ }
565
+
566
+ // Returns a DocumentForVSCode
567
+ createDocument ( ) {
568
+ return new DocumentForVSCode ( this ) ;
569
+ }
570
+
571
+ dispose ( ) {
572
+ this . _process . _vscodeDestroyWorkspace ( this . _wasmWorkspace ) ;
573
+ this . _wasmWorkspace = null ;
574
+ }
575
+ }
576
+
577
+ class DocumentForVSCode {
578
+ // Private. Call WorkspaceForVSCode#createDocument instead.
579
+ constructor ( workspace ) {
580
+ if ( ! ( workspace instanceof WorkspaceForVSCode ) ) {
581
+ throw new TypeError ( `Expected WorkspaceForVSCode, but got ${ workspace } ` ) ;
582
+ }
583
+ this . _process = workspace . _process ;
562
584
this . _wasmDoc = this . _process . _vscodeCreateSourceDocument (
563
- this . _wasmWorkspace
585
+ workspace . _wasmWorkspace
564
586
) ;
565
587
}
566
588
0 commit comments