@@ -9,17 +9,17 @@ let VSCODE_WASM_MODULE_PATH = "./dist/quick-lint-js-vscode.wasm";
9
9
10
10
let DocumentLinterState = {
11
11
// A DocumentForVSCode hasn't been created yet.
12
- NO_PARSER : "NO_PARSER " ,
12
+ NO_WASM_DOC : "NO_WASM_DOC " ,
13
13
14
14
// A DocumentForVSCode is in the process of being created.
15
- CREATING_PARSER : "CREATING_PARSER " ,
15
+ CREATING_WASM_DOC : "CREATING_WASM_DOC " ,
16
16
17
17
// A DocumentForVSCode has been created, but it has no text.
18
- PARSER_UNINITIALIZED : "PARSER_UNINITIALIZED " ,
18
+ WASM_DOC_UNINITIALIZED : "WASM_DOC_UNINITIALIZED " ,
19
19
20
20
// A DocumentForVSCode has been created, and its text is up-to-date with the
21
21
// vscode.Document.
22
- PARSER_LOADED : "PARSER_LOADED " ,
22
+ WASM_DOC_LOADED : "WASM_DOC_LOADED " ,
23
23
24
24
// The DocumentForVSCode's Process crashed, and we are creating a new Process
25
25
// and DocumentForVSCode.
@@ -50,30 +50,30 @@ class DocumentLinter {
50
50
constructor ( document , documentProcessManager ) {
51
51
this . _document = document ;
52
52
this . _documentProcessManager = documentProcessManager ;
53
- this . _state = DocumentLinterState . NO_PARSER ;
53
+ this . _state = DocumentLinterState . NO_WASM_DOC ;
54
54
55
- // Used only in states: CREATING_PARSER
56
- this . _parserPromise = null ;
55
+ // Used only in states: CREATING_WASM_DOC
56
+ this . _wasmDocPromise = null ;
57
57
58
- // Used only in states: PARSER_UNINITIALIZED, PARSER_LOADED
59
- this . _parser = null ;
58
+ // Used only in states: WASM_DOC_UNINITIALIZED, WASM_DOC_LOADED
59
+ this . _wasmDoc = null ;
60
60
61
- // Used only in states: PARSER_LOADED , RECOVERING
61
+ // Used only in states: WASM_DOC_LOADED , RECOVERING
62
62
this . _pendingChanges = [ ] ;
63
63
64
64
// Used only in states: RECOVERING
65
65
this . _recoveryPromise = null ;
66
66
}
67
67
68
- async _createParser ( ) {
69
- assertEqual ( this . _state , DocumentLinterState . NO_PARSER ) ;
70
- this . _state = DocumentLinterState . CREATING_PARSER ;
71
- this . _parserPromise = ( async ( ) => {
68
+ async _createWASMDoc ( ) {
69
+ assertEqual ( this . _state , DocumentLinterState . NO_WASM_DOC ) ;
70
+ this . _state = DocumentLinterState . CREATING_WASM_DOC ;
71
+ this . _wasmDocPromise = ( async ( ) => {
72
72
let process ;
73
- let parser ;
73
+ let wasmDoc ;
74
74
try {
75
75
process = await this . _documentProcessManager . getOrCreateProcessAsync ( ) ;
76
- parser = process . createDocumentForVSCode ( ) ;
76
+ wasmDoc = process . createDocumentForVSCode ( ) ;
77
77
} catch ( e ) {
78
78
if ( e instanceof ProcessCrashed ) {
79
79
throw new LintingCrashed ( e ) ;
@@ -83,29 +83,29 @@ class DocumentLinter {
83
83
}
84
84
85
85
if ( this . _state === DocumentLinterState . DISPOSED ) {
86
- parser . dispose ( ) ;
86
+ wasmDoc . dispose ( ) ;
87
87
throw new DocumentLinterDisposed ( ) ;
88
88
}
89
- assertEqual ( this . _state , DocumentLinterState . CREATING_PARSER ) ;
90
- this . _parser = parser ;
91
- this . _state = DocumentLinterState . PARSER_UNINITIALIZED ;
92
- return parser ;
89
+ assertEqual ( this . _state , DocumentLinterState . CREATING_WASM_DOC ) ;
90
+ this . _wasmDoc = wasmDoc ;
91
+ this . _state = DocumentLinterState . WASM_DOC_UNINITIALIZED ;
92
+ return wasmDoc ;
93
93
} ) ( ) ;
94
- return await this . _parserPromise ;
94
+ return await this . _wasmDocPromise ;
95
95
}
96
96
97
97
async disposeAsync ( ) {
98
98
let oldState = this . _state ;
99
99
this . _state = DocumentLinterState . DISPOSED ;
100
100
switch ( oldState ) {
101
- case DocumentLinterState . NO_PARSER :
101
+ case DocumentLinterState . NO_WASM_DOC :
102
102
break ;
103
103
104
- case DocumentLinterState . CREATING_PARSER :
105
- case DocumentLinterState . PARSER_UNINITIALIZED :
106
- case DocumentLinterState . PARSER_LOADED : {
104
+ case DocumentLinterState . CREATING_WASM_DOC :
105
+ case DocumentLinterState . WASM_DOC_UNINITIALIZED :
106
+ case DocumentLinterState . WASM_DOC_LOADED : {
107
107
try {
108
- await this . _parserPromise ;
108
+ await this . _wasmDocPromise ;
109
109
} catch ( e ) {
110
110
if ( e instanceof DocumentLinterDisposed ) {
111
111
// Ignore.
@@ -115,9 +115,9 @@ class DocumentLinter {
115
115
throw e ;
116
116
}
117
117
}
118
- if ( this . _parser !== null ) {
118
+ if ( this . _wasmDoc !== null ) {
119
119
try {
120
- this . _parser . dispose ( ) ;
120
+ this . _wasmDoc . dispose ( ) ;
121
121
} catch ( e ) {
122
122
if ( e instanceof ProcessCrashed ) {
123
123
// Ignore.
@@ -147,21 +147,21 @@ class DocumentLinter {
147
147
148
148
async editorChangedVisibilityAsync ( ) {
149
149
switch ( this . _state ) {
150
- case DocumentLinterState . NO_PARSER :
151
- await this . _createParser ( ) ;
150
+ case DocumentLinterState . NO_WASM_DOC :
151
+ await this . _createWASMDoc ( ) ;
152
152
await this . editorChangedVisibilityAsync ( ) ;
153
153
break ;
154
154
155
- case DocumentLinterState . CREATING_PARSER :
156
- await this . _parserPromise ;
155
+ case DocumentLinterState . CREATING_WASM_DOC :
156
+ await this . _wasmDocPromise ;
157
157
await this . editorChangedVisibilityAsync ( ) ;
158
158
break ;
159
159
160
- case DocumentLinterState . PARSER_UNINITIALIZED :
161
- await this . _initializeParserAsync ( ) ;
160
+ case DocumentLinterState . WASM_DOC_UNINITIALIZED :
161
+ await this . _initializeWASMDocAsync ( ) ;
162
162
break ;
163
163
164
- case DocumentLinterState . PARSER_LOADED :
164
+ case DocumentLinterState . WASM_DOC_LOADED :
165
165
// No changes could have been made with the editor closed. Ignore.
166
166
break ;
167
167
@@ -176,33 +176,33 @@ class DocumentLinter {
176
176
async textChangedAsync ( changes ) {
177
177
// BEGIN CRITICAL SECTION (no awaiting below)
178
178
switch ( this . _state ) {
179
- case DocumentLinterState . NO_PARSER :
179
+ case DocumentLinterState . NO_WASM_DOC :
180
180
// END CRITICAL SECTION (no awaiting above)
181
- await this . _createParser ( ) ;
182
- await this . _initializeParserAsync ( ) ;
181
+ await this . _createWASMDoc ( ) ;
182
+ await this . _initializeWASMDocAsync ( ) ;
183
183
break ;
184
184
185
- case DocumentLinterState . CREATING_PARSER :
185
+ case DocumentLinterState . CREATING_WASM_DOC :
186
186
// END CRITICAL SECTION (no awaiting above)
187
- await this . _parserPromise ;
188
- await this . _initializeParserAsync ( ) ;
187
+ await this . _wasmDocPromise ;
188
+ await this . _initializeWASMDocAsync ( ) ;
189
189
break ;
190
190
191
- case DocumentLinterState . PARSER_UNINITIALIZED :
191
+ case DocumentLinterState . WASM_DOC_UNINITIALIZED :
192
192
// END CRITICAL SECTION (no awaiting above)
193
- await this . _initializeParserAsync ( ) ;
193
+ await this . _initializeWASMDocAsync ( ) ;
194
194
break ;
195
195
196
- case DocumentLinterState . PARSER_LOADED :
196
+ case DocumentLinterState . WASM_DOC_LOADED :
197
197
this . _pendingChanges . push ( ...changes ) ;
198
198
try {
199
199
for ( let change of this . _pendingChanges ) {
200
- this . _parser . replaceText ( change . range , change . text ) ;
200
+ this . _wasmDoc . replaceText ( change . range , change . text ) ;
201
201
}
202
202
this . _pendingChanges . length = 0 ;
203
203
// END CRITICAL SECTION (no awaiting above)
204
204
205
- let diags = this . _parser . lint ( ) ;
205
+ let diags = this . _wasmDoc . lint ( ) ;
206
206
this . _document . setDiagnostics ( diags ) ;
207
207
} catch ( e ) {
208
208
// END CRITICAL SECTION (no awaiting above)
@@ -230,23 +230,23 @@ class DocumentLinter {
230
230
}
231
231
}
232
232
233
- // Transition: PARSER_UNINITIALIZED -> PARSER_LOADED (or NO_PARSER on error)
234
- async _initializeParserAsync ( ) {
233
+ // Transition: WASM_DOC_UNINITIALIZED -> WASM_DOC_LOADED (or NO_WASM_DOC on error)
234
+ async _initializeWASMDocAsync ( ) {
235
235
// BEGIN CRITICAL SECTION (no awaiting below)
236
- assertEqual ( this . _state , DocumentLinterState . PARSER_UNINITIALIZED ) ;
236
+ assertEqual ( this . _state , DocumentLinterState . WASM_DOC_UNINITIALIZED ) ;
237
237
try {
238
- this . _parser . replaceText (
238
+ this . _wasmDoc . replaceText (
239
239
{
240
240
start : { line : 0 , character : 0 } ,
241
241
end : { line : 0 , character : 0 } ,
242
242
} ,
243
243
this . _document . getText ( )
244
244
) ;
245
245
this . _pendingChanges . length = 0 ;
246
- this . _state = DocumentLinterState . PARSER_LOADED ;
246
+ this . _state = DocumentLinterState . WASM_DOC_LOADED ;
247
247
// END CRITICAL SECTION (no awaiting above)
248
248
249
- let diags = this . _parser . lint ( ) ;
249
+ let diags = this . _wasmDoc . lint ( ) ;
250
250
this . _document . setDiagnostics ( diags ) ;
251
251
} catch ( e ) {
252
252
if ( e instanceof ProcessCrashed ) {
@@ -257,7 +257,7 @@ class DocumentLinter {
257
257
}
258
258
}
259
259
260
- // Transition: any -> RECOVERING -> PARSER_LOADED (or NO_PARSER on error)
260
+ // Transition: any -> RECOVERING -> WASM_DOC_LOADED (or NO_WASM_DOC on error)
261
261
async _recoverFromCrashAsync ( error ) {
262
262
// BEGIN CRITICAL SECTION (no awaiting below)
263
263
console . warn (
@@ -269,27 +269,27 @@ class DocumentLinter {
269
269
let process ;
270
270
try {
271
271
process = await this . _documentProcessManager . getOrCreateProcessAsync ( ) ;
272
- let parser = process . createDocumentForVSCode ( ) ;
272
+ let wasmDoc = process . createDocumentForVSCode ( ) ;
273
273
274
274
// BEGIN CRITICAL SECTION (no awaiting below)
275
275
assertEqual ( this . _state , DocumentLinterState . RECOVERING ) ;
276
- parser . replaceText (
276
+ wasmDoc . replaceText (
277
277
{
278
278
start : { line : 0 , character : 0 } ,
279
279
end : { line : 0 , character : 0 } ,
280
280
} ,
281
281
this . _document . getText ( )
282
282
) ;
283
283
this . _pendingChanges . length = 0 ;
284
- this . _parser = parser ;
285
- this . _state = DocumentLinterState . PARSER_LOADED ;
284
+ this . _wasmDoc = wasmDoc ;
285
+ this . _state = DocumentLinterState . WASM_DOC_LOADED ;
286
286
// END CRITICAL SECTION (no awaiting above)
287
287
288
- diags = parser . lint ( ) ;
288
+ diags = wasmDoc . lint ( ) ;
289
289
} catch ( e ) {
290
- this . _parser = null ;
291
- this . _parserPromise = null ;
292
- this . _state = DocumentLinterState . NO_PARSER ;
290
+ this . _wasmDoc = null ;
291
+ this . _wasmDocPromise = null ;
292
+ this . _state = DocumentLinterState . NO_WASM_DOC ;
293
293
if ( e instanceof ProcessCrashed ) {
294
294
throw new LintingCrashed ( e ) ;
295
295
} else {
@@ -529,14 +529,14 @@ class Process {
529
529
class DocumentForVSCode {
530
530
constructor ( process ) {
531
531
this . _process = process ;
532
- this . _parser = this . _process . _vscodeCreateDocument ( ) ;
532
+ this . _wasmDoc = this . _process . _vscodeCreateDocument ( ) ;
533
533
}
534
534
535
535
replaceText ( range , replacementText ) {
536
536
let utf8ReplacementText = encodeUTF8String ( replacementText , this . _process ) ;
537
537
try {
538
538
this . _process . _vscodeReplaceText (
539
- this . _parser ,
539
+ this . _wasmDoc ,
540
540
range . start . line ,
541
541
range . start . character ,
542
542
range . end . line ,
@@ -556,7 +556,7 @@ class DocumentForVSCode {
556
556
}
557
557
558
558
lint ( ) {
559
- let diagnosticsPointer = this . _process . _vscodeLint ( this . _parser ) ;
559
+ let diagnosticsPointer = this . _process . _vscodeLint ( this . _wasmDoc ) ;
560
560
561
561
let rawDiagnosticsU32 = new Uint32Array (
562
562
this . _process . _heap ,
@@ -612,8 +612,8 @@ class DocumentForVSCode {
612
612
}
613
613
614
614
dispose ( ) {
615
- this . _process . _vscodeDestroyDocument ( this . _parser ) ;
616
- this . _parser = null ;
615
+ this . _process . _vscodeDestroyDocument ( this . _wasmDoc ) ;
616
+ this . _wasmDoc = null ;
617
617
}
618
618
619
619
get process ( ) {
@@ -624,14 +624,14 @@ class DocumentForVSCode {
624
624
class DocumentForWebDemo {
625
625
constructor ( process ) {
626
626
this . _process = process ;
627
- this . _parser = this . _process . _webDemoCreateDocument ( ) ;
627
+ this . _wasmDoc = this . _process . _webDemoCreateDocument ( ) ;
628
628
}
629
629
630
630
setText ( text ) {
631
631
let utf8Text = encodeUTF8String ( text , this . _process ) ;
632
632
try {
633
633
this . _process . _webDemoSetText (
634
- this . _parser ,
634
+ this . _wasmDoc ,
635
635
utf8Text . pointer ,
636
636
utf8Text . byteSize
637
637
) ;
@@ -641,7 +641,7 @@ class DocumentForWebDemo {
641
641
}
642
642
643
643
lint ( ) {
644
- let diagnosticsPointer = this . _process . _webDemoLint ( this . _parser ) ;
644
+ let diagnosticsPointer = this . _process . _webDemoLint ( this . _wasmDoc ) ;
645
645
646
646
let rawDiagnosticsU32 = new Uint32Array (
647
647
this . _process . _heap ,
@@ -689,8 +689,8 @@ class DocumentForWebDemo {
689
689
}
690
690
691
691
dispose ( ) {
692
- this . _process . _webDemoDestroyDocument ( this . _parser ) ;
693
- this . _parser = null ;
692
+ this . _process . _webDemoDestroyDocument ( this . _wasmDoc ) ;
693
+ this . _wasmDoc = null ;
694
694
}
695
695
}
696
696
0 commit comments