Skip to content

Commit 9ccf6cc

Browse files
committed
wasm: rename parser -> wasmDoc
The name 'parser' is used for DocumentForVSCode instances. This is confusing. Rename 'parser' to 'WASM doc' to relate it to DocumentForVSCode (but disassociate it from VS Code's Document class). This commit should not change behavior.
1 parent 7d4888a commit 9ccf6cc

File tree

1 file changed

+72
-72
lines changed

1 file changed

+72
-72
lines changed

wasm/quick-lint-js.js

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ let VSCODE_WASM_MODULE_PATH = "./dist/quick-lint-js-vscode.wasm";
99

1010
let DocumentLinterState = {
1111
// A DocumentForVSCode hasn't been created yet.
12-
NO_PARSER: "NO_PARSER",
12+
NO_WASM_DOC: "NO_WASM_DOC",
1313

1414
// A DocumentForVSCode is in the process of being created.
15-
CREATING_PARSER: "CREATING_PARSER",
15+
CREATING_WASM_DOC: "CREATING_WASM_DOC",
1616

1717
// A DocumentForVSCode has been created, but it has no text.
18-
PARSER_UNINITIALIZED: "PARSER_UNINITIALIZED",
18+
WASM_DOC_UNINITIALIZED: "WASM_DOC_UNINITIALIZED",
1919

2020
// A DocumentForVSCode has been created, and its text is up-to-date with the
2121
// vscode.Document.
22-
PARSER_LOADED: "PARSER_LOADED",
22+
WASM_DOC_LOADED: "WASM_DOC_LOADED",
2323

2424
// The DocumentForVSCode's Process crashed, and we are creating a new Process
2525
// and DocumentForVSCode.
@@ -50,30 +50,30 @@ class DocumentLinter {
5050
constructor(document, documentProcessManager) {
5151
this._document = document;
5252
this._documentProcessManager = documentProcessManager;
53-
this._state = DocumentLinterState.NO_PARSER;
53+
this._state = DocumentLinterState.NO_WASM_DOC;
5454

55-
// Used only in states: CREATING_PARSER
56-
this._parserPromise = null;
55+
// Used only in states: CREATING_WASM_DOC
56+
this._wasmDocPromise = null;
5757

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;
6060

61-
// Used only in states: PARSER_LOADED, RECOVERING
61+
// Used only in states: WASM_DOC_LOADED, RECOVERING
6262
this._pendingChanges = [];
6363

6464
// Used only in states: RECOVERING
6565
this._recoveryPromise = null;
6666
}
6767

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 () => {
7272
let process;
73-
let parser;
73+
let wasmDoc;
7474
try {
7575
process = await this._documentProcessManager.getOrCreateProcessAsync();
76-
parser = process.createDocumentForVSCode();
76+
wasmDoc = process.createDocumentForVSCode();
7777
} catch (e) {
7878
if (e instanceof ProcessCrashed) {
7979
throw new LintingCrashed(e);
@@ -83,29 +83,29 @@ class DocumentLinter {
8383
}
8484

8585
if (this._state === DocumentLinterState.DISPOSED) {
86-
parser.dispose();
86+
wasmDoc.dispose();
8787
throw new DocumentLinterDisposed();
8888
}
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;
9393
})();
94-
return await this._parserPromise;
94+
return await this._wasmDocPromise;
9595
}
9696

9797
async disposeAsync() {
9898
let oldState = this._state;
9999
this._state = DocumentLinterState.DISPOSED;
100100
switch (oldState) {
101-
case DocumentLinterState.NO_PARSER:
101+
case DocumentLinterState.NO_WASM_DOC:
102102
break;
103103

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: {
107107
try {
108-
await this._parserPromise;
108+
await this._wasmDocPromise;
109109
} catch (e) {
110110
if (e instanceof DocumentLinterDisposed) {
111111
// Ignore.
@@ -115,9 +115,9 @@ class DocumentLinter {
115115
throw e;
116116
}
117117
}
118-
if (this._parser !== null) {
118+
if (this._wasmDoc !== null) {
119119
try {
120-
this._parser.dispose();
120+
this._wasmDoc.dispose();
121121
} catch (e) {
122122
if (e instanceof ProcessCrashed) {
123123
// Ignore.
@@ -147,21 +147,21 @@ class DocumentLinter {
147147

148148
async editorChangedVisibilityAsync() {
149149
switch (this._state) {
150-
case DocumentLinterState.NO_PARSER:
151-
await this._createParser();
150+
case DocumentLinterState.NO_WASM_DOC:
151+
await this._createWASMDoc();
152152
await this.editorChangedVisibilityAsync();
153153
break;
154154

155-
case DocumentLinterState.CREATING_PARSER:
156-
await this._parserPromise;
155+
case DocumentLinterState.CREATING_WASM_DOC:
156+
await this._wasmDocPromise;
157157
await this.editorChangedVisibilityAsync();
158158
break;
159159

160-
case DocumentLinterState.PARSER_UNINITIALIZED:
161-
await this._initializeParserAsync();
160+
case DocumentLinterState.WASM_DOC_UNINITIALIZED:
161+
await this._initializeWASMDocAsync();
162162
break;
163163

164-
case DocumentLinterState.PARSER_LOADED:
164+
case DocumentLinterState.WASM_DOC_LOADED:
165165
// No changes could have been made with the editor closed. Ignore.
166166
break;
167167

@@ -176,33 +176,33 @@ class DocumentLinter {
176176
async textChangedAsync(changes) {
177177
// BEGIN CRITICAL SECTION (no awaiting below)
178178
switch (this._state) {
179-
case DocumentLinterState.NO_PARSER:
179+
case DocumentLinterState.NO_WASM_DOC:
180180
// END CRITICAL SECTION (no awaiting above)
181-
await this._createParser();
182-
await this._initializeParserAsync();
181+
await this._createWASMDoc();
182+
await this._initializeWASMDocAsync();
183183
break;
184184

185-
case DocumentLinterState.CREATING_PARSER:
185+
case DocumentLinterState.CREATING_WASM_DOC:
186186
// END CRITICAL SECTION (no awaiting above)
187-
await this._parserPromise;
188-
await this._initializeParserAsync();
187+
await this._wasmDocPromise;
188+
await this._initializeWASMDocAsync();
189189
break;
190190

191-
case DocumentLinterState.PARSER_UNINITIALIZED:
191+
case DocumentLinterState.WASM_DOC_UNINITIALIZED:
192192
// END CRITICAL SECTION (no awaiting above)
193-
await this._initializeParserAsync();
193+
await this._initializeWASMDocAsync();
194194
break;
195195

196-
case DocumentLinterState.PARSER_LOADED:
196+
case DocumentLinterState.WASM_DOC_LOADED:
197197
this._pendingChanges.push(...changes);
198198
try {
199199
for (let change of this._pendingChanges) {
200-
this._parser.replaceText(change.range, change.text);
200+
this._wasmDoc.replaceText(change.range, change.text);
201201
}
202202
this._pendingChanges.length = 0;
203203
// END CRITICAL SECTION (no awaiting above)
204204

205-
let diags = this._parser.lint();
205+
let diags = this._wasmDoc.lint();
206206
this._document.setDiagnostics(diags);
207207
} catch (e) {
208208
// END CRITICAL SECTION (no awaiting above)
@@ -230,23 +230,23 @@ class DocumentLinter {
230230
}
231231
}
232232

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() {
235235
// BEGIN CRITICAL SECTION (no awaiting below)
236-
assertEqual(this._state, DocumentLinterState.PARSER_UNINITIALIZED);
236+
assertEqual(this._state, DocumentLinterState.WASM_DOC_UNINITIALIZED);
237237
try {
238-
this._parser.replaceText(
238+
this._wasmDoc.replaceText(
239239
{
240240
start: { line: 0, character: 0 },
241241
end: { line: 0, character: 0 },
242242
},
243243
this._document.getText()
244244
);
245245
this._pendingChanges.length = 0;
246-
this._state = DocumentLinterState.PARSER_LOADED;
246+
this._state = DocumentLinterState.WASM_DOC_LOADED;
247247
// END CRITICAL SECTION (no awaiting above)
248248

249-
let diags = this._parser.lint();
249+
let diags = this._wasmDoc.lint();
250250
this._document.setDiagnostics(diags);
251251
} catch (e) {
252252
if (e instanceof ProcessCrashed) {
@@ -257,7 +257,7 @@ class DocumentLinter {
257257
}
258258
}
259259

260-
// Transition: any -> RECOVERING -> PARSER_LOADED (or NO_PARSER on error)
260+
// Transition: any -> RECOVERING -> WASM_DOC_LOADED (or NO_WASM_DOC on error)
261261
async _recoverFromCrashAsync(error) {
262262
// BEGIN CRITICAL SECTION (no awaiting below)
263263
console.warn(
@@ -269,27 +269,27 @@ class DocumentLinter {
269269
let process;
270270
try {
271271
process = await this._documentProcessManager.getOrCreateProcessAsync();
272-
let parser = process.createDocumentForVSCode();
272+
let wasmDoc = process.createDocumentForVSCode();
273273

274274
// BEGIN CRITICAL SECTION (no awaiting below)
275275
assertEqual(this._state, DocumentLinterState.RECOVERING);
276-
parser.replaceText(
276+
wasmDoc.replaceText(
277277
{
278278
start: { line: 0, character: 0 },
279279
end: { line: 0, character: 0 },
280280
},
281281
this._document.getText()
282282
);
283283
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;
286286
// END CRITICAL SECTION (no awaiting above)
287287

288-
diags = parser.lint();
288+
diags = wasmDoc.lint();
289289
} 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;
293293
if (e instanceof ProcessCrashed) {
294294
throw new LintingCrashed(e);
295295
} else {
@@ -529,14 +529,14 @@ class Process {
529529
class DocumentForVSCode {
530530
constructor(process) {
531531
this._process = process;
532-
this._parser = this._process._vscodeCreateDocument();
532+
this._wasmDoc = this._process._vscodeCreateDocument();
533533
}
534534

535535
replaceText(range, replacementText) {
536536
let utf8ReplacementText = encodeUTF8String(replacementText, this._process);
537537
try {
538538
this._process._vscodeReplaceText(
539-
this._parser,
539+
this._wasmDoc,
540540
range.start.line,
541541
range.start.character,
542542
range.end.line,
@@ -556,7 +556,7 @@ class DocumentForVSCode {
556556
}
557557

558558
lint() {
559-
let diagnosticsPointer = this._process._vscodeLint(this._parser);
559+
let diagnosticsPointer = this._process._vscodeLint(this._wasmDoc);
560560

561561
let rawDiagnosticsU32 = new Uint32Array(
562562
this._process._heap,
@@ -612,8 +612,8 @@ class DocumentForVSCode {
612612
}
613613

614614
dispose() {
615-
this._process._vscodeDestroyDocument(this._parser);
616-
this._parser = null;
615+
this._process._vscodeDestroyDocument(this._wasmDoc);
616+
this._wasmDoc = null;
617617
}
618618

619619
get process() {
@@ -624,14 +624,14 @@ class DocumentForVSCode {
624624
class DocumentForWebDemo {
625625
constructor(process) {
626626
this._process = process;
627-
this._parser = this._process._webDemoCreateDocument();
627+
this._wasmDoc = this._process._webDemoCreateDocument();
628628
}
629629

630630
setText(text) {
631631
let utf8Text = encodeUTF8String(text, this._process);
632632
try {
633633
this._process._webDemoSetText(
634-
this._parser,
634+
this._wasmDoc,
635635
utf8Text.pointer,
636636
utf8Text.byteSize
637637
);
@@ -641,7 +641,7 @@ class DocumentForWebDemo {
641641
}
642642

643643
lint() {
644-
let diagnosticsPointer = this._process._webDemoLint(this._parser);
644+
let diagnosticsPointer = this._process._webDemoLint(this._wasmDoc);
645645

646646
let rawDiagnosticsU32 = new Uint32Array(
647647
this._process._heap,
@@ -689,8 +689,8 @@ class DocumentForWebDemo {
689689
}
690690

691691
dispose() {
692-
this._process._webDemoDestroyDocument(this._parser);
693-
this._parser = null;
692+
this._process._webDemoDestroyDocument(this._wasmDoc);
693+
this._wasmDoc = null;
694694
}
695695
}
696696

0 commit comments

Comments
 (0)