@@ -41,14 +41,8 @@ exports.LintingCrashed = LintingCrashed;
41
41
class DocumentLinterDisposed extends Error { }
42
42
exports . DocumentLinterDisposed = DocumentLinterDisposed ;
43
43
44
- class DocumentLinter {
45
- // document has the following methods:
46
- //
47
- // getText(): string;
48
- // setDiagnostics(diagnostics: Object[]): void;
49
- // removeDiagnostics(): void;
50
- constructor ( document , documentProcessManager ) {
51
- this . _document = document ;
44
+ class AbstractSyncedDocument {
45
+ constructor ( documentProcessManager ) {
52
46
this . _documentProcessManager = documentProcessManager ;
53
47
this . _state = DocumentLinterState . NO_WASM_DOC ;
54
48
@@ -136,7 +130,6 @@ class DocumentLinter {
136
130
default :
137
131
throw new Error ( `Unexpected linter state: ${ this . _state } ` ) ;
138
132
}
139
- this . _document . removeDiagnostics ( ) ;
140
133
}
141
134
142
135
async editorChangedVisibilityAsync ( ) {
@@ -196,8 +189,7 @@ class DocumentLinter {
196
189
this . _pendingChanges . length = 0 ;
197
190
// END CRITICAL SECTION (no awaiting above)
198
191
199
- let diags = this . _wasmDoc . lint ( ) ;
200
- this . _document . setDiagnostics ( diags ) ;
192
+ this . _documentSynced ( ) ;
201
193
} catch ( e ) {
202
194
// END CRITICAL SECTION (no awaiting above)
203
195
if ( e instanceof ProcessCrashed ) {
@@ -234,14 +226,13 @@ class DocumentLinter {
234
226
start : { line : 0 , character : 0 } ,
235
227
end : { line : 0 , character : 0 } ,
236
228
} ,
237
- this . _document . getText ( )
229
+ this . _getText ( )
238
230
) ;
239
231
this . _pendingChanges . length = 0 ;
240
232
this . _state = DocumentLinterState . WASM_DOC_LOADED ;
241
233
// END CRITICAL SECTION (no awaiting above)
242
234
243
- let diags = this . _wasmDoc . lint ( ) ;
244
- this . _document . setDiagnostics ( diags ) ;
235
+ this . _documentSynced ( ) ;
245
236
} catch ( e ) {
246
237
if ( e instanceof ProcessCrashed ) {
247
238
await this . _recoverFromCrashAsync ( e ) ;
@@ -272,14 +263,14 @@ class DocumentLinter {
272
263
start : { line : 0 , character : 0 } ,
273
264
end : { line : 0 , character : 0 } ,
274
265
} ,
275
- this . _document . getText ( )
266
+ this . _getText ( )
276
267
) ;
277
268
this . _pendingChanges . length = 0 ;
278
269
this . _wasmDoc = wasmDoc ;
279
270
this . _state = DocumentLinterState . WASM_DOC_LOADED ;
280
271
// END CRITICAL SECTION (no awaiting above)
281
272
282
- diags = wasmDoc . lint ( ) ;
273
+ this . _documentSynced ( ) ;
283
274
} catch ( e ) {
284
275
this . _wasmDoc = null ;
285
276
this . _wasmDocPromise = null ;
@@ -290,11 +281,49 @@ class DocumentLinter {
290
281
throw e ;
291
282
}
292
283
}
293
- this . _document . setDiagnostics ( diags ) ;
294
284
} ) ( ) ;
295
285
// END CRITICAL SECTION (no awaiting above)
296
286
await this . _recoveryPromise ;
297
287
}
288
+
289
+ // Abstract:
290
+ _getText ( ) {
291
+ throw new Error ( "Please override _getText in a derived class" ) ;
292
+ }
293
+
294
+ // Abstract:
295
+ _documentSynced ( ) {
296
+ throw new Error ( "Please override _documentSynced in a derived class" ) ;
297
+ }
298
+ }
299
+
300
+ class DocumentLinter extends AbstractSyncedDocument {
301
+ // document has the following methods:
302
+ //
303
+ // getText(): string;
304
+ // setDiagnostics(diagnostics: Object[]): void;
305
+ // removeDiagnostics(): void;
306
+ constructor ( document , documentProcessManager ) {
307
+ super ( documentProcessManager ) ;
308
+ this . _document = document ;
309
+ }
310
+
311
+ // Override:
312
+ _getText ( ) {
313
+ return this . _document . getText ( ) ;
314
+ }
315
+
316
+ // Override:
317
+ _documentSynced ( ) {
318
+ let diags = this . _wasmDoc . lint ( ) ;
319
+ this . _document . setDiagnostics ( diags ) ;
320
+ }
321
+
322
+ // Override:
323
+ async disposeAsync ( ) {
324
+ await super . disposeAsync ( ) ;
325
+ this . _document . removeDiagnostics ( ) ;
326
+ }
298
327
}
299
328
exports . DocumentLinter = DocumentLinter ;
300
329
0 commit comments