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