@arcgis/coding-components 4.29.0-beta.47 → 4.29.0-beta.49

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.
Files changed (94) hide show
  1. package/dist/arcgis-coding-components/arcgis-coding-components.esm.js +1 -1
  2. package/dist/arcgis-coding-components/assets/code-editor/arcade.worker.js +13 -13
  3. package/dist/arcgis-coding-components/index.esm.js +1 -1
  4. package/dist/arcgis-coding-components/{p-10a322ec.js → p-0d616249.js} +9 -9
  5. package/dist/arcgis-coding-components/p-2c0d6f15.js +2 -0
  6. package/dist/arcgis-coding-components/{p-71faf9a4.js → p-5802524a.js} +1 -1
  7. package/dist/arcgis-coding-components/{p-9eabda86.js → p-5ddccf04.js} +1 -1
  8. package/dist/arcgis-coding-components/p-7475f3a6.js +1 -0
  9. package/dist/arcgis-coding-components/{p-e6ede32d.js → p-7d8caba9.js} +1 -1
  10. package/dist/arcgis-coding-components/{p-f7d7d78d.js → p-9f6db08a.js} +1 -1
  11. package/dist/arcgis-coding-components/{p-e475e6cd.js → p-aefe77ce.js} +1 -1
  12. package/dist/arcgis-coding-components/p-ce2be55e.entry.js +1 -0
  13. package/dist/arcgis-coding-components/{p-ce586a8c.js → p-d425a387.js} +1 -1
  14. package/dist/arcgis-coding-components/{p-c084ada8.js → p-ff21f230.js} +1 -1
  15. package/dist/cjs/{arcade-defaults-8445d852.js → arcade-defaults-2d513b59.js} +1534 -1534
  16. package/dist/cjs/arcade-mode-6219f1b8.js +599 -0
  17. package/dist/cjs/arcgis-arcade-api_6.cjs.entry.js +1404 -1408
  18. package/dist/cjs/arcgis-coding-components.cjs.js +2 -2
  19. package/dist/cjs/{cssMode-e63287bb.js → cssMode-1ec48254.js} +2 -2
  20. package/dist/cjs/{html-c0d4db3b.js → html-0e1741fe.js} +2 -2
  21. package/dist/cjs/{htmlMode-fdc44d57.js → htmlMode-279d3c29.js} +2 -2
  22. package/dist/cjs/{index-6a382a34.js → index-ac186201.js} +67 -24
  23. package/dist/cjs/index.cjs.js +2 -2
  24. package/dist/cjs/{javascript-a419d064.js → javascript-04f1bce0.js} +3 -3
  25. package/dist/cjs/{jsonMode-73aee5d2.js → jsonMode-59322f7a.js} +2 -2
  26. package/dist/cjs/loader.cjs.js +1 -1
  27. package/dist/cjs/{tsMode-37d1b053.js → tsMode-17561f70.js} +2 -2
  28. package/dist/cjs/{typescript-53f9f36a.js → typescript-b7da8629.js} +2 -2
  29. package/dist/components/arcade-api.js +160 -160
  30. package/dist/components/arcade-contribution.js +60 -60
  31. package/dist/components/arcade-defaults.js +1240 -1240
  32. package/dist/components/arcade-mode.js +514 -513
  33. package/dist/components/arcade-results.js +426 -430
  34. package/dist/components/arcade-suggestions.js +130 -132
  35. package/dist/components/arcade-variables.js +157 -155
  36. package/dist/components/arcgis-arcade-api.d.ts +2 -2
  37. package/dist/components/arcgis-arcade-editor.d.ts +2 -2
  38. package/dist/components/arcgis-arcade-editor.js +391 -391
  39. package/dist/components/arcgis-arcade-results.d.ts +2 -2
  40. package/dist/components/arcgis-arcade-suggestions.d.ts +2 -2
  41. package/dist/components/arcgis-arcade-variables.d.ts +2 -2
  42. package/dist/components/arcgis-code-editor.d.ts +2 -2
  43. package/dist/components/code-editor.js +251 -251
  44. package/dist/components/fields.js +69 -69
  45. package/dist/components/functional-components.js +1 -1
  46. package/dist/components/index2.js +2 -2
  47. package/dist/components/markdown.js +28 -28
  48. package/dist/components/utilities.js +20 -20
  49. package/dist/esm/{arcade-defaults-d7893362.js → arcade-defaults-0bafa696.js} +1534 -1534
  50. package/dist/esm/arcade-mode-c17a1fa1.js +595 -0
  51. package/dist/esm/arcgis-arcade-api_6.entry.js +1404 -1408
  52. package/dist/esm/arcgis-coding-components.js +3 -3
  53. package/dist/esm/{cssMode-b1771f92.js → cssMode-3d18bd2b.js} +2 -2
  54. package/dist/esm/{html-af635d52.js → html-2bce5d77.js} +2 -2
  55. package/dist/esm/{htmlMode-3021c301.js → htmlMode-69d56956.js} +2 -2
  56. package/dist/esm/{index-fd6b2fd8.js → index-022fb97b.js} +67 -24
  57. package/dist/esm/index.js +2 -2
  58. package/dist/esm/{javascript-70589186.js → javascript-ded5c9d7.js} +3 -3
  59. package/dist/esm/{jsonMode-cb509b79.js → jsonMode-0bf84cb2.js} +2 -2
  60. package/dist/esm/loader.js +2 -2
  61. package/dist/esm/{tsMode-ed90c9aa.js → tsMode-15d4e936.js} +2 -2
  62. package/dist/esm/{typescript-db8a0b18.js → typescript-cc4d00f0.js} +2 -2
  63. package/dist/types/components/arcade-api/arcade-api.d.ts +40 -40
  64. package/dist/types/components/arcade-api/t9n-types.d.ts +6 -6
  65. package/dist/types/components/arcade-editor/arcade-editor.d.ts +127 -127
  66. package/dist/types/components/arcade-editor/t9n-types.d.ts +6 -6
  67. package/dist/types/components/arcade-results/arcade-results.d.ts +47 -47
  68. package/dist/types/components/arcade-results/t9n-types.d.ts +11 -11
  69. package/dist/types/components/arcade-suggestions/arcade-suggestions.d.ts +34 -34
  70. package/dist/types/components/arcade-suggestions/t9n-types.d.ts +4 -4
  71. package/dist/types/components/arcade-variables/arcade-variables.d.ts +41 -41
  72. package/dist/types/components/arcade-variables/t9n-types.d.ts +6 -6
  73. package/dist/types/components/code-editor/code-editor.d.ts +73 -73
  74. package/dist/types/stencil-public-runtime.d.ts +8 -0
  75. package/dist/types/utils/arcade-executor.d.ts +79 -79
  76. package/dist/types/utils/arcade-monaco/arcade-defaults.d.ts +66 -66
  77. package/dist/types/utils/arcade-monaco/arcade-language-features.d.ts +23 -23
  78. package/dist/types/utils/arcade-monaco/arcade-mode.d.ts +9 -9
  79. package/dist/types/utils/arcade-monaco/arcade-theme.d.ts +7 -7
  80. package/dist/types/utils/arcade-monaco/arcade-worker-manager.d.ts +9 -9
  81. package/dist/types/utils/arcade-monaco/arcade.worker.d.ts +12 -12
  82. package/dist/types/utils/arcade-monaco/types.d.ts +29 -29
  83. package/dist/types/utils/editor-suggestions.d.ts +24 -24
  84. package/dist/types/utils/functional-components.d.ts +1 -1
  85. package/dist/types/utils/markdown.d.ts +1 -1
  86. package/dist/types/utils/profile/editor-profile.d.ts +185 -185
  87. package/dist/types/utils/profile/types.d.ts +101 -101
  88. package/dist/types/utils/utilities.d.ts +1 -1
  89. package/package.json +7 -7
  90. package/dist/arcgis-coding-components/p-5d670bd2.js +0 -2
  91. package/dist/arcgis-coding-components/p-9e242e76.js +0 -1
  92. package/dist/arcgis-coding-components/p-ccdf0ac1.entry.js +0 -1
  93. package/dist/cjs/arcade-mode-b77afcc9.js +0 -598
  94. package/dist/esm/arcade-mode-70e22d22.js +0 -594
@@ -0,0 +1,595 @@
1
+ import { n as main, e as editor, M as MarkerSeverity, R as Range, l as languages, E as Emitter } from './arcade-defaults-0bafa696.js';
2
+ import './index-022fb97b.js';
3
+
4
+ var ge=(e=>(e.False="false",e.Null="null",e.True="true",e))(ge||{}),xe=(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))(xe||{}),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||{}),De=["++","--"],We=["-","+","!","~"],qe=["=","/=","*=","%=","+=","-="],He=["||","&&"],bt=["|","&",">>","<<",">>>","^","==","!=","<","<=",">",">=","+","-","*","/","%"],It=(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))(It||{}),kt=(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))(kt||{});var v=[[],[],[]];De.forEach(e=>v[e.length-1].push(e));We.forEach(e=>v[e.length-1].push(e));He.forEach(e=>v[e.length-1].push(e));qe.forEach(e=>v[e.length-1].push(e));bt.forEach(e=>v[e.length-1].push(e));var rt=(D=>(D.AlreadyDefined="AlreadyDefined",D.ApiConflict="ApiConflict",D.AssignedNeverUsed="AssignedNeverUsed",D.DefinedNeverAssigned="DefinedNeverAssigned",D.DefinedNeverUsed="DefinedNeverUsed",D.EmptyBlockStatement="EmptyBlockStatement",D.ExecutionError="ExecutionError",D.InvalidApiFunctionUsage="InvalidApiFunctionUsage",D.InvalidConstantIdentifier="InvalidConstantIdentifier",D.InvalidPropertyIdentifier="InvalidPropertyIdentifier",D.NoArgumentExpected="NoArgumentExpected",D.NotADictionary="NotADictionary",D.NotDefined="NotDefined",D.NotEnoughArguments="NotEnoughArguments",D.ProfileVariablesAreImmutable="ProfileVariablesAreImmutable",D.ProfileVariablesConflict="ProfileVariablesConflict",D.ReservedKeyword="ReservedKeyword",D.TooManyArguments="TooManyArguments",D.UnexpectedEmptyFunction="UnexpectedEmptyFunction",D.UnexpectedPropertyIdentifier="UnexpectedPropertyIdentifier",D.UnknownPropertyIdentifier="UnknownPropertyIdentifier",D))(rt||{});var st=Object.values(xe),at=Object.values(ge);at.map(e=>({label:e,kind:main.CompletionItemKind.Constant}));st.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: Array.from(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: st.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(() => 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" && typeof edit.replace !== "undefined");
339
+ }
340
+ function toCompletionItemKind(kind) {
341
+ const mItemKind = languages.CompletionItemKind;
342
+ switch (kind) {
343
+ case main.CompletionItemKind.Text:
344
+ return mItemKind.Text;
345
+ case main.CompletionItemKind.Method:
346
+ return mItemKind.Method;
347
+ case main.CompletionItemKind.Function:
348
+ return mItemKind.Function;
349
+ case main.CompletionItemKind.Constructor:
350
+ return mItemKind.Constructor;
351
+ case main.CompletionItemKind.Field:
352
+ return mItemKind.Field;
353
+ case main.CompletionItemKind.Variable:
354
+ return mItemKind.Variable;
355
+ case main.CompletionItemKind.Class:
356
+ return mItemKind.Class;
357
+ case main.CompletionItemKind.Interface:
358
+ return mItemKind.Interface;
359
+ case main.CompletionItemKind.Module:
360
+ return mItemKind.Module;
361
+ case main.CompletionItemKind.Property:
362
+ return mItemKind.Property;
363
+ case main.CompletionItemKind.Unit:
364
+ return mItemKind.Unit;
365
+ case main.CompletionItemKind.Value:
366
+ return mItemKind.Value;
367
+ case main.CompletionItemKind.Enum:
368
+ return mItemKind.Enum;
369
+ case main.CompletionItemKind.Keyword:
370
+ return mItemKind.Keyword;
371
+ case main.CompletionItemKind.Snippet:
372
+ return mItemKind.Snippet;
373
+ case main.CompletionItemKind.Color:
374
+ return mItemKind.Color;
375
+ case main.CompletionItemKind.File:
376
+ return mItemKind.File;
377
+ case main.CompletionItemKind.Reference:
378
+ return mItemKind.Reference;
379
+ case main.CompletionItemKind.Folder:
380
+ return mItemKind.Folder;
381
+ case main.CompletionItemKind.EnumMember:
382
+ return mItemKind.EnumMember;
383
+ case main.CompletionItemKind.Constant:
384
+ return mItemKind.Constant;
385
+ case main.CompletionItemKind.Struct:
386
+ return mItemKind.Struct;
387
+ case main.CompletionItemKind.Event:
388
+ return mItemKind.Event;
389
+ case main.CompletionItemKind.Operator:
390
+ return mItemKind.Operator;
391
+ case main.CompletionItemKind.TypeParameter:
392
+ return mItemKind.TypeParameter;
393
+ }
394
+ return mItemKind.Property;
395
+ }
396
+ class CompletionProvider {
397
+ constructor(_worker, _defaults) {
398
+ this._worker = _worker;
399
+ this._defaults = _defaults;
400
+ this.triggerCharacters = [".", "("];
401
+ }
402
+ async provideCompletionItems(model, position
403
+ // _context: languages.CompletionContext,
404
+ // _token: CancellationToken,
405
+ ) {
406
+ const worker = await this._worker(model.uri);
407
+ const context = this._defaults.getApiContextForModel(model.uri);
408
+ const completionList = await worker.doComplete(model.uri.toString(), fromPosition(position), context);
409
+ if (!completionList) {
410
+ return;
411
+ }
412
+ const wordInfo = model.getWordUntilPosition(position);
413
+ const wordRange = new Range(position.lineNumber, wordInfo.startColumn, position.lineNumber, wordInfo.endColumn);
414
+ const items = completionList.items.map((entry) => {
415
+ const item = {
416
+ label: entry.label,
417
+ insertText: entry.insertText || entry.label,
418
+ sortText: entry.sortText,
419
+ filterText: entry.filterText,
420
+ detail: entry.detail,
421
+ range: wordRange,
422
+ kind: toCompletionItemKind(entry.kind)
423
+ };
424
+ if (entry.textEdit) {
425
+ if (isInsertReplaceEdit(entry.textEdit)) {
426
+ item.range = {
427
+ insert: toRange(entry.textEdit.insert),
428
+ replace: toRange(entry.textEdit.replace)
429
+ };
430
+ }
431
+ else {
432
+ item.range = toRange(entry.textEdit.range);
433
+ }
434
+ item.insertText = entry.textEdit.newText;
435
+ }
436
+ if (entry.additionalTextEdits) {
437
+ item.additionalTextEdits = entry.additionalTextEdits.map(toTextEdit);
438
+ }
439
+ if (entry.insertTextFormat === main.InsertTextFormat.Snippet) {
440
+ item.insertTextRules = languages.CompletionItemInsertTextRule.InsertAsSnippet;
441
+ }
442
+ if (entry.documentation) {
443
+ if (typeof entry.documentation === "string") {
444
+ item.documentation = entry.documentation;
445
+ }
446
+ else {
447
+ item.documentation = {
448
+ supportThemeIcons: false,
449
+ value: entry.documentation.value,
450
+ supportHtml: true
451
+ };
452
+ }
453
+ }
454
+ return item;
455
+ });
456
+ return {
457
+ incomplete: completionList.isIncomplete,
458
+ suggestions: items
459
+ };
460
+ }
461
+ }
462
+ //#endregion
463
+ //#region Formatter
464
+ class FormattingProvider {
465
+ constructor(_worker, _defaults) {
466
+ this._worker = _worker;
467
+ this._defaults = _defaults;
468
+ }
469
+ async provideDocumentFormattingEdits(model
470
+ // _options: languages.FormattingOptions,
471
+ // _token: CancellationToken,
472
+ ) {
473
+ const worker = await this._worker(model.uri);
474
+ const context = this._defaults.getApiContextForModel(model.uri.toString());
475
+ const edits = await worker.doFormat(model.uri.toString(), context);
476
+ if (!edits) {
477
+ return [];
478
+ }
479
+ return edits.map((e) => ({ range: toRange(e.range), text: e.newText }));
480
+ }
481
+ }
482
+ //#endregion
483
+
484
+ /**
485
+ * Manager to create our arcade worker and client proxy
486
+ */
487
+ class WorkerManager {
488
+ constructor(_defaults) {
489
+ this._defaults = _defaults;
490
+ this._worker = null;
491
+ this._client = null;
492
+ // Observes the arcade defaults. If modified then stop the worker.
493
+ this._configChangeListener = this._defaults.onDidChange(() => this.stopWorker());
494
+ }
495
+ dispose() {
496
+ this._configChangeListener.dispose();
497
+ this.stopWorker();
498
+ }
499
+ stopWorker() {
500
+ if (this._worker) {
501
+ this._worker.dispose();
502
+ this._worker = null;
503
+ }
504
+ this._client = null;
505
+ }
506
+ _getClientProxy() {
507
+ // We used createWebWorker to create or run the web worker if it isn’t already created.
508
+ // Otherwise, we get and return the proxy client.
509
+ if (!this._client) {
510
+ const { languageId, languageOptions } = this._defaults;
511
+ this._worker = editor.createWebWorker({
512
+ moduleId: "ArcadeWorker",
513
+ label: languageId,
514
+ createData: {
515
+ languageId,
516
+ languageOptions
517
+ }
518
+ });
519
+ this._client = this._worker.getProxy();
520
+ }
521
+ return this._client;
522
+ }
523
+ async getLanguageServiceWorker(...resources) {
524
+ const _client = await this._getClientProxy();
525
+ await this._worker?.withSyncedResources(resources);
526
+ return _client;
527
+ }
528
+ }
529
+
530
+ let arcadeWorker;
531
+ /**
532
+ * Returns the arcade worker for the model uris.
533
+ * @param uris The model uris for which to get the worker.
534
+ * @returns The arcade worker.
535
+ */
536
+ async function getArcadeWorker(...uris) {
537
+ return new Promise((resolve, reject) => {
538
+ if (!arcadeWorker) {
539
+ return reject(new Error("TypeScript not registered!"));
540
+ }
541
+ resolve(arcadeWorker(...uris));
542
+ });
543
+ }
544
+ /**
545
+ * The Arcade Language Diagnostic Service.
546
+ * Consumers can listen to the diagnostics change event to get notified when the diagnostics change.
547
+ */
548
+ class ArcadeDiagnosticService {
549
+ constructor() {
550
+ this._onDiagnosticsChange = new Emitter();
551
+ }
552
+ /**
553
+ * An event to signal changes to the diagnostics.
554
+ * The event value is the uri string and the diagnostics.
555
+ */
556
+ get onDiagnosticsChange() {
557
+ return this._onDiagnosticsChange.event;
558
+ }
559
+ /**
560
+ * Fires the diagnostics change event.
561
+ * @param uri The uri of the model for which the diagnostics changed.
562
+ * @param diagnostics The diagnostics for the model.
563
+ */
564
+ fireDiagnosticsChange(uri, diagnostics) {
565
+ this._onDiagnosticsChange.fire({ uri, diagnostics });
566
+ }
567
+ }
568
+ const arcadeDiagnosticService = new ArcadeDiagnosticService();
569
+ /**
570
+ * Get the Arcade Diagnostic Service.
571
+ * @returns The Arcade Language Diagnostic Service.
572
+ */
573
+ function getArcadeDiagnosticService() {
574
+ return arcadeDiagnosticService;
575
+ }
576
+ function setupMode(arcadeDefaults) {
577
+ const client = new WorkerManager(arcadeDefaults);
578
+ const workerAccessor = (...uris) => client.getLanguageServiceWorker(...uris);
579
+ arcadeWorker = workerAccessor;
580
+ // Use the arcade Monarch Json to define the highlighting
581
+ languages.setMonarchTokensProvider(arcadeDefaults.languageId, arcadeMonarchLanguage);
582
+ languages.setLanguageConfiguration(arcadeDefaults.languageId, arcadeLanguageConfiguration);
583
+ // Creates and registers a Completion Adapter
584
+ languages.registerCompletionItemProvider(arcadeDefaults.languageId, new CompletionProvider(workerAccessor, arcadeDefaults));
585
+ // Creates and registers a Formatter
586
+ languages.registerDocumentFormattingEditProvider(arcadeDefaults.languageId, new FormattingProvider(workerAccessor, arcadeDefaults));
587
+ // Creates a Diagnostic Adapter
588
+ // eslint-disable-next-line no-new
589
+ new DiagnosticsAdapter(arcadeDefaults.languageId, workerAccessor, {
590
+ defaults: arcadeDefaults,
591
+ diagnosticsService: arcadeDiagnosticService
592
+ });
593
+ }
594
+
595
+ export { getArcadeDiagnosticService, getArcadeWorker, setupMode };