@@ -69,13 +69,17 @@ class DocumentLinter {
69
69
assertEqual ( this . _state , DocumentLinterState . NO_PARSER ) ;
70
70
this . _state = DocumentLinterState . CREATING_PARSER ;
71
71
this . _parserPromise = ( async ( ) => {
72
+ let process ;
72
73
let parser ;
73
74
try {
74
- let process =
75
- await this . _documentProcessManager . getOrCreateProcessAsync ( ) ;
76
- parser = await process . createDocumentForVSCodeAsync ( ) ;
75
+ process = await this . _documentProcessManager . getOrCreateProcessAsync ( ) ;
76
+ // BEGIN CRITICAL SECTION (no awaiting below)
77
+ this . _documentProcessManager . checkIfProcessCrashed ( process ) ;
78
+ parser = process . createDocumentForVSCode ( ) ;
79
+ // END CRITICAL SECTION (no awaiting above)
77
80
} catch ( e ) {
78
81
if ( e instanceof ProcessCrashed ) {
82
+ this . _documentProcessManager . processCrashed ( process ) ;
79
83
throw new LintingCrashed ( e ) ;
80
84
} else {
81
85
throw e ;
@@ -117,9 +121,15 @@ class DocumentLinter {
117
121
}
118
122
if ( this . _parser !== null ) {
119
123
try {
124
+ // BEGIN CRITICAL SECTION (no awaiting below)
125
+ this . _documentProcessManager . checkIfProcessCrashed (
126
+ this . _parser . process
127
+ ) ;
120
128
this . _parser . dispose ( ) ;
129
+ // END CRITICAL SECTION (no awaiting above)
121
130
} catch ( e ) {
122
131
if ( e instanceof ProcessCrashed ) {
132
+ this . _documentProcessManager . processCrashed ( this . _parser . process ) ;
123
133
// Ignore.
124
134
} else {
125
135
throw e ;
@@ -196,17 +206,26 @@ class DocumentLinter {
196
206
case DocumentLinterState . PARSER_LOADED :
197
207
this . _pendingChanges . push ( ...changes ) ;
198
208
try {
209
+ this . _documentProcessManager . checkIfProcessCrashed (
210
+ this . _parser . process
211
+ ) ;
199
212
for ( let change of this . _pendingChanges ) {
200
213
this . _parser . replaceText ( change . range , change . text ) ;
201
214
}
202
215
this . _pendingChanges . length = 0 ;
203
216
// END CRITICAL SECTION (no awaiting above)
204
217
218
+ // BEGIN CRITICAL SECTION (no awaiting below)
219
+ this . _documentProcessManager . checkIfProcessCrashed (
220
+ this . _parser . process
221
+ ) ;
205
222
let diags = this . _parser . lint ( ) ;
223
+ // END CRITICAL SECTION (no awaiting above)
206
224
this . _document . setDiagnostics ( diags ) ;
207
225
} catch ( e ) {
208
226
// END CRITICAL SECTION (no awaiting above)
209
227
if ( e instanceof ProcessCrashed ) {
228
+ this . _documentProcessManager . processCrashed ( this . _parser . process ) ;
210
229
await this . _recoverFromCrashAsync ( e ) ;
211
230
} else {
212
231
throw e ;
@@ -235,6 +254,7 @@ class DocumentLinter {
235
254
// BEGIN CRITICAL SECTION (no awaiting below)
236
255
assertEqual ( this . _state , DocumentLinterState . PARSER_UNINITIALIZED ) ;
237
256
try {
257
+ this . _documentProcessManager . checkIfProcessCrashed ( this . _parser . process ) ;
238
258
this . _parser . replaceText (
239
259
{
240
260
start : { line : 0 , character : 0 } ,
@@ -246,10 +266,14 @@ class DocumentLinter {
246
266
this . _state = DocumentLinterState . PARSER_LOADED ;
247
267
// END CRITICAL SECTION (no awaiting above)
248
268
269
+ // BEGIN CRITICAL SECTION (no awaiting below)
270
+ this . _documentProcessManager . checkIfProcessCrashed ( this . _parser . process ) ;
249
271
let diags = this . _parser . lint ( ) ;
272
+ // END CRITICAL SECTION (no awaiting above)
250
273
this . _document . setDiagnostics ( diags ) ;
251
274
} catch ( e ) {
252
275
if ( e instanceof ProcessCrashed ) {
276
+ this . _documentProcessManager . processCrashed ( this . _parser . process ) ;
253
277
await this . _recoverFromCrashAsync ( e ) ;
254
278
} else {
255
279
throw e ;
@@ -266,15 +290,17 @@ class DocumentLinter {
266
290
this . _state = DocumentLinterState . RECOVERING ;
267
291
this . _recoveryPromise = ( async ( ) => {
268
292
let diags ;
293
+ let process ;
269
294
try {
270
- let process =
271
- await this . _documentProcessManager . getOrCreateDifferentProcessAsync (
272
- this . _parser . process
273
- ) ;
274
- let parser = await process . createDocumentForVSCodeAsync ( ) ;
295
+ process = await this . _documentProcessManager . getOrCreateProcessAsync ( ) ;
296
+ // BEGIN CRITICAL SECTION (no awaiting below)
297
+ this . _documentProcessManager . checkIfProcessCrashed ( process ) ;
298
+ let parser = process . createDocumentForVSCode ( ) ;
299
+ // END CRITICAL SECTION (no awaiting above)
275
300
276
301
// BEGIN CRITICAL SECTION (no awaiting below)
277
302
assertEqual ( this . _state , DocumentLinterState . RECOVERING ) ;
303
+ this . _documentProcessManager . checkIfProcessCrashed ( process ) ;
278
304
parser . replaceText (
279
305
{
280
306
start : { line : 0 , character : 0 } ,
@@ -287,12 +313,16 @@ class DocumentLinter {
287
313
this . _state = DocumentLinterState . PARSER_LOADED ;
288
314
// END CRITICAL SECTION (no awaiting above)
289
315
316
+ // BEGIN CRITICAL SECTION (no awaiting below)
317
+ this . _documentProcessManager . checkIfProcessCrashed ( process ) ;
290
318
diags = parser . lint ( ) ;
319
+ // END CRITICAL SECTION (no awaiting above)
291
320
} catch ( e ) {
292
321
this . _parser = null ;
293
322
this . _parserPromise = null ;
294
323
this . _state = DocumentLinterState . NO_PARSER ;
295
324
if ( e instanceof ProcessCrashed ) {
325
+ this . _documentProcessManager . processCrashed ( process ) ;
296
326
throw new LintingCrashed ( e ) ;
297
327
} else {
298
328
throw e ;
@@ -315,6 +345,25 @@ class DocumentProcessManager {
315
345
this . _process = null ;
316
346
}
317
347
348
+ processCrashed ( process ) {
349
+ if ( ! ( process instanceof Process ) ) {
350
+ throw new TypeError ( `Expected Process, but got ${ process } ` ) ;
351
+ }
352
+ if ( this . _process === process ) {
353
+ this . _process = null ;
354
+ this . _processPromise = null ;
355
+ }
356
+ }
357
+
358
+ checkIfProcessCrashed ( process ) {
359
+ if ( ! ( process instanceof Process ) ) {
360
+ throw new TypeError ( `Expected Process, but got ${ process } ` ) ;
361
+ }
362
+ if ( this . _process !== process ) {
363
+ throw new ProcessCrashed ( ) ;
364
+ }
365
+ }
366
+
318
367
async createNewProcessAsync ( ) {
319
368
let processFactory = await this . _processFactoryPromise ;
320
369
let process = await processFactory . createProcessAsync ( ) ;
@@ -332,17 +381,6 @@ class DocumentProcessManager {
332
381
return await this . _processPromise ;
333
382
}
334
383
335
- async getOrCreateDifferentProcessAsync ( existingProcess ) {
336
- if ( ! ( existingProcess instanceof Process ) ) {
337
- throw new TypeError ( `Expected Process, but got ${ existingProcess } ` ) ;
338
- }
339
- if ( this . _process !== existingProcess ) {
340
- return this . _process ;
341
- }
342
- this . _forgetCurrentProcess ( ) ;
343
- return await this . getOrCreateProcessAsync ( ) ;
344
- }
345
-
346
384
_forgetCurrentProcess ( ) {
347
385
this . _process = null ;
348
386
this . _processPromise = null ;
@@ -493,7 +531,7 @@ class Process {
493
531
return `Process(id=${ this . _idForDebugging } )` ;
494
532
}
495
533
496
- async createDocumentForVSCodeAsync ( ) {
534
+ createDocumentForVSCode ( ) {
497
535
return new DocumentForVSCode ( this ) ;
498
536
}
499
537
0 commit comments