@arcgis/coding-components 4.29.0-beta.74 → 4.29.0-beta.76

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,596 +0,0 @@
1
- import { o as main, e as editor, M as MarkerSeverity, R as Range, l as languages, E as Emitter } from './arcade-defaults-7106421e.js';
2
- import './index-022fb97b.js';
3
-
4
- var fe=(e=>(e.False="false",e.Null="null",e.True="true",e))(fe||{}),ge=(e=>(e.Break="break",e.Continue="continue",e.Else="else",e.For="for",e.From="from",e.Function="function",e.If="if",e.Import="import",e.Export="export",e.In="in",e.Return="return",e.Var="var",e.While="while",e))(ge||{}),c=(e=>(e.AssignmentExpression="AssignmentExpression",e.ArrayExpression="ArrayExpression",e.BlockComment="BlockComment",e.BlockStatement="BlockStatement",e.BinaryExpression="BinaryExpression",e.BreakStatement="BreakStatement",e.CallExpression="CallExpression",e.ContinueStatement="ContinueStatement",e.EmptyStatement="EmptyStatement",e.ExpressionStatement="ExpressionStatement",e.ExportNamedDeclaration="ExportNamedDeclaration",e.ExportSpecifier="ExportSpecifier",e.ForStatement="ForStatement",e.ForInStatement="ForInStatement",e.FunctionDeclaration="FunctionDeclaration",e.Identifier="Identifier",e.IfStatement="IfStatement",e.ImportDeclaration="ImportDeclaration",e.ImportDefaultSpecifier="ImportDefaultSpecifier",e.LineComment="LineComment",e.Literal="Literal",e.LogicalExpression="LogicalExpression",e.MemberExpression="MemberExpression",e.ObjectExpression="ObjectExpression",e.Program="Program",e.Property="Property",e.ReturnStatement="ReturnStatement",e.TemplateElement="TemplateElement",e.TemplateLiteral="TemplateLiteral",e.UnaryExpression="UnaryExpression",e.UpdateExpression="UpdateExpression",e.VariableDeclaration="VariableDeclaration",e.VariableDeclarator="VariableDeclarator",e.WhileStatement="WhileStatement",e))(c||{}),me=["++","--"],We=["-","+","!","~"],qe=["=","/=","*=","%=","+=","-="],He=["||","&&"],Pt=["|","&",">>","<<",">>>","^","==","!=","<","<=",">",">=","+","-","*","/","%"],bt=(e=>(e[e.Unknown=0]="Unknown",e[e.BooleanLiteral=1]="BooleanLiteral",e[e.EOF=2]="EOF",e[e.Identifier=3]="Identifier",e[e.Keyword=4]="Keyword",e[e.NullLiteral=5]="NullLiteral",e[e.NumericLiteral=6]="NumericLiteral",e[e.Punctuator=7]="Punctuator",e[e.StringLiteral=8]="StringLiteral",e[e.Template=10]="Template",e))(bt||{}),It=(e=>(e.InvalidModuleUri="InvalidModuleUri",e.ForInOfLoopInitializer="ForInOfLoopInitializer",e.IdentiferExpected="IdentiferExpected",e.InvalidEscapedReservedWord="InvalidEscapedReservedWord",e.InvalidExpression="InvalidExpression",e.InvalidFunctionIdentifier="InvalidFunctionIdentifier",e.InvalidHexEscapeSequence="InvalidHexEscapeSequence",e.InvalidLeftHandSideInAssignment="InvalidLeftHandSideInAssignment",e.InvalidLeftHandSideInForIn="InvalidLeftHandSideInForIn",e.InvalidTemplateHead="InvalidTemplateHead",e.InvalidVariableAssignment="InvalidVariableAssignment",e.KeyMustBeString="KeyMustBeString",e.NoFunctionInsideBlock="NoFunctionInsideBlock",e.NoFunctionInsideFunction="NoFunctionInsideFunction",e.ModuleExportRootOnly="ModuleExportRootOnly",e.ModuleImportRootOnly="ModuleImportRootOnly",e.PunctuatorExpected="PunctuatorExpected",e.TemplateOctalLiteral="TemplateOctalLiteral",e.UnexpectedBoolean="UnexpectedBoolean",e.UnexpectedEndOfScript="UnexpectedEndOfScript",e.UnexpectedIdentifier="UnexpectedIdentifier",e.UnexpectedKeyword="UnexpectedKeyword",e.UnexpectedNull="UnexpectedNull",e.UnexpectedNumber="UnexpectedNumber",e.UnexpectedPunctuator="UnexpectedPunctuator",e.UnexpectedString="UnexpectedString",e.UnexpectedTemplate="UnexpectedTemplate",e.UnexpectedToken="UnexpectedToken",e))(It||{});var L=[[],[],[]];me.forEach(e=>L[e.length-1].push(e));We.forEach(e=>L[e.length-1].push(e));He.forEach(e=>L[e.length-1].push(e));qe.forEach(e=>L[e.length-1].push(e));Pt.forEach(e=>L[e.length-1].push(e));var nt=Object.values(ge),st=Object.values(fe);st.map(e=>({label:e,kind:main.CompletionItemKind.Constant}));nt.map(e=>({label:e,kind:main.CompletionItemKind.Keyword}));
5
-
6
- const operators = [
7
- "<=",
8
- ">=",
9
- "==",
10
- "!=",
11
- "+",
12
- "-",
13
- "*",
14
- "/",
15
- "%",
16
- "++",
17
- "--",
18
- "<<",
19
- ">>",
20
- ">>>",
21
- "&",
22
- "|",
23
- "^",
24
- "!",
25
- "~",
26
- "&&",
27
- "||",
28
- "=",
29
- "+=",
30
- "-=",
31
- "*=",
32
- "**=",
33
- "/=",
34
- "%="
35
- ];
36
- const arcadeLanguageConfiguration = {
37
- // the default separators except `@$`
38
- wordPattern: /(-?\d*\.\d\w*)|([^`~!#%\^&\*\(\)\-=\+\[\{\]\}\\\|;:'",\.<>\/\?\s]+)/gu,
39
- comments: {
40
- lineComment: "//",
41
- blockComment: ["/*", "*/"]
42
- },
43
- brackets: [
44
- ["{", "}"],
45
- ["[", "]"],
46
- ["(", ")"]
47
- ],
48
- autoClosingPairs: [
49
- { open: "{", close: "}" },
50
- { open: "[", close: "]" },
51
- { open: "(", close: ")" },
52
- { open: '"', close: '"', notIn: ["string"] },
53
- { open: "'", close: "'", notIn: ["string", "comment"] },
54
- { open: "`", close: "`", notIn: ["string", "comment"] }
55
- ],
56
- autoCloseBefore: ";:.,=}])` \n\t",
57
- folding: {
58
- markers: {
59
- start: /^\s*\/\/\s*#?region\b/u,
60
- end: /^\s*\/\/\s*#?endregion\b/u
61
- }
62
- },
63
- indentationRules: {
64
- // ^(.*\*/)?\s*\}.*$
65
- decreaseIndentPattern: /^((?!.*?\/\*).*\*\/)?\s*[\}\]\)].*$/u,
66
- // ^.*\{[^}"']*$
67
- increaseIndentPattern: /^((?!\/\/).)*(\{[^}"'`]*|\([^)"'`]*|\[[^\]"'`]*)$/u
68
- }
69
- };
70
- const arcadeMonarchLanguage = {
71
- // Set defaultToken to invalid to see what you do not tokenize yet
72
- defaultToken: "invalid",
73
- tokenPostfix: ".arc",
74
- // Arcade is case insensitive
75
- ignoreCase: true,
76
- // builtinFunctions: [...arcadeService.FunctionNames],
77
- // Arcade keywords. 'from' is a special case as we want to treat it as a keyword in
78
- // import statement but as an identifer in var statement.
79
- keywords: nt.filter((k) => k !== "from"),
80
- operators,
81
- constants: ["true", "false", "null"],
82
- // we include these common regular expressions
83
- symbols: /[=><!~?:&|+\-*\/\^%]+/u,
84
- escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/u,
85
- digits: /\d+(_+\d+)*/u,
86
- octaldigits: /[0-7]+(_+[0-7]+)*/u,
87
- binarydigits: /[0-1]+(_+[0-1]+)*/u,
88
- hexdigits: /[[0-9a-fA-F]+(_+[0-9a-fA-F]+)*/u,
89
- regexpctl: /[(){}\[\]\$\^|\-*+?\.]/u,
90
- regexpesc: /\\(?:[bBdDfnrstvwWn0\\\/]|@regexpctl|c[A-Z]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4})/u,
91
- // The main tokenizer for our languages
92
- tokenizer: {
93
- root: [[/[{}]/u, "delimiter.bracket"], { include: "common" }],
94
- common: [
95
- // import statement. import followed by a white space
96
- [/import(?=\s)/u, { token: "keyword", next: "@import" }],
97
- // identifiers and keywords
98
- [
99
- /[a-z_$][\w$]*/u,
100
- {
101
- cases: {
102
- "@constants": "constant",
103
- "@keywords": "keyword",
104
- "@default": "identifier"
105
- }
106
- }
107
- ],
108
- // whitespace
109
- { include: "@whitespace" },
110
- // regular expression: ensure it is terminated before beginning (otherwise it is an opeator)
111
- [
112
- /\/(?=([^\\\/]|\\.)+\/([gimsuy]*)(\s*)(\.|;|\/|,|\)|\]|\}|$))/u,
113
- { token: "regexp", bracket: "@open", next: "@regexp" }
114
- ],
115
- // delimiters and operators
116
- [/[()\[\]]/u, "@brackets"],
117
- [/[<>](?!@symbols)/u, "@brackets"],
118
- [
119
- /@symbols/u,
120
- {
121
- cases: {
122
- "@operators": "delimiter",
123
- "@default": ""
124
- }
125
- }
126
- ],
127
- // numbers
128
- [/(@digits)[eE]([\-+]?(@digits))?/u, "number"],
129
- [/(@digits)\.(@digits)([eE][\-+]?(@digits))?/u, "number"],
130
- [/0[xX](@hexdigits)/u, "number"],
131
- [/0[oO]?(@octaldigits)/u, "number"],
132
- [/0[bB](@binarydigits)/u, "number"],
133
- [/(@digits)/u, "number"],
134
- // delimiter: after number because of .\d floats
135
- [/[;,.]/u, "delimiter"],
136
- // strings
137
- [/"([^"\\]|\\.)*$/u, "string.invalid"],
138
- [/'([^'\\]|\\.)*$/u, "string.invalid"],
139
- [/"/u, "string", "@string_double"],
140
- [/'/u, "string", "@string_single"],
141
- [/`/u, "string", "@string_backtick"]
142
- ],
143
- import: [
144
- // import keyword
145
- [/import(?=\s)/u, { token: "keyword" }],
146
- // whitespace
147
- { include: "@whitespace" },
148
- // identifier
149
- [/[a-z_$][\w$]*/u, "identifier"],
150
- // whitespace
151
- { include: "@whitespace" },
152
- // from keyword
153
- [/from/u, { token: "keyword", next: "@popall" }]
154
- ],
155
- whitespace: [
156
- [/[ \t\r\n]+/u, ""],
157
- [/\/\*/u, "comment", "@comment"],
158
- [/\/\/.*$/u, "comment"]
159
- ],
160
- comment: [
161
- [/[^\/*]+/u, "comment"],
162
- [/\*\//u, "comment", "@pop"],
163
- [/[\/*]/u, "comment"]
164
- ],
165
- // We match regular expression quite precisely
166
- regexp: [
167
- [/(\{)(\d+(?:,\d*)?)(\})/u, ["regexp.escape.control", "regexp.escape.control", "regexp.escape.control"]],
168
- [
169
- /(\[)(\^?)(?=(?:[^\]\\\/]|\\.)+)/u,
170
- ["regexp.escape.control", { token: "regexp.escape.control", next: "@regexrange" }]
171
- ],
172
- [/(\()(\?:|\?=|\?!)/u, ["regexp.escape.control", "regexp.escape.control"]],
173
- [/[()]/u, "regexp.escape.control"],
174
- [/@regexpctl/u, "regexp.escape.control"],
175
- [/[^\\\/]/u, "regexp"],
176
- [/@regexpesc/u, "regexp.escape"],
177
- [/\\\./u, "regexp.invalid"],
178
- [/(\/)([gimsuy]*)/u, [{ token: "regexp", bracket: "@close", next: "@pop" }, "keyword.other"]]
179
- ],
180
- regexrange: [
181
- [/-/u, "regexp.escape.control"],
182
- [/\^/u, "regexp.invalid"],
183
- [/@regexpesc/u, "regexp.escape"],
184
- [/[^\]]/u, "regexp"],
185
- [/\]/u, { token: "regexp.escape.control", next: "@pop", bracket: "@close" }]
186
- ],
187
- string_double: [
188
- [/[^\\"]+/u, "string"],
189
- [/@escapes/u, "string.escape"],
190
- [/\\./u, "string.escape.invalid"],
191
- [/"/u, "string", "@pop"]
192
- ],
193
- string_single: [
194
- [/[^\\']+/u, "string"],
195
- [/@escapes/u, "string.escape"],
196
- [/\\./u, "string.escape.invalid"],
197
- [/'/u, "string", "@pop"]
198
- ],
199
- string_backtick: [
200
- [/\$\{/u, { token: "delimiter.bracket", next: "@bracketCounting" }],
201
- [/[^\\`$]+/u, "string"],
202
- [/@escapes/u, "string.escape"],
203
- [/\\./u, "string.escape.invalid"],
204
- [/`/u, "string", "@pop"]
205
- ],
206
- bracketCounting: [
207
- [/\{/u, "delimiter.bracket", "@bracketCounting"],
208
- [/\}/u, "delimiter.bracket", "@pop"],
209
- { include: "common" }
210
- ]
211
- }
212
- };
213
-
214
- //#region Diagnostic
215
- class DiagnosticsAdapter {
216
- constructor(_languageId, _worker, { defaults, diagnosticsService }) {
217
- this._languageId = _languageId;
218
- this._worker = _worker;
219
- this._disposables = [];
220
- this._listener = Object.create(null);
221
- this._diagnosticsService = diagnosticsService;
222
- this._defaults = defaults;
223
- const onModelAdd = (model) => {
224
- const languageId = model.getLanguageId();
225
- if (languageId !== this._languageId) {
226
- return;
227
- }
228
- let handle;
229
- this._listener[model.uri.toString()] = model.onDidChangeContent(() => {
230
- window.clearTimeout(handle);
231
- handle = window.setTimeout(async () => await this._doValidate(model, languageId), 500);
232
- });
233
- this._doValidate(model, languageId);
234
- };
235
- const onModelRemoved = (model) => {
236
- const uriStr = model.uri.toString();
237
- editor.setModelMarkers(model, this._languageId, []);
238
- const listener = this._listener[uriStr];
239
- if (listener) {
240
- listener.dispose();
241
- delete this._listener[uriStr];
242
- }
243
- };
244
- this._disposables.push(editor.onDidCreateModel(onModelAdd));
245
- this._disposables.push(editor.onWillDisposeModel((model) => {
246
- onModelRemoved(model);
247
- }));
248
- this._disposables.push(editor.onDidChangeModelLanguage((event) => {
249
- onModelRemoved(event.model);
250
- onModelAdd(event.model);
251
- }));
252
- this._disposables.push(defaults.onDidChange(() => {
253
- editor.getModels().forEach((model) => {
254
- if (model.getLanguageId() === this._languageId) {
255
- onModelRemoved(model);
256
- onModelAdd(model);
257
- }
258
- });
259
- }));
260
- this._disposables.push(defaults.onModelContextDidChange((key) => {
261
- editor.getModels().forEach((model) => {
262
- if (model.getLanguageId() === this._languageId && model.uri.toString() === key) {
263
- this._doValidate(model, this._languageId);
264
- }
265
- });
266
- }));
267
- this._disposables.push({
268
- dispose: () => {
269
- for (const key of Object.keys(this._listener)) {
270
- this._listener[key].dispose();
271
- }
272
- }
273
- });
274
- editor.getModels().forEach(onModelAdd);
275
- }
276
- dispose() {
277
- this._disposables.forEach((d) => d && d.dispose());
278
- this._disposables = [];
279
- }
280
- async _doValidate(model, languageId) {
281
- if (!model.isAttachedToEditor()) {
282
- return;
283
- }
284
- try {
285
- const workerProxy = await this._worker(model.uri);
286
- const context = this._defaults.getApiContextForModel(model.uri);
287
- const diagnostics = await workerProxy.doValidation(model.uri.toString(), context);
288
- const markers = diagnostics.map((d) => toMarker(model.uri, d));
289
- this._diagnosticsService.fireDiagnosticsChange(model.uri, diagnostics);
290
- editor.setModelMarkers(model, languageId, markers);
291
- }
292
- catch (err) {
293
- console.error(err);
294
- }
295
- }
296
- }
297
- function toSeverity(languageServiceSeverity) {
298
- switch (languageServiceSeverity) {
299
- case main.DiagnosticSeverity.Error:
300
- return MarkerSeverity.Error;
301
- case main.DiagnosticSeverity.Warning:
302
- return MarkerSeverity.Warning;
303
- case main.DiagnosticSeverity.Information:
304
- return MarkerSeverity.Info;
305
- case main.DiagnosticSeverity.Hint:
306
- return MarkerSeverity.Hint;
307
- default:
308
- return MarkerSeverity.Info;
309
- }
310
- }
311
- function toMarker(_resource, diag) {
312
- // Diagnostics positions are zero-based, MarkerData are 1-based
313
- return {
314
- severity: toSeverity(diag.severity),
315
- startLineNumber: diag.range.start.line + 1,
316
- startColumn: diag.range.start.character + 1,
317
- endLineNumber: diag.range.end.line + 1,
318
- endColumn: diag.range.end.character + 1,
319
- message: diag.message
320
- };
321
- }
322
- //#endregion
323
- //#region Completion
324
- function fromPosition(position) {
325
- // Language service is zero based
326
- return { character: position.column - 1, line: position.lineNumber - 1 };
327
- }
328
- function toRange(range) {
329
- return new Range(range.start.line + 1, range.start.character + 1, range.end.line + 1, range.end.character + 1);
330
- }
331
- function toTextEdit(textEdit) {
332
- return {
333
- range: toRange(textEdit.range),
334
- text: textEdit.newText
335
- };
336
- }
337
- function isInsertReplaceEdit(edit) {
338
- return (typeof edit.insert !== "undefined" &&
339
- typeof edit.replace !== "undefined");
340
- }
341
- function toCompletionItemKind(kind) {
342
- const mItemKind = languages.CompletionItemKind;
343
- switch (kind) {
344
- case main.CompletionItemKind.Text:
345
- return mItemKind.Text;
346
- case main.CompletionItemKind.Method:
347
- return mItemKind.Method;
348
- case main.CompletionItemKind.Function:
349
- return mItemKind.Function;
350
- case main.CompletionItemKind.Constructor:
351
- return mItemKind.Constructor;
352
- case main.CompletionItemKind.Field:
353
- return mItemKind.Field;
354
- case main.CompletionItemKind.Variable:
355
- return mItemKind.Variable;
356
- case main.CompletionItemKind.Class:
357
- return mItemKind.Class;
358
- case main.CompletionItemKind.Interface:
359
- return mItemKind.Interface;
360
- case main.CompletionItemKind.Module:
361
- return mItemKind.Module;
362
- case main.CompletionItemKind.Property:
363
- return mItemKind.Property;
364
- case main.CompletionItemKind.Unit:
365
- return mItemKind.Unit;
366
- case main.CompletionItemKind.Value:
367
- return mItemKind.Value;
368
- case main.CompletionItemKind.Enum:
369
- return mItemKind.Enum;
370
- case main.CompletionItemKind.Keyword:
371
- return mItemKind.Keyword;
372
- case main.CompletionItemKind.Snippet:
373
- return mItemKind.Snippet;
374
- case main.CompletionItemKind.Color:
375
- return mItemKind.Color;
376
- case main.CompletionItemKind.File:
377
- return mItemKind.File;
378
- case main.CompletionItemKind.Reference:
379
- return mItemKind.Reference;
380
- case main.CompletionItemKind.Folder:
381
- return mItemKind.Folder;
382
- case main.CompletionItemKind.EnumMember:
383
- return mItemKind.EnumMember;
384
- case main.CompletionItemKind.Constant:
385
- return mItemKind.Constant;
386
- case main.CompletionItemKind.Struct:
387
- return mItemKind.Struct;
388
- case main.CompletionItemKind.Event:
389
- return mItemKind.Event;
390
- case main.CompletionItemKind.Operator:
391
- return mItemKind.Operator;
392
- case main.CompletionItemKind.TypeParameter:
393
- return mItemKind.TypeParameter;
394
- }
395
- return mItemKind.Property;
396
- }
397
- class CompletionProvider {
398
- constructor(_worker, _defaults) {
399
- this._worker = _worker;
400
- this._defaults = _defaults;
401
- this.triggerCharacters = [".", "("];
402
- }
403
- async provideCompletionItems(model, position
404
- // _context: languages.CompletionContext,
405
- // _token: CancellationToken,
406
- ) {
407
- const worker = await this._worker(model.uri);
408
- const context = this._defaults.getApiContextForModel(model.uri);
409
- const completionList = await worker.doComplete(model.uri.toString(), fromPosition(position), context);
410
- if (!completionList) {
411
- return;
412
- }
413
- const wordInfo = model.getWordUntilPosition(position);
414
- const wordRange = new Range(position.lineNumber, wordInfo.startColumn, position.lineNumber, wordInfo.endColumn);
415
- const items = completionList.items.map((entry) => {
416
- const item = {
417
- label: entry.label,
418
- insertText: entry.insertText || entry.label,
419
- sortText: entry.sortText,
420
- filterText: entry.filterText,
421
- detail: entry.detail,
422
- range: wordRange,
423
- kind: toCompletionItemKind(entry.kind)
424
- };
425
- if (entry.textEdit) {
426
- if (isInsertReplaceEdit(entry.textEdit)) {
427
- item.range = {
428
- insert: toRange(entry.textEdit.insert),
429
- replace: toRange(entry.textEdit.replace)
430
- };
431
- }
432
- else {
433
- item.range = toRange(entry.textEdit.range);
434
- }
435
- item.insertText = entry.textEdit.newText;
436
- }
437
- if (entry.additionalTextEdits) {
438
- item.additionalTextEdits = entry.additionalTextEdits.map(toTextEdit);
439
- }
440
- if (entry.insertTextFormat === main.InsertTextFormat.Snippet) {
441
- item.insertTextRules = languages.CompletionItemInsertTextRule.InsertAsSnippet;
442
- }
443
- if (entry.documentation) {
444
- if (typeof entry.documentation === "string") {
445
- item.documentation = entry.documentation;
446
- }
447
- else {
448
- item.documentation = {
449
- supportThemeIcons: false,
450
- value: entry.documentation.value,
451
- supportHtml: true
452
- };
453
- }
454
- }
455
- return item;
456
- });
457
- return {
458
- incomplete: completionList.isIncomplete,
459
- suggestions: items
460
- };
461
- }
462
- }
463
- //#endregion
464
- //#region Formatter
465
- class FormattingProvider {
466
- constructor(_worker, _defaults) {
467
- this._worker = _worker;
468
- this._defaults = _defaults;
469
- }
470
- async provideDocumentFormattingEdits(model
471
- // _options: languages.FormattingOptions,
472
- // _token: CancellationToken,
473
- ) {
474
- const worker = await this._worker(model.uri);
475
- const context = this._defaults.getApiContextForModel(model.uri.toString());
476
- const edits = await worker.doFormat(model.uri.toString(), context);
477
- if (!edits) {
478
- return [];
479
- }
480
- return edits.map((e) => ({ range: toRange(e.range), text: e.newText }));
481
- }
482
- }
483
- //#endregion
484
-
485
- /**
486
- * Manager to create our arcade worker and client proxy
487
- */
488
- class WorkerManager {
489
- constructor(_defaults) {
490
- this._defaults = _defaults;
491
- this._worker = null;
492
- this._client = null;
493
- // Observes the arcade defaults. If modified then stop the worker.
494
- this._configChangeListener = this._defaults.onDidChange(() => this.stopWorker());
495
- }
496
- dispose() {
497
- this._configChangeListener.dispose();
498
- this.stopWorker();
499
- }
500
- stopWorker() {
501
- if (this._worker) {
502
- this._worker.dispose();
503
- this._worker = null;
504
- }
505
- this._client = null;
506
- }
507
- async _getClientProxy() {
508
- // We used createWebWorker to create or run the web worker if it isn’t already created.
509
- // Otherwise, we get and return the proxy client.
510
- if (!this._client) {
511
- const { languageId, languageOptions } = this._defaults;
512
- this._worker = editor.createWebWorker({
513
- moduleId: "ArcadeWorker",
514
- label: languageId,
515
- createData: {
516
- languageId,
517
- languageOptions
518
- }
519
- });
520
- this._client = this._worker.getProxy();
521
- }
522
- return await this._client;
523
- }
524
- async getLanguageServiceWorker(...resources) {
525
- const _client = await this._getClientProxy();
526
- await this._worker?.withSyncedResources(resources);
527
- return _client;
528
- }
529
- }
530
-
531
- let arcadeWorker;
532
- /**
533
- * Returns the arcade worker for the model uris.
534
- * @param uris The model uris for which to get the worker.
535
- * @returns The arcade worker.
536
- */
537
- async function getArcadeWorker(...uris) {
538
- return await new Promise((resolve, reject) => {
539
- if (!arcadeWorker) {
540
- return reject(new Error("TypeScript not registered!"));
541
- }
542
- resolve(arcadeWorker(...uris));
543
- });
544
- }
545
- /**
546
- * The Arcade Language Diagnostic Service.
547
- * Consumers can listen to the diagnostics change event to get notified when the diagnostics change.
548
- */
549
- class ArcadeDiagnosticService {
550
- constructor() {
551
- this._onDiagnosticsChange = new Emitter();
552
- }
553
- /**
554
- * An event to signal changes to the diagnostics.
555
- * The event value is the uri string and the diagnostics.
556
- */
557
- get onDiagnosticsChange() {
558
- return this._onDiagnosticsChange.event;
559
- }
560
- /**
561
- * Fires the diagnostics change event.
562
- * @param uri The uri of the model for which the diagnostics changed.
563
- * @param diagnostics The diagnostics for the model.
564
- */
565
- fireDiagnosticsChange(uri, diagnostics) {
566
- this._onDiagnosticsChange.fire({ uri, diagnostics });
567
- }
568
- }
569
- const arcadeDiagnosticService = new ArcadeDiagnosticService();
570
- /**
571
- * Get the Arcade Diagnostic Service.
572
- * @returns The Arcade Language Diagnostic Service.
573
- */
574
- function getArcadeDiagnosticService() {
575
- return arcadeDiagnosticService;
576
- }
577
- function setupMode(arcadeDefaults) {
578
- const client = new WorkerManager(arcadeDefaults);
579
- const workerAccessor = async (...uris) => await client.getLanguageServiceWorker(...uris);
580
- arcadeWorker = workerAccessor;
581
- // Use the arcade Monarch Json to define the highlighting
582
- languages.setMonarchTokensProvider(arcadeDefaults.languageId, arcadeMonarchLanguage);
583
- languages.setLanguageConfiguration(arcadeDefaults.languageId, arcadeLanguageConfiguration);
584
- // Creates and registers a Completion Adapter
585
- languages.registerCompletionItemProvider(arcadeDefaults.languageId, new CompletionProvider(workerAccessor, arcadeDefaults));
586
- // Creates and registers a Formatter
587
- languages.registerDocumentFormattingEditProvider(arcadeDefaults.languageId, new FormattingProvider(workerAccessor, arcadeDefaults));
588
- // Creates a Diagnostic Adapter
589
- // eslint-disable-next-line no-new
590
- new DiagnosticsAdapter(arcadeDefaults.languageId, workerAccessor, {
591
- defaults: arcadeDefaults,
592
- diagnosticsService: arcadeDiagnosticService
593
- });
594
- }
595
-
596
- export { getArcadeDiagnosticService, getArcadeWorker, setupMode };