@player-lang/json-language-service 0.0.2-next.0

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 (59) hide show
  1. package/dist/cjs/index.cjs +2314 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/index.legacy-esm.js +2249 -0
  4. package/dist/index.mjs +2249 -0
  5. package/dist/index.mjs.map +1 -0
  6. package/package.json +40 -0
  7. package/src/__tests__/__snapshots__/service.test.ts.snap +213 -0
  8. package/src/__tests__/service.test.ts +298 -0
  9. package/src/constants.ts +38 -0
  10. package/src/index.ts +490 -0
  11. package/src/parser/__tests__/parse.test.ts +18 -0
  12. package/src/parser/document.ts +456 -0
  13. package/src/parser/edits.ts +31 -0
  14. package/src/parser/index.ts +38 -0
  15. package/src/parser/jsonParseErrors.ts +69 -0
  16. package/src/parser/types.ts +314 -0
  17. package/src/parser/utils.ts +94 -0
  18. package/src/plugins/__tests__/asset-wrapper-array-plugin.test.ts +112 -0
  19. package/src/plugins/__tests__/binding-schema-plugin.test.ts +62 -0
  20. package/src/plugins/__tests__/duplicate-id-plugin.test.ts +195 -0
  21. package/src/plugins/__tests__/missing-asset-wrapper-plugin.test.ts +190 -0
  22. package/src/plugins/__tests__/nav-state-plugin.test.ts +136 -0
  23. package/src/plugins/__tests__/view-node-plugin.test.ts +154 -0
  24. package/src/plugins/asset-wrapper-array-plugin.ts +123 -0
  25. package/src/plugins/binding-schema-plugin.ts +289 -0
  26. package/src/plugins/duplicate-id-plugin.ts +158 -0
  27. package/src/plugins/missing-asset-wrapper-plugin.ts +96 -0
  28. package/src/plugins/nav-state-plugin.ts +139 -0
  29. package/src/plugins/view-node-plugin.ts +225 -0
  30. package/src/plugins/xlr-plugin.ts +371 -0
  31. package/src/types.ts +119 -0
  32. package/src/utils.ts +143 -0
  33. package/src/xlr/__tests__/__snapshots__/transform.test.ts.snap +390 -0
  34. package/src/xlr/__tests__/transform.test.ts +108 -0
  35. package/src/xlr/index.ts +3 -0
  36. package/src/xlr/registry.ts +99 -0
  37. package/src/xlr/service.ts +190 -0
  38. package/src/xlr/transforms.ts +169 -0
  39. package/types/constants.d.ts +7 -0
  40. package/types/index.d.ts +69 -0
  41. package/types/parser/document.d.ts +25 -0
  42. package/types/parser/edits.d.ts +10 -0
  43. package/types/parser/index.d.ts +16 -0
  44. package/types/parser/jsonParseErrors.d.ts +27 -0
  45. package/types/parser/types.d.ts +188 -0
  46. package/types/parser/utils.d.ts +26 -0
  47. package/types/plugins/asset-wrapper-array-plugin.d.ts +9 -0
  48. package/types/plugins/binding-schema-plugin.d.ts +15 -0
  49. package/types/plugins/duplicate-id-plugin.d.ts +7 -0
  50. package/types/plugins/missing-asset-wrapper-plugin.d.ts +9 -0
  51. package/types/plugins/nav-state-plugin.d.ts +9 -0
  52. package/types/plugins/view-node-plugin.d.ts +9 -0
  53. package/types/plugins/xlr-plugin.d.ts +7 -0
  54. package/types/types.d.ts +81 -0
  55. package/types/utils.d.ts +24 -0
  56. package/types/xlr/index.d.ts +4 -0
  57. package/types/xlr/registry.d.ts +17 -0
  58. package/types/xlr/service.d.ts +22 -0
  59. package/types/xlr/transforms.d.ts +18 -0
@@ -0,0 +1,2249 @@
1
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-service/src/index.ts
2
+ import { format as formatJSON } from "jsonc-parser";
3
+ import {
4
+ AsyncParallelHook,
5
+ SyncBailHook,
6
+ SyncHook,
7
+ SyncWaterfallHook
8
+ } from "tapable-ts";
9
+ import {
10
+ CompletionList,
11
+ Range as Range4,
12
+ TextEdit as TextEdit2,
13
+ CodeActionKind
14
+ } from "vscode-languageserver-types";
15
+
16
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-service/src/plugins/asset-wrapper-array-plugin.ts
17
+ import { DiagnosticSeverity as DiagnosticSeverity2 } from "vscode-languageserver-types";
18
+
19
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-service/src/parser/index.ts
20
+ import { getNodeValue as getJSONNodeValue } from "jsonc-parser";
21
+
22
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-service/src/parser/utils.ts
23
+ function isPropertyNode(node) {
24
+ return node?.type === "property";
25
+ }
26
+ function isObjectNode(node) {
27
+ return node?.type === "object";
28
+ }
29
+ function isKeyNode(node) {
30
+ return isPropertyNode(node?.parent) && node?.parent.keyNode === node;
31
+ }
32
+ function isValueNode(node) {
33
+ return isPropertyNode(node?.parent) && node?.parent.valueNode === node;
34
+ }
35
+ function isViewNode(node) {
36
+ return node?.type === "view";
37
+ }
38
+ function isStateNode(node) {
39
+ return node?.type === "state";
40
+ }
41
+ function isFlowNode(node) {
42
+ return node?.type === "flow";
43
+ }
44
+ function isNavigationNode(node) {
45
+ return node?.type === "navigation";
46
+ }
47
+ function getValForKey(node, key) {
48
+ const prop = node.properties.find((k) => k.keyNode.value === key);
49
+ return prop?.valueNode?.jsonNode.value;
50
+ }
51
+ function getPropForValNode(node) {
52
+ if (isValueNode(node) && isPropertyNode(node?.parent)) {
53
+ return node?.parent.keyNode.value;
54
+ }
55
+ }
56
+ function getViewNode(node) {
57
+ if (node.parent) {
58
+ if (node.parent.type === "view") {
59
+ return node.parent;
60
+ }
61
+ return getViewNode(node.parent);
62
+ }
63
+ if (node.type === "asset") {
64
+ return node;
65
+ }
66
+ }
67
+ function getContentNode(node) {
68
+ if (node.type === "content") {
69
+ return node;
70
+ }
71
+ return node.parent ? getContentNode(node.parent) : void 0;
72
+ }
73
+
74
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-service/src/parser/document.ts
75
+ import { parseTree, findNodeAtOffset } from "jsonc-parser";
76
+
77
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-service/src/parser/types.ts
78
+ var ASTNodeImpl = class {
79
+ parent;
80
+ jsonNode;
81
+ constructor(jsonNode, parent) {
82
+ this.jsonNode = jsonNode;
83
+ this.parent = parent;
84
+ }
85
+ };
86
+ var StringASTNodeImpl = class extends ASTNodeImpl {
87
+ type = "string";
88
+ value;
89
+ constructor(jsonNode, parent) {
90
+ super(jsonNode, parent);
91
+ this.value = jsonNode.value;
92
+ }
93
+ };
94
+ var NumberASTNodeImpl = class extends ASTNodeImpl {
95
+ type = "number";
96
+ value;
97
+ constructor(jsonNode, parent) {
98
+ super(jsonNode, parent);
99
+ this.value = jsonNode.value;
100
+ }
101
+ };
102
+ var BooleanASTNodeImpl = class extends ASTNodeImpl {
103
+ type = "boolean";
104
+ value;
105
+ constructor(jsonNode, parent) {
106
+ super(jsonNode, parent);
107
+ this.value = jsonNode.value;
108
+ }
109
+ };
110
+ var NullASTNodeImpl = class extends ASTNodeImpl {
111
+ type = "null";
112
+ value = null;
113
+ };
114
+ var PropertyASTNodeImpl = class extends ASTNodeImpl {
115
+ type = "property";
116
+ keyNode;
117
+ valueNode;
118
+ constructor(jsonNode, parent, keyNode) {
119
+ super(jsonNode, parent);
120
+ this.keyNode = keyNode;
121
+ }
122
+ get children() {
123
+ return this.valueNode ? [this.keyNode, this.valueNode] : [this.keyNode];
124
+ }
125
+ };
126
+ var ViewASTNodeImpl = class extends ASTNodeImpl {
127
+ type = "view";
128
+ properties = [];
129
+ id = void 0;
130
+ viewType = void 0;
131
+ get children() {
132
+ return this.properties;
133
+ }
134
+ };
135
+ var ContentASTNodeImpl = class extends ASTNodeImpl {
136
+ type = "content";
137
+ properties = [];
138
+ views = void 0;
139
+ navigation = void 0;
140
+ get children() {
141
+ return this.properties;
142
+ }
143
+ };
144
+ var NavigationASTNodeImpl = class extends ASTNodeImpl {
145
+ type = "navigation";
146
+ properties = [];
147
+ begin = void 0;
148
+ flows = [];
149
+ get children() {
150
+ return this.properties;
151
+ }
152
+ };
153
+ var FlowASTNodeImpl = class extends ASTNodeImpl {
154
+ type = "flow";
155
+ properties = [];
156
+ start = void 0;
157
+ states = [];
158
+ get children() {
159
+ return this.properties;
160
+ }
161
+ };
162
+ var FlowStateASTNodeImpl = class extends ASTNodeImpl {
163
+ type = "state";
164
+ properties = [];
165
+ stateType = void 0;
166
+ get children() {
167
+ return this.properties;
168
+ }
169
+ };
170
+ var AssetASTNodeImpl = class extends ASTNodeImpl {
171
+ type = "asset";
172
+ properties = [];
173
+ id = void 0;
174
+ assetType = void 0;
175
+ get children() {
176
+ return this.properties;
177
+ }
178
+ };
179
+ var ArrayASTNodeImpl = class extends ASTNodeImpl {
180
+ type = "array";
181
+ items = [];
182
+ get children() {
183
+ return this.items;
184
+ }
185
+ };
186
+ var ObjectASTNodeImpl = class extends ASTNodeImpl {
187
+ type = "object";
188
+ properties = [];
189
+ get children() {
190
+ return this.properties;
191
+ }
192
+ };
193
+
194
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-service/src/parser/jsonParseErrors.ts
195
+ import { printParseErrorCode } from "jsonc-parser";
196
+ import {
197
+ Diagnostic,
198
+ Range,
199
+ DiagnosticSeverity
200
+ } from "vscode-languageserver-types";
201
+ function prettyPrintParseErrorCode(code) {
202
+ switch (code) {
203
+ case 6 /* CommaExpected */:
204
+ return `Expected comma`;
205
+ case 5 /* ColonExpected */:
206
+ return `Expected colon`;
207
+ case 3 /* PropertyNameExpected */:
208
+ return `Expected property name`;
209
+ case 4 /* ValueExpected */:
210
+ return `Expected value`;
211
+ case 7 /* CloseBraceExpected */:
212
+ return `Expected }`;
213
+ case 9 /* EndOfFileExpected */:
214
+ return `Expected end of file`;
215
+ case 8 /* CloseBracketExpected */:
216
+ return `Expected ]`;
217
+ case 12 /* UnexpectedEndOfString */:
218
+ return `Expected "`;
219
+ default:
220
+ return printParseErrorCode(code);
221
+ }
222
+ }
223
+ function convertErrorsToDiags(document, errors) {
224
+ return errors.map((parseError) => {
225
+ return Diagnostic.create(
226
+ Range.create(
227
+ document.positionAt(parseError.offset),
228
+ document.positionAt(parseError.offset + parseError.length)
229
+ ),
230
+ prettyPrintParseErrorCode(parseError.error),
231
+ DiagnosticSeverity.Error
232
+ );
233
+ });
234
+ }
235
+
236
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-service/src/parser/document.ts
237
+ function isStringProperty(node) {
238
+ return node.valueNode?.type === "string";
239
+ }
240
+ var PlayerContent = class {
241
+ root;
242
+ syntaxErrors;
243
+ jsonNodeToNode;
244
+ constructor(root, errors, jsonToNodeMap) {
245
+ this.root = root;
246
+ this.jsonNodeToNode = jsonToNodeMap;
247
+ this.syntaxErrors = errors;
248
+ }
249
+ getNodeFromOffset(offset) {
250
+ const jsonNode = findNodeAtOffset(this.root.jsonNode, offset);
251
+ if (!jsonNode) {
252
+ return;
253
+ }
254
+ if (this.jsonNodeToNode.has(jsonNode)) {
255
+ return this.jsonNodeToNode.get(jsonNode);
256
+ }
257
+ const parentNode = jsonNode.parent;
258
+ if (this.jsonNodeToNode.has(parentNode)) {
259
+ return this.jsonNodeToNode.get(parentNode);
260
+ }
261
+ const grandparentNode = parentNode.parent;
262
+ if (this.jsonNodeToNode.has(grandparentNode)) {
263
+ return this.jsonNodeToNode.get(grandparentNode);
264
+ }
265
+ const greatGrandparentNode = grandparentNode.parent;
266
+ if (this.jsonNodeToNode.has(greatGrandparentNode)) {
267
+ return this.jsonNodeToNode.get(greatGrandparentNode);
268
+ }
269
+ }
270
+ };
271
+ var ObjType = /* @__PURE__ */ ((ObjType2) => {
272
+ ObjType2[ObjType2["FLOW"] = 0] = "FLOW";
273
+ ObjType2[ObjType2["ASSET"] = 1] = "ASSET";
274
+ ObjType2[ObjType2["ASSET_WRAPPER"] = 2] = "ASSET_WRAPPER";
275
+ ObjType2[ObjType2["UNKNOWN"] = 3] = "UNKNOWN";
276
+ return ObjType2;
277
+ })(ObjType || {});
278
+ function identify(node) {
279
+ if (node === void 0 || node.type !== "object") {
280
+ return 3 /* UNKNOWN */;
281
+ }
282
+ const knownProps = node.children?.reduce((props, childNode) => {
283
+ if (childNode.type === "property" && childNode.children) {
284
+ const [key] = childNode.children;
285
+ props.add(key.value);
286
+ }
287
+ return props;
288
+ }, /* @__PURE__ */ new Set());
289
+ if (knownProps?.has("type")) {
290
+ return 1 /* ASSET */;
291
+ }
292
+ return 0 /* FLOW */;
293
+ }
294
+ function parse(document) {
295
+ const errors = [];
296
+ const jsonToNode = /* @__PURE__ */ new Map();
297
+ const root = parseTree(document.getText(), errors, {
298
+ disallowComments: true
299
+ });
300
+ const diags = convertErrorsToDiags(document, errors);
301
+ function parseAsset(node, parent) {
302
+ const assetNode = new AssetASTNodeImpl(node, parent);
303
+ node.children?.forEach((prop) => {
304
+ if (prop.type === "property" && prop.children?.length) {
305
+ const [key, val] = prop.children;
306
+ const keyNode = new StringASTNodeImpl(key);
307
+ const property = new PropertyASTNodeImpl(prop, assetNode, keyNode);
308
+ property.keyNode = new StringASTNodeImpl(key, property);
309
+ property.valueNode = parseUnknownNode(val, property);
310
+ if (key.value === "id" && isStringProperty(property)) {
311
+ assetNode.id = property;
312
+ } else if (key.value === "type" && isStringProperty(property)) {
313
+ assetNode.assetType = property;
314
+ }
315
+ assetNode.properties.push(property);
316
+ jsonToNode.set(prop, property);
317
+ jsonToNode.set(key, property.keyNode);
318
+ if (property.valueNode) {
319
+ jsonToNode.set(val, property.valueNode);
320
+ }
321
+ }
322
+ });
323
+ return assetNode;
324
+ }
325
+ function parseUnknownNode(node, parent) {
326
+ switch (node?.type) {
327
+ case "string": {
328
+ const newNode = new StringASTNodeImpl(node, parent);
329
+ jsonToNode.set(node, newNode);
330
+ return newNode;
331
+ }
332
+ case "null": {
333
+ const newNode = new NullASTNodeImpl(node, parent);
334
+ jsonToNode.set(node, newNode);
335
+ return newNode;
336
+ }
337
+ case "boolean": {
338
+ const newNode = new BooleanASTNodeImpl(node, parent);
339
+ jsonToNode.set(node, newNode);
340
+ return newNode;
341
+ }
342
+ case "number": {
343
+ const newNode = new NumberASTNodeImpl(node, parent);
344
+ jsonToNode.set(node, newNode);
345
+ return newNode;
346
+ }
347
+ case "array": {
348
+ const arr = new ArrayASTNodeImpl(node, parent);
349
+ node.children?.forEach((arrChild) => {
350
+ const child = parseUnknownNode(arrChild, arr);
351
+ if (child) {
352
+ jsonToNode.set(arrChild, child);
353
+ arr.items.push(child);
354
+ }
355
+ });
356
+ jsonToNode.set(node, arr);
357
+ return arr;
358
+ }
359
+ case "object": {
360
+ const obj = new ObjectASTNodeImpl(node, parent);
361
+ jsonToNode.set(node, obj);
362
+ node.children?.forEach((prop) => {
363
+ if (prop.type === "property" && prop.children?.length) {
364
+ const [key, val] = prop.children;
365
+ const keyNode = new StringASTNodeImpl(key);
366
+ const propNode = new PropertyASTNodeImpl(prop, obj, keyNode);
367
+ propNode.keyNode = new StringASTNodeImpl(key, propNode);
368
+ if (val) {
369
+ if (keyNode.value === "asset") {
370
+ propNode.valueNode = parseAsset(val, propNode);
371
+ } else {
372
+ propNode.valueNode = parseUnknownNode(val, propNode);
373
+ }
374
+ }
375
+ jsonToNode.set(prop, propNode);
376
+ jsonToNode.set(key, propNode.keyNode);
377
+ if (propNode.valueNode) {
378
+ jsonToNode.set(val, propNode.valueNode);
379
+ }
380
+ obj.properties.push(propNode);
381
+ }
382
+ });
383
+ return obj;
384
+ }
385
+ default:
386
+ }
387
+ }
388
+ function parseView(node, parent) {
389
+ const viewNode = new ViewASTNodeImpl(node, parent);
390
+ node.children?.forEach((prop) => {
391
+ if (prop.type === "property" && (prop.children?.length ?? 0) > 0) {
392
+ const [key, val] = prop.children ?? [];
393
+ const keyNode = new StringASTNodeImpl(key);
394
+ const property = new PropertyASTNodeImpl(prop, viewNode, keyNode);
395
+ property.keyNode = new StringASTNodeImpl(key, property);
396
+ if (val) {
397
+ property.valueNode = parseUnknownNode(val, property);
398
+ if (key.value === "id" && isStringProperty(property)) {
399
+ viewNode.id = property;
400
+ } else if (key.value === "type" && isStringProperty(property)) {
401
+ viewNode.viewType = property;
402
+ }
403
+ }
404
+ jsonToNode.set(prop, property);
405
+ jsonToNode.set(key, property.keyNode);
406
+ if (property.valueNode) {
407
+ jsonToNode.set(val, property.valueNode);
408
+ }
409
+ viewNode.properties.push(property);
410
+ }
411
+ });
412
+ jsonToNode.set(node, viewNode);
413
+ return viewNode;
414
+ }
415
+ function parseFlowState(node, parent) {
416
+ const state = new FlowStateASTNodeImpl(node, parent);
417
+ jsonToNode.set(node, state);
418
+ if (node.type === "object") {
419
+ node.children?.forEach((prop) => {
420
+ if (prop.type === "property" && prop.children?.length) {
421
+ const [key, val] = prop.children;
422
+ const keyNode = new StringASTNodeImpl(key);
423
+ const property = new PropertyASTNodeImpl(prop, state, keyNode);
424
+ property.keyNode = new StringASTNodeImpl(key, property);
425
+ if (key.value === "state_type" && val?.type === "string") {
426
+ property.valueNode = parseUnknownNode(val, property);
427
+ state.stateType = property;
428
+ } else {
429
+ property.valueNode = parseUnknownNode(val, property);
430
+ }
431
+ jsonToNode.set(prop, property);
432
+ jsonToNode.set(key, property.keyNode);
433
+ if (property.valueNode) {
434
+ jsonToNode.set(val, property.valueNode);
435
+ }
436
+ state.properties.push(property);
437
+ }
438
+ });
439
+ }
440
+ return state;
441
+ }
442
+ function parseFlow(node, parent) {
443
+ const flow = new FlowASTNodeImpl(node, parent);
444
+ jsonToNode.set(node, flow);
445
+ if (node.type === "object") {
446
+ node.children?.forEach((prop) => {
447
+ if (prop.type === "property" && prop.children?.length) {
448
+ const [key, val] = prop.children;
449
+ const keyNode = new StringASTNodeImpl(key);
450
+ const property = new PropertyASTNodeImpl(prop, flow, keyNode);
451
+ property.keyNode = new StringASTNodeImpl(key, property);
452
+ if (key.value === "startState" && val?.type === "string") {
453
+ property.valueNode = parseUnknownNode(val, property);
454
+ flow.start = property;
455
+ } else if (val?.type === "object" && property.keyNode.value !== "onStart" && property.keyNode.value !== "onEnd") {
456
+ property.valueNode = parseFlowState(val, property);
457
+ flow.states.push(property);
458
+ } else {
459
+ property.valueNode = parseUnknownNode(val, property);
460
+ }
461
+ jsonToNode.set(prop, property);
462
+ jsonToNode.set(key, property.keyNode);
463
+ if (property.valueNode) {
464
+ jsonToNode.set(val, property.valueNode);
465
+ }
466
+ flow.properties.push(property);
467
+ }
468
+ });
469
+ }
470
+ return flow;
471
+ }
472
+ function parseNavigation(node, parent) {
473
+ const navNode = new NavigationASTNodeImpl(node, parent);
474
+ jsonToNode.set(node, navNode);
475
+ if (node.type === "object") {
476
+ node.children?.forEach((prop) => {
477
+ if (prop.type === "property" && prop.children?.length) {
478
+ const [key, val] = prop.children;
479
+ const keyNode = new StringASTNodeImpl(key);
480
+ const property = new PropertyASTNodeImpl(prop, navNode, keyNode);
481
+ property.keyNode = new StringASTNodeImpl(key, property);
482
+ if (key.value === "BEGIN" && val?.type === "string") {
483
+ property.valueNode = parseUnknownNode(val, property);
484
+ navNode.begin = property;
485
+ } else if (val?.type === "object") {
486
+ property.valueNode = parseFlow(val, property);
487
+ navNode.flows.push(property);
488
+ }
489
+ jsonToNode.set(prop, property);
490
+ jsonToNode.set(key, property.keyNode);
491
+ if (property.valueNode) {
492
+ jsonToNode.set(val, property.valueNode);
493
+ }
494
+ navNode.properties.push(property);
495
+ }
496
+ });
497
+ }
498
+ return navNode;
499
+ }
500
+ function parseContent(node) {
501
+ const contentNode = new ContentASTNodeImpl(node, void 0);
502
+ if (node.type === "object") {
503
+ node.children?.forEach((childProp) => {
504
+ if (childProp.type === "property" && childProp.children?.length) {
505
+ const [key, val] = childProp.children;
506
+ const keyNode = new StringASTNodeImpl(key);
507
+ const property = new PropertyASTNodeImpl(
508
+ childProp,
509
+ contentNode,
510
+ keyNode
511
+ );
512
+ property.keyNode = new StringASTNodeImpl(key, property);
513
+ if (key.value === "views" && val?.type === "array") {
514
+ const views = new ArrayASTNodeImpl(val, property);
515
+ val.children?.forEach((view) => {
516
+ const parsedV = parseView(view, views);
517
+ jsonToNode.set(view, parsedV);
518
+ views.items.push(parsedV);
519
+ });
520
+ property.valueNode = views;
521
+ contentNode.views = property;
522
+ } else if (key.value === "navigation" && val) {
523
+ const nav = parseNavigation(val, property);
524
+ contentNode.navigation = property;
525
+ property.valueNode = nav;
526
+ } else if (val) {
527
+ property.valueNode = parseUnknownNode(val, property);
528
+ }
529
+ jsonToNode.set(childProp, property);
530
+ jsonToNode.set(key, property.keyNode);
531
+ if (property.valueNode) {
532
+ jsonToNode.set(val, property.valueNode);
533
+ }
534
+ contentNode.properties.push(property);
535
+ }
536
+ });
537
+ }
538
+ jsonToNode.set(node, contentNode);
539
+ return contentNode;
540
+ }
541
+ let rootASTNode = {
542
+ type: "empty",
543
+ value: void 0,
544
+ jsonNode: root
545
+ };
546
+ const objType = identify(root);
547
+ switch (objType) {
548
+ case 1 /* ASSET */:
549
+ rootASTNode = parseAsset(root);
550
+ break;
551
+ case 0 /* FLOW */:
552
+ rootASTNode = parseContent(root);
553
+ break;
554
+ default:
555
+ break;
556
+ }
557
+ return new PlayerContent(rootASTNode, diags, jsonToNode);
558
+ }
559
+
560
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-service/src/parser/edits.ts
561
+ import { TextEdit, Range as Range2 } from "vscode-languageserver-types";
562
+ function replaceString(node, newText) {
563
+ return {
564
+ type: "replace",
565
+ node,
566
+ value: newText
567
+ };
568
+ }
569
+ function toRange(document, node) {
570
+ return Range2.create(
571
+ document.positionAt(node.jsonNode.offset),
572
+ document.positionAt(node.jsonNode.offset + node.jsonNode.length)
573
+ );
574
+ }
575
+ function toTextEdit(document, edit) {
576
+ switch (edit.type) {
577
+ case "replace":
578
+ return TextEdit.replace(toRange(document, edit.node), edit.value);
579
+ default:
580
+ throw new Error("Dont know how to convert this to a TextEdit");
581
+ }
582
+ }
583
+
584
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-service/src/parser/index.ts
585
+ async function walk(node, visitor) {
586
+ const queue = [node];
587
+ let stop = false;
588
+ while (queue.length > 0 && !stop) {
589
+ const nodeToVisit = queue.shift();
590
+ if (nodeToVisit?.children) {
591
+ queue.push(...nodeToVisit.children);
592
+ }
593
+ stop = nodeToVisit ? await visitor(nodeToVisit) : true;
594
+ }
595
+ }
596
+ function getNodeValue(node) {
597
+ return getJSONNodeValue(node.jsonNode);
598
+ }
599
+
600
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-service/src/utils.ts
601
+ import { Range as Range3, Location } from "vscode-languageserver-types";
602
+ import { TextDocument } from "vscode-languageserver-textdocument";
603
+ import detectIndent from "detect-indent";
604
+ var typeToVisitorMap = {
605
+ string: "StringNode",
606
+ number: "NumberNode",
607
+ boolean: "BooleanNode",
608
+ array: "ArrayNode",
609
+ null: "NullNode",
610
+ empty: "EmptyNode",
611
+ property: "PropertyNode",
612
+ object: "ObjectNode",
613
+ asset: "AssetNode",
614
+ view: "ViewNode",
615
+ content: "ContentNode",
616
+ navigation: "NavigationNode",
617
+ flow: "FlowNode",
618
+ state: "FlowStateNode"
619
+ };
620
+ function containsRange(source, range) {
621
+ const { start, end } = range;
622
+ const { start: srcStart, end: srcEnd } = source;
623
+ return start.line === srcStart.line && end.line === srcEnd.line && start.character >= srcStart.character && end.character <= srcEnd.character;
624
+ }
625
+ function toTextDocument(str) {
626
+ return TextDocument.create("foo", "json", 1, str);
627
+ }
628
+ function isKnownRootType(document) {
629
+ const { type } = document.root;
630
+ return type === "view" || type === "asset" || type === "content";
631
+ }
632
+ function isValueCompletion(node) {
633
+ return node.parent?.type === "property" && node.parent.valueNode === node;
634
+ }
635
+ function isPropertyCompletion(node) {
636
+ return node.parent?.type === "property" && node.parent.keyNode === node;
637
+ }
638
+ function getProperty(obj, name) {
639
+ if ("properties" in obj) {
640
+ return obj.properties.find(
641
+ (p) => p.keyNode.value === name
642
+ );
643
+ }
644
+ }
645
+ function getLSLocationOfNode(document, node) {
646
+ const nodeRange = Range3.create(
647
+ document.positionAt(node.jsonNode.offset),
648
+ document.positionAt(node.jsonNode.offset + node.jsonNode.length)
649
+ );
650
+ return Location.create(document.uri, nodeRange);
651
+ }
652
+ function getDepth(node) {
653
+ if (!node.parent) {
654
+ return 0;
655
+ }
656
+ if (node.type === "property") {
657
+ return getDepth(node.parent);
658
+ }
659
+ return 1 + getDepth(node.parent);
660
+ }
661
+ function formatLikeNode(document, originalNode, replacement) {
662
+ const { indent } = detectIndent(document.getText());
663
+ const depth = getDepth(originalNode);
664
+ return JSON.stringify(replacement, null, indent).split("\n").map((l, index) => index === 0 ? l : `${indent.repeat(depth)}${l}`).join("\n");
665
+ }
666
+ function mapFlowStateToType(flowType) {
667
+ let flowXLR;
668
+ switch (flowType) {
669
+ case "VIEW":
670
+ flowXLR = "NavigationFlowViewState";
671
+ break;
672
+ case "END":
673
+ flowXLR = "NavigationFlowEndState";
674
+ break;
675
+ case "ACTION":
676
+ flowXLR = "NavigationFlowActionState";
677
+ break;
678
+ case "EXTERNAL":
679
+ flowXLR = "NavigationFlowExternalState";
680
+ break;
681
+ case "FLOW":
682
+ flowXLR = "NavigationFlowFlowState";
683
+ break;
684
+ default:
685
+ break;
686
+ }
687
+ return flowXLR;
688
+ }
689
+
690
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-service/src/plugins/asset-wrapper-array-plugin.ts
691
+ var isInView = (node) => {
692
+ if (node.type === "view") {
693
+ return true;
694
+ }
695
+ if (!node.parent) {
696
+ return false;
697
+ }
698
+ return isInView(node.parent);
699
+ };
700
+ var checkTypesForAssetWrapper = (nodes) => {
701
+ for (let i = 0; i < nodes.length; i++) {
702
+ const node = nodes[i];
703
+ if (node.type === "object" && node.title?.includes("AssetWrapper")) {
704
+ return true;
705
+ } else if (node.type === "or") {
706
+ return checkTypesForAssetWrapper(node.or);
707
+ } else if (node.type === "and") {
708
+ return checkTypesForAssetWrapper(node.and);
709
+ }
710
+ }
711
+ return false;
712
+ };
713
+ var checkSwitchCase = (node) => {
714
+ return node.value === "staticSwitch" || node.value === "dynamicSwitch";
715
+ };
716
+ var AssetWrapperArrayPlugin = class {
717
+ name = "asset-wrapper-to-array";
718
+ apply(service) {
719
+ service.hooks.validate.tap(
720
+ this.name,
721
+ async (documentInfo, validationContext) => {
722
+ validationContext.useASTVisitor({
723
+ ArrayNode: async (arrayNode) => {
724
+ if (!isInView(arrayNode)) {
725
+ return;
726
+ }
727
+ const xlrInfo = service.XLRService.getTypeInfoAtPosition(arrayNode);
728
+ if (!xlrInfo) return;
729
+ const isAssetWrapper = checkTypesForAssetWrapper(xlrInfo.nodes);
730
+ const parentNode = arrayNode.parent;
731
+ if (parentNode?.type !== "property") {
732
+ return;
733
+ }
734
+ const targetLabel = parentNode.keyNode;
735
+ const isSwitchCase = checkSwitchCase(targetLabel);
736
+ if (isAssetWrapper && !isSwitchCase) {
737
+ let newAsset = {
738
+ asset: {
739
+ id: "",
740
+ type: "collection",
741
+ values: getNodeValue(arrayNode)
742
+ }
743
+ };
744
+ if (arrayNode.children.length === 1) {
745
+ newAsset = getNodeValue(arrayNode.children[0]);
746
+ }
747
+ validationContext.addViolation({
748
+ node: targetLabel,
749
+ severity: DiagnosticSeverity2.Error,
750
+ message: `Implicit Array -> "collection" assets is not supported.`,
751
+ fix: () => {
752
+ return {
753
+ name: `Convert to ${arrayNode.children.length > 0 ? "collection" : "asset"}`,
754
+ edit: {
755
+ type: "replace",
756
+ node: arrayNode,
757
+ value: formatLikeNode(
758
+ documentInfo.document,
759
+ arrayNode,
760
+ newAsset
761
+ )
762
+ }
763
+ };
764
+ }
765
+ });
766
+ }
767
+ }
768
+ });
769
+ }
770
+ );
771
+ }
772
+ };
773
+
774
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-service/src/plugins/binding-schema-plugin.ts
775
+ import { CompletionItemKind } from "vscode-languageserver-types";
776
+ function getBindingInfo(ctx) {
777
+ const info = {
778
+ bindingToSchemaType: /* @__PURE__ */ new Map(),
779
+ typeToNode: /* @__PURE__ */ new Map()
780
+ };
781
+ if (ctx.PlayerContent.root.type !== "content") {
782
+ return info;
783
+ }
784
+ const schemaRoot = ctx.PlayerContent.root.properties?.find(
785
+ (child) => child.keyNode.value === "schema"
786
+ );
787
+ if (!schemaRoot || schemaRoot.valueNode?.type !== "object") {
788
+ return info;
789
+ }
790
+ const schemaTypeQueue = [
791
+ {
792
+ currentPath: "",
793
+ typeToVisit: "ROOT",
794
+ visited: /* @__PURE__ */ new Set()
795
+ }
796
+ ];
797
+ while (schemaTypeQueue.length > 0) {
798
+ const next = schemaTypeQueue.shift();
799
+ if (!next) {
800
+ break;
801
+ }
802
+ if (next.visited.has(next.typeToVisit)) {
803
+ continue;
804
+ }
805
+ const visited = new Set(...next.visited, next.typeToVisit);
806
+ const { currentPath, typeToVisit } = next;
807
+ const typeNode = schemaRoot.valueNode.properties.find(
808
+ (child) => child.keyNode.value === typeToVisit
809
+ );
810
+ if (!typeNode || typeNode.valueNode?.type !== "object") {
811
+ continue;
812
+ }
813
+ info.typeToNode.set(typeToVisit, { type: typeToVisit, typeNode });
814
+ typeNode.valueNode.properties.forEach((prop) => {
815
+ const nextPath = [currentPath, prop.keyNode.value].join(
816
+ currentPath === "" ? "" : "."
817
+ );
818
+ info.bindingToSchemaType.set(nextPath, {
819
+ binding: nextPath,
820
+ typeName: typeToVisit,
821
+ key: prop.keyNode.value
822
+ });
823
+ if (prop.valueNode?.type === "object") {
824
+ const nestedTypeName = prop.valueNode.properties.find(
825
+ (c) => c.keyNode.value === "type"
826
+ );
827
+ if (nestedTypeName && nestedTypeName.valueNode?.type === "string") {
828
+ schemaTypeQueue.push({
829
+ currentPath: nextPath,
830
+ typeToVisit: nestedTypeName.valueNode.value,
831
+ visited
832
+ });
833
+ }
834
+ }
835
+ });
836
+ }
837
+ return info;
838
+ }
839
+ var checkTypesForBinding = (nodes) => {
840
+ for (let i = 0; i < nodes.length; i++) {
841
+ const node = nodes[i];
842
+ if (node.type === "string" && node.name === "Binding") return true;
843
+ if (node.type === "or") return checkTypesForBinding(node.or);
844
+ if (node.type === "and") return checkTypesForBinding(node.and);
845
+ }
846
+ return false;
847
+ };
848
+ function isBindingPropertyAssignment(ctx) {
849
+ if (ctx.node.type !== "string" || ctx.node.parent?.type !== "property") {
850
+ return false;
851
+ }
852
+ if (checkTypesForBinding(ctx.XLR?.nodes ?? [])) {
853
+ return true;
854
+ }
855
+ return false;
856
+ }
857
+ function getLocationForBindingTypeDefinition(ctx, schemaInfo) {
858
+ if (!isBindingPropertyAssignment(ctx)) {
859
+ return;
860
+ }
861
+ const existingBindingValue = ctx.node.value;
862
+ const info = schemaInfo.bindingToSchemaType.get(existingBindingValue);
863
+ if (!info) {
864
+ return;
865
+ }
866
+ const nodeLocation = schemaInfo.typeToNode.get(info.typeName);
867
+ if (!nodeLocation || nodeLocation.typeNode.valueNode?.type !== "object") {
868
+ return;
869
+ }
870
+ const prop = getProperty(nodeLocation.typeNode.valueNode, info.key);
871
+ if (!prop) {
872
+ return;
873
+ }
874
+ return getLSLocationOfNode(ctx.document, prop);
875
+ }
876
+ function getLocationForSchemaType(ctx, schemaInfo) {
877
+ if (isValueCompletion(ctx.node)) {
878
+ if (ctx.node.parent?.type === "property" && ctx.node.type === "string" && ctx.node.parent.keyNode.value === "type") {
879
+ const typeName = ctx.node.value;
880
+ const node = schemaInfo.typeToNode.get(typeName);
881
+ if (!node) {
882
+ return;
883
+ }
884
+ const schemaPropNode = getContentNode(ctx.node)?.properties.find(
885
+ (p) => p.keyNode.value === "schema"
886
+ );
887
+ if (schemaPropNode?.valueNode?.type !== "object") {
888
+ return;
889
+ }
890
+ const schemaTypeNode = schemaPropNode.valueNode.properties.find(
891
+ (p) => p.keyNode.value === typeName
892
+ );
893
+ if (schemaTypeNode !== node.typeNode) {
894
+ return;
895
+ }
896
+ return getLSLocationOfNode(ctx.document, node.typeNode);
897
+ }
898
+ }
899
+ }
900
+ var SchemaInfoPlugin = class {
901
+ name = "view-node";
902
+ apply(service) {
903
+ let schemaInfo;
904
+ service.hooks.onDocumentUpdate.tap(this.name, (ctx) => {
905
+ schemaInfo = getBindingInfo(ctx);
906
+ });
907
+ service.hooks.complete.tap(this.name, async (ctx, completionCtx) => {
908
+ if (!isBindingPropertyAssignment(ctx)) {
909
+ return;
910
+ }
911
+ const existingBindingValue = ctx.node.value;
912
+ const bindings = Array.from(
913
+ schemaInfo?.bindingToSchemaType.keys() ?? []
914
+ ).filter((k) => k.startsWith(existingBindingValue));
915
+ bindings.forEach((b) => {
916
+ completionCtx.addCompletionItem({
917
+ kind: CompletionItemKind.Value,
918
+ label: b.substring(existingBindingValue.length)
919
+ });
920
+ });
921
+ });
922
+ service.hooks.definition.tap(this.name, (ctx) => {
923
+ if (!schemaInfo) {
924
+ return;
925
+ }
926
+ return getLocationForSchemaType(ctx, schemaInfo) || getLocationForBindingTypeDefinition(ctx, schemaInfo);
927
+ });
928
+ }
929
+ };
930
+
931
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-service/src/plugins/xlr-plugin.ts
932
+ import {
933
+ CompletionItemKind as CompletionItemKind2,
934
+ DiagnosticSeverity as DiagnosticSeverity3,
935
+ MarkupKind
936
+ } from "vscode-languageserver-types";
937
+ function isError(issue) {
938
+ return issue.severity === DiagnosticSeverity3.Error;
939
+ }
940
+ var findErrorNode = (rootNode, nodeToFind) => {
941
+ const children = [rootNode];
942
+ while (children.length > 0) {
943
+ const child = children.pop();
944
+ if (child.jsonNode === nodeToFind) {
945
+ return child;
946
+ }
947
+ if (child.children) {
948
+ children.push(...child.children);
949
+ }
950
+ }
951
+ return rootNode;
952
+ };
953
+ var translateSeverity = (severity) => {
954
+ return severity;
955
+ };
956
+ function createValidationVisitor(ctx, sdk) {
957
+ const nodesWithErrors = /* @__PURE__ */ new Set();
958
+ return {
959
+ AssetNode: (assetNode) => {
960
+ let expectedType = assetNode.assetType?.valueNode?.value;
961
+ if (!sdk.hasType(expectedType)) {
962
+ ctx.addViolation({
963
+ node: assetNode,
964
+ message: `Warning - Asset Type ${assetNode.assetType?.valueNode?.value} was not loaded into Validator definitions`,
965
+ severity: DiagnosticSeverity3.Error
966
+ });
967
+ expectedType = "Asset";
968
+ }
969
+ const validationIssues = sdk.validateByName(
970
+ expectedType,
971
+ assetNode.jsonNode
972
+ );
973
+ validationIssues.forEach((issue) => {
974
+ if (!(nodesWithErrors.has(issue.node) && isError(issue))) {
975
+ ctx.addViolation({
976
+ node: findErrorNode(assetNode, issue.node),
977
+ message: isError(issue) ? `Asset Validation Error - ${issue.type}: ${issue.message}` : issue.message,
978
+ severity: translateSeverity(issue.severity)
979
+ });
980
+ if (isError(issue)) {
981
+ nodesWithErrors.add(issue.node);
982
+ }
983
+ }
984
+ });
985
+ },
986
+ ViewNode: (viewNode) => {
987
+ let expectedType = viewNode.viewType?.valueNode?.value;
988
+ if (!sdk.hasType(expectedType)) {
989
+ ctx.addViolation({
990
+ node: viewNode,
991
+ message: `Warning - View Type ${viewNode.viewType?.valueNode?.value} was not loaded into Validator definitions`,
992
+ severity: DiagnosticSeverity3.Error
993
+ });
994
+ expectedType = "View";
995
+ }
996
+ const validationIssues = sdk.validateByName(
997
+ expectedType,
998
+ viewNode.jsonNode
999
+ );
1000
+ validationIssues.forEach((issue) => {
1001
+ if (!(nodesWithErrors.has(issue.node) && isError(issue))) {
1002
+ ctx.addViolation({
1003
+ node: findErrorNode(viewNode, issue.node),
1004
+ message: isError(issue) ? `View Validation Error - ${issue.type}: ${issue.message}` : issue.message,
1005
+ severity: translateSeverity(issue.severity)
1006
+ });
1007
+ if (isError(issue)) {
1008
+ nodesWithErrors.add(issue.node);
1009
+ }
1010
+ }
1011
+ });
1012
+ },
1013
+ ContentNode: (contentNode) => {
1014
+ const flowType = sdk.getType("Flow");
1015
+ if (!flowType) {
1016
+ throw new Error(
1017
+ "Flow is not a registered type, can't validate content. Did you load a version of the base Player types?"
1018
+ );
1019
+ }
1020
+ const assetType = sdk.getType("Asset");
1021
+ if (!assetType) {
1022
+ throw new Error(
1023
+ "Asset is not a registered type, can't validate content. Did you load a version of the base Player types?"
1024
+ );
1025
+ }
1026
+ if (flowType.type === "object" && flowType.properties.views?.node.type === "array") {
1027
+ flowType.properties.views.node.elementType = assetType;
1028
+ }
1029
+ const validationIssues = sdk.validateByType(
1030
+ flowType,
1031
+ contentNode.jsonNode
1032
+ );
1033
+ validationIssues.forEach((issue) => {
1034
+ if (!nodesWithErrors.has(issue.node) || issue.type === "missing") {
1035
+ nodesWithErrors.add(issue.node);
1036
+ ctx.addViolation({
1037
+ node: findErrorNode(contentNode, issue.node),
1038
+ message: `Content Validation Error - ${issue.type}: ${issue.message}`,
1039
+ severity: DiagnosticSeverity3.Error
1040
+ });
1041
+ }
1042
+ });
1043
+ },
1044
+ NavigationNode: (navigationNode) => {
1045
+ const expectedType = "Navigation";
1046
+ const validationIssues = sdk.validateByName(
1047
+ expectedType,
1048
+ navigationNode.jsonNode
1049
+ );
1050
+ validationIssues.forEach((issue) => {
1051
+ if (!nodesWithErrors.has(issue.node) || issue.type === "missing") {
1052
+ nodesWithErrors.add(issue.node);
1053
+ ctx.addViolation({
1054
+ node: findErrorNode(navigationNode, issue.node),
1055
+ message: `Navigation Validation Error - ${issue.type}: ${issue.message}`,
1056
+ severity: DiagnosticSeverity3.Error
1057
+ });
1058
+ }
1059
+ });
1060
+ },
1061
+ FlowNode: (flowNode) => {
1062
+ const expectedType = "NavigationFlow";
1063
+ const validationIssues = sdk.validateByName(
1064
+ expectedType,
1065
+ flowNode.jsonNode
1066
+ );
1067
+ validationIssues.forEach((issue) => {
1068
+ if (!nodesWithErrors.has(issue.node) || issue.type === "missing") {
1069
+ nodesWithErrors.add(issue.node);
1070
+ ctx.addViolation({
1071
+ node: findErrorNode(flowNode, issue.node),
1072
+ message: `Navigation Flow Validation Error - ${issue.type}: ${issue.message}`,
1073
+ severity: DiagnosticSeverity3.Error
1074
+ });
1075
+ }
1076
+ });
1077
+ },
1078
+ FlowStateNode: (flowStateNode) => {
1079
+ const flowxlr = mapFlowStateToType(
1080
+ flowStateNode.stateType?.valueNode?.value
1081
+ );
1082
+ if (flowxlr) {
1083
+ const validationIssues = sdk.validateByName(
1084
+ flowxlr,
1085
+ flowStateNode.jsonNode
1086
+ );
1087
+ validationIssues.forEach((issue) => {
1088
+ if (!nodesWithErrors.has(issue.node) || issue.type === "missing") {
1089
+ nodesWithErrors.add(issue.node);
1090
+ ctx.addViolation({
1091
+ node: findErrorNode(flowStateNode, issue.node),
1092
+ message: `Navigation Node Validation Error - ${issue.type}: ${issue.message}`,
1093
+ severity: DiagnosticSeverity3.Error
1094
+ });
1095
+ }
1096
+ });
1097
+ } else {
1098
+ ctx.addViolation({
1099
+ node: flowStateNode,
1100
+ message: "Unknown Flow Type, valid options are: VIEW, END, ACTION, EXTERNAL, FLOW",
1101
+ severity: DiagnosticSeverity3.Error
1102
+ });
1103
+ }
1104
+ }
1105
+ };
1106
+ }
1107
+ function getObjectCompletions(authoredNode, potentialTypes) {
1108
+ const completions = [];
1109
+ const presentKeys = /* @__PURE__ */ new Set();
1110
+ if (authoredNode.properties) {
1111
+ authoredNode.properties.forEach(
1112
+ (propertyNode) => presentKeys.add(propertyNode.keyNode.value)
1113
+ );
1114
+ }
1115
+ potentialTypes.forEach((node) => {
1116
+ if (node.type === "object") {
1117
+ Object.keys(node.properties).forEach((prop) => {
1118
+ if (!presentKeys.has(prop)) {
1119
+ completions.push({
1120
+ label: prop,
1121
+ documentation: node.properties[prop].node.description ?? node.properties[prop].node.title,
1122
+ kind: CompletionItemKind2.Property
1123
+ });
1124
+ }
1125
+ });
1126
+ } else if (node.type === "and") {
1127
+ completions.push(...getObjectCompletions(authoredNode, node.and));
1128
+ } else if (node.type === "or") {
1129
+ completions.push(...getObjectCompletions(authoredNode, node.or));
1130
+ }
1131
+ });
1132
+ return completions;
1133
+ }
1134
+ function getPropertyCompletions(propertyName, potentialTypes) {
1135
+ const completions = [];
1136
+ potentialTypes.forEach((nodeType) => {
1137
+ if (nodeType.type === "object") {
1138
+ const propertyNode = nodeType.properties[propertyName]?.node;
1139
+ if (propertyNode && propertyNode.type === "string" && propertyNode.const) {
1140
+ completions.push({
1141
+ label: propertyNode.const,
1142
+ kind: CompletionItemKind2.Value
1143
+ });
1144
+ }
1145
+ }
1146
+ });
1147
+ return completions;
1148
+ }
1149
+ function complete(ctx) {
1150
+ if (ctx.XLR?.nearestObjects) {
1151
+ if (ctx.node.type === "string" && ctx.node?.parent?.type === "property") {
1152
+ return getPropertyCompletions(
1153
+ ctx.node.parent.keyNode.value,
1154
+ ctx.XLR.nearestObjects
1155
+ );
1156
+ }
1157
+ return getObjectCompletions(ctx.node, ctx.XLR.nearestObjects);
1158
+ }
1159
+ return [];
1160
+ }
1161
+ function hover(ctx) {
1162
+ if (ctx.XLR && ctx.node.type === "string") {
1163
+ const docStrings = [];
1164
+ const prop = ctx.node.value;
1165
+ ctx.XLR.nearestObjects.forEach((typeNode) => {
1166
+ const docString = typeNode.properties[prop]?.node?.description ?? typeNode.properties[prop]?.node?.title ?? void 0;
1167
+ if (docString) {
1168
+ docStrings.push(docString);
1169
+ }
1170
+ });
1171
+ if (docStrings.length > 1) {
1172
+ return {
1173
+ contents: {
1174
+ kind: MarkupKind.PlainText,
1175
+ value: "Docs unavailable - More than one type could exist at this location"
1176
+ }
1177
+ };
1178
+ }
1179
+ return {
1180
+ contents: {
1181
+ kind: MarkupKind.PlainText,
1182
+ value: docStrings[0] ?? "Error getting docs"
1183
+ }
1184
+ };
1185
+ }
1186
+ }
1187
+ var XLRPlugin = class {
1188
+ name = "xlr-plugin";
1189
+ apply(service) {
1190
+ service.hooks.validate.tap(this.name, async (ctx, validation) => {
1191
+ validation.useASTVisitor(
1192
+ createValidationVisitor(validation, service.XLRService.XLRSDK)
1193
+ );
1194
+ });
1195
+ service.hooks.complete.tap(this.name, async (ctx, completion) => {
1196
+ complete(ctx).map((i) => completion.addCompletionItem(i));
1197
+ });
1198
+ service.hooks.hover.tap(this.name, (ctx) => {
1199
+ return hover(ctx);
1200
+ });
1201
+ }
1202
+ };
1203
+
1204
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-service/src/plugins/duplicate-id-plugin.ts
1205
+ import { DiagnosticSeverity as DiagnosticSeverity4 } from "vscode-languageserver-types";
1206
+ var checkParentTemplate = (node, depth = 0) => {
1207
+ if (node.parent) {
1208
+ if (isPropertyNode(node.parent) && node.parent.keyNode.value === "template") {
1209
+ depth += 1;
1210
+ return checkParentTemplate(node.parent, depth);
1211
+ }
1212
+ return checkParentTemplate(node.parent, depth);
1213
+ }
1214
+ return depth;
1215
+ };
1216
+ var generateID = (node) => {
1217
+ if (!node || node.type === "view") {
1218
+ return "";
1219
+ }
1220
+ const prefix = generateID(node.parent);
1221
+ let current = "";
1222
+ if (node.type === "property") {
1223
+ current = node.keyNode.value;
1224
+ } else if (node.type === "asset" && node.assetType?.valueNode?.value) {
1225
+ current = node.assetType.valueNode?.value;
1226
+ }
1227
+ return [prefix, current].filter(Boolean).join("-");
1228
+ };
1229
+ var createViolation = (node) => {
1230
+ const valueNode = node.id?.valueNode;
1231
+ if (!valueNode) {
1232
+ return;
1233
+ }
1234
+ return {
1235
+ node: valueNode,
1236
+ severity: DiagnosticSeverity4.Error,
1237
+ message: `The id "${node.id?.valueNode?.value}" is already in use in this view.`,
1238
+ fix: () => {
1239
+ return {
1240
+ name: "Generate new ID",
1241
+ edit: replaceString(valueNode, `"${generateID(node)}"`)
1242
+ };
1243
+ }
1244
+ };
1245
+ };
1246
+ var createValidationVisitor2 = (ctx) => {
1247
+ const viewInfo = /* @__PURE__ */ new Map();
1248
+ return {
1249
+ AssetNode: (assetNode) => {
1250
+ const view = getViewNode(assetNode);
1251
+ if (!view) {
1252
+ throw new Error(
1253
+ "Asset found but not within a view. Something is wrong"
1254
+ );
1255
+ }
1256
+ const assetID = assetNode.id;
1257
+ if (!assetID || !assetID.valueNode?.value) {
1258
+ return;
1259
+ }
1260
+ const id = assetID.valueNode?.value;
1261
+ if (!viewInfo.has(view)) {
1262
+ viewInfo.set(view, /* @__PURE__ */ new Map());
1263
+ }
1264
+ const assetIDMap = viewInfo.get(view);
1265
+ const idInfo = assetIDMap?.get(id);
1266
+ const templateDepth = checkParentTemplate(assetNode);
1267
+ if (templateDepth > 0) {
1268
+ const expectedIndexElements = [];
1269
+ for (let i = 0; i < templateDepth; i++) {
1270
+ expectedIndexElements.push(`_index${i === 0 ? "" : i}_`);
1271
+ }
1272
+ const missingIndexSegments = expectedIndexElements.filter(
1273
+ (e) => !id.includes(e)
1274
+ );
1275
+ if (missingIndexSegments.length !== 0) {
1276
+ ctx.addViolation({
1277
+ node: assetNode,
1278
+ severity: DiagnosticSeverity4.Error,
1279
+ message: `The id for this templated elements is missing the following index segments: ${missingIndexSegments.join(
1280
+ ", "
1281
+ )}`
1282
+ });
1283
+ }
1284
+ }
1285
+ if (idInfo) {
1286
+ if (!idInfo.handled) {
1287
+ const origViolation = createViolation(idInfo.original);
1288
+ if (origViolation) {
1289
+ ctx.addViolation(origViolation);
1290
+ }
1291
+ idInfo.handled = true;
1292
+ }
1293
+ const assetViolation = createViolation(assetNode);
1294
+ if (assetViolation) {
1295
+ ctx.addViolation(assetViolation);
1296
+ }
1297
+ } else {
1298
+ assetIDMap?.set(id, { original: assetNode, handled: false });
1299
+ }
1300
+ }
1301
+ };
1302
+ };
1303
+ var DuplicateIDPlugin = class {
1304
+ name = "duplicate-id";
1305
+ apply(service) {
1306
+ service.hooks.validate.tap(this.name, async (ctx, validation) => {
1307
+ validation.useASTVisitor(createValidationVisitor2(validation));
1308
+ });
1309
+ }
1310
+ };
1311
+
1312
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-service/src/plugins/missing-asset-wrapper-plugin.ts
1313
+ import { DiagnosticSeverity as DiagnosticSeverity5 } from "vscode-languageserver-types";
1314
+ var getObjectTarget = (node) => {
1315
+ if (isObjectNode(node)) {
1316
+ return node;
1317
+ }
1318
+ if (isKeyNode(node) && isPropertyNode(node.parent) && isObjectNode(node.parent.valueNode)) {
1319
+ return node.parent.valueNode;
1320
+ }
1321
+ };
1322
+ var MissingAssetWrapperPlugin = class {
1323
+ name = "missing-asset-wrapper";
1324
+ apply(languageService) {
1325
+ languageService.hooks.onValidateEnd.tap(
1326
+ this.name,
1327
+ (diagnostics, { addFixableViolation, documentContext }) => {
1328
+ let filteredDiags = diagnostics;
1329
+ const expectedAssetDiags = diagnostics.filter(
1330
+ (d) => d.message.includes(
1331
+ `Does not match any of the expected types for type: 'AssetWrapperOrSwitch'`
1332
+ ) || d.message.startsWith("Expected property: asset")
1333
+ );
1334
+ expectedAssetDiags.forEach((d) => {
1335
+ const originalNode = documentContext.PlayerContent.getNodeFromOffset(
1336
+ documentContext.document.offsetAt(d.range.start)
1337
+ );
1338
+ const objectNode = getObjectTarget(originalNode);
1339
+ if (objectNode && originalNode) {
1340
+ const associatedDiags = filteredDiags.filter((nestedDiag) => {
1341
+ const diagNode = documentContext.PlayerContent.getNodeFromOffset(
1342
+ documentContext.document.offsetAt(nestedDiag.range.start)
1343
+ );
1344
+ return objectNode.properties.some((p) => p.keyNode === diagNode);
1345
+ });
1346
+ addFixableViolation(d, {
1347
+ node: originalNode,
1348
+ message: d.message,
1349
+ severity: d.severity ?? DiagnosticSeverity5.Error,
1350
+ fix: () => ({
1351
+ name: `Wrap in "asset"`,
1352
+ edit: {
1353
+ type: "replace",
1354
+ node: objectNode,
1355
+ value: formatLikeNode(documentContext.document, objectNode, {
1356
+ asset: getNodeValue(objectNode)
1357
+ })
1358
+ }
1359
+ })
1360
+ });
1361
+ filteredDiags = filteredDiags.filter(
1362
+ (filteredD) => !associatedDiags.includes(filteredD)
1363
+ );
1364
+ }
1365
+ });
1366
+ return filteredDiags;
1367
+ }
1368
+ );
1369
+ }
1370
+ };
1371
+
1372
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-service/src/plugins/nav-state-plugin.ts
1373
+ import {
1374
+ CompletionItemKind as CompletionItemKind3,
1375
+ DiagnosticSeverity as DiagnosticSeverity6
1376
+ } from "vscode-languageserver-types";
1377
+ var createValidationVisitor3 = (ctx) => {
1378
+ const validTransitions = /* @__PURE__ */ new Map();
1379
+ return {
1380
+ FlowNode: (flowNode) => {
1381
+ const flowNodeId = flowNode.parent?.keyNode.value;
1382
+ flowNode.states.forEach((p) => {
1383
+ if (!validTransitions.has(flowNodeId)) {
1384
+ validTransitions.set(flowNodeId, /* @__PURE__ */ new Set());
1385
+ }
1386
+ validTransitions.get(flowNodeId)?.add(p.keyNode.value);
1387
+ });
1388
+ },
1389
+ FlowStateNode: (flowState) => {
1390
+ const transitions = flowState.properties.find(
1391
+ (p) => p.keyNode.value === "transitions"
1392
+ );
1393
+ let flowNode = flowState.parent;
1394
+ while (flowNode && !isFlowNode(flowNode)) {
1395
+ flowNode = flowNode?.parent;
1396
+ }
1397
+ const flowNodeId = flowNode?.parent?.keyNode.value;
1398
+ transitions?.valueNode?.children?.forEach((transitionObjects) => {
1399
+ if (transitionObjects.type === "property" && transitionObjects.valueNode?.type === "string") {
1400
+ if (!validTransitions.get(flowNodeId)?.has(transitionObjects.valueNode.value)) {
1401
+ ctx.addViolation({
1402
+ node: transitionObjects.valueNode,
1403
+ severity: DiagnosticSeverity6.Error,
1404
+ message: `Node "${transitionObjects.valueNode.value}" not found`
1405
+ });
1406
+ }
1407
+ }
1408
+ });
1409
+ }
1410
+ };
1411
+ };
1412
+ var isTransitionValue = (node) => {
1413
+ return node.type === "string" && isPropertyNode(node.parent) && node.parent.parent?.type === "object" && isPropertyNode(node.parent.parent.parent) && node.parent.parent.parent.keyNode.value === "transitions" && isStateNode(node.parent.parent.parent.parent) && isPropertyNode(node.parent.parent.parent.parent.parent) && isFlowNode(node.parent.parent.parent.parent.parent.parent);
1414
+ };
1415
+ var getFlowNode = (node) => {
1416
+ if (isFlowNode(node)) {
1417
+ return node;
1418
+ }
1419
+ if (node.parent) {
1420
+ return getFlowNode(node.parent);
1421
+ }
1422
+ };
1423
+ var NavStatePlugin = class {
1424
+ name = "nav-state";
1425
+ apply(service) {
1426
+ service.hooks.validate.tap(this.name, async (ctx, validation) => {
1427
+ validation.useASTVisitor(createValidationVisitor3(validation));
1428
+ });
1429
+ service.hooks.complete.tap(this.name, async (ctx, completionCtx) => {
1430
+ if (!isValueCompletion(ctx.node)) {
1431
+ return;
1432
+ }
1433
+ if (isTransitionValue(ctx.node)) {
1434
+ const flowNode = getFlowNode(ctx.node);
1435
+ flowNode?.states.forEach((p) => {
1436
+ completionCtx.addCompletionItem({
1437
+ kind: CompletionItemKind3.Value,
1438
+ label: p.keyNode.value
1439
+ });
1440
+ });
1441
+ }
1442
+ });
1443
+ service.hooks.definition.tap(this.name, (ctx) => {
1444
+ if (!isValueCompletion(ctx.node)) {
1445
+ return;
1446
+ }
1447
+ if (ctx.node.type === "string" && isTransitionValue(ctx.node)) {
1448
+ const flowNode = getFlowNode(ctx.node);
1449
+ const { value } = ctx.node;
1450
+ const flowProp = flowNode?.states.find(
1451
+ (n) => n.keyNode.value === value
1452
+ );
1453
+ if (flowProp) {
1454
+ return getLSLocationOfNode(ctx.document, flowProp.keyNode);
1455
+ }
1456
+ }
1457
+ });
1458
+ }
1459
+ };
1460
+
1461
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-service/src/plugins/view-node-plugin.ts
1462
+ import {
1463
+ CompletionItemKind as CompletionItemKind4,
1464
+ DiagnosticSeverity as DiagnosticSeverity7
1465
+ } from "vscode-languageserver-types";
1466
+ var createValidationVisitor4 = (ctx, viewInfo) => {
1467
+ return {
1468
+ FlowStateNode: (flowState) => {
1469
+ if (flowState.stateType?.valueNode?.value === "VIEW") {
1470
+ const refNode = getProperty(flowState, "ref");
1471
+ if (!refNode || refNode.valueNode?.type !== "string") {
1472
+ return;
1473
+ }
1474
+ const refID = refNode.valueNode.value;
1475
+ if (viewInfo.views.has(refID)) {
1476
+ return;
1477
+ }
1478
+ ctx.addViolation({
1479
+ node: refNode.valueNode,
1480
+ message: `View with id: ${refID} does not exist.`,
1481
+ severity: DiagnosticSeverity7.Error
1482
+ });
1483
+ }
1484
+ },
1485
+ ViewNode: (viewNode) => {
1486
+ if (viewNode.id && viewNode.id.valueNode?.value !== void 0) {
1487
+ if (!viewInfo.nodes.get(viewNode.id.valueNode?.value)) {
1488
+ ctx.addViolation({
1489
+ node: viewNode.id.valueNode,
1490
+ message: `View is not reachable`,
1491
+ severity: DiagnosticSeverity7.Warning
1492
+ });
1493
+ }
1494
+ }
1495
+ }
1496
+ };
1497
+ };
1498
+ var getViewInfo = (ctx) => {
1499
+ const views = /* @__PURE__ */ new Map();
1500
+ const nodes = /* @__PURE__ */ new Map();
1501
+ const { root } = ctx.PlayerContent;
1502
+ if (root.type === "content") {
1503
+ root.views?.valueNode?.children.forEach((c) => {
1504
+ if (isViewNode(c) && c.id?.valueNode) {
1505
+ views.set(c.id.valueNode.value, {
1506
+ id: c.id.valueNode.value,
1507
+ idProp: c.id
1508
+ });
1509
+ }
1510
+ });
1511
+ root.navigation?.valueNode?.flows.forEach((flow) => {
1512
+ flow.valueNode?.states?.forEach((state) => {
1513
+ if (state.valueNode?.stateType?.valueNode?.value === "VIEW") {
1514
+ const ref = state.valueNode.properties.find(
1515
+ (p) => p.keyNode.value === "ref"
1516
+ );
1517
+ if (ref?.valueNode?.type === "string") {
1518
+ const refVal = ref.valueNode.value;
1519
+ nodes.set(refVal, {
1520
+ id: refVal,
1521
+ refProp: ref
1522
+ });
1523
+ }
1524
+ }
1525
+ });
1526
+ });
1527
+ }
1528
+ return {
1529
+ views,
1530
+ nodes
1531
+ };
1532
+ };
1533
+ var ViewNodePlugin = class {
1534
+ name = "view-node";
1535
+ apply(service) {
1536
+ let viewInfo;
1537
+ service.hooks.validate.tap(this.name, async (ctx, validation) => {
1538
+ if (!viewInfo) {
1539
+ return;
1540
+ }
1541
+ validation.useASTVisitor(createValidationVisitor4(validation, viewInfo));
1542
+ });
1543
+ service.hooks.onDocumentUpdate.tap(this.name, (ctx) => {
1544
+ viewInfo = getViewInfo(ctx);
1545
+ });
1546
+ service.hooks.complete.tap(this.name, async (ctx, completionCtx) => {
1547
+ if (!isValueCompletion(ctx.node)) {
1548
+ return;
1549
+ }
1550
+ if (ctx.node.type === "string" && isPropertyNode(ctx.node.parent) && isStateNode(ctx.node.parent.parent) && ctx.node.parent.keyNode.value === "ref") {
1551
+ Array.from(viewInfo?.views.keys() ?? []).forEach((vID) => {
1552
+ completionCtx.addCompletionItem({
1553
+ kind: CompletionItemKind4.Value,
1554
+ label: vID
1555
+ });
1556
+ });
1557
+ } else if (ctx.node.type === "string" && isPropertyNode(ctx.node.parent) && isViewNode(ctx.node.parent.parent) && ctx.node.parent.keyNode.value === "id") {
1558
+ Array.from(viewInfo?.nodes.keys() ?? []).forEach((vID) => {
1559
+ completionCtx.addCompletionItem({
1560
+ kind: CompletionItemKind4.Value,
1561
+ label: vID
1562
+ });
1563
+ });
1564
+ }
1565
+ });
1566
+ service.hooks.definition.tap(this.name, (ctx) => {
1567
+ if (!isValueCompletion(ctx.node)) {
1568
+ return;
1569
+ }
1570
+ if (ctx.node.type === "string" && isPropertyNode(ctx.node.parent)) {
1571
+ if (isViewNode(ctx.node.parent.parent) && ctx.node.parent.keyNode.value === "id") {
1572
+ const { value } = ctx.node;
1573
+ const stateNode = viewInfo?.nodes.get(value);
1574
+ if (stateNode) {
1575
+ return getLSLocationOfNode(ctx.document, stateNode.refProp);
1576
+ }
1577
+ } else if (isStateNode(ctx.node.parent.parent) && ctx.node.parent.keyNode.value === "ref") {
1578
+ const { value } = ctx.node;
1579
+ const viewNode = viewInfo?.views.get(value);
1580
+ if (viewNode) {
1581
+ return getLSLocationOfNode(ctx.document, viewNode.idProp);
1582
+ }
1583
+ }
1584
+ }
1585
+ });
1586
+ }
1587
+ };
1588
+
1589
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-service/src/xlr/transforms.ts
1590
+ import { simpleTransformGenerator } from "@xlr-lib/xlr-sdk";
1591
+ import { isPrimitiveTypeNode } from "@xlr-lib/xlr-utils";
1592
+ var applyCommonProps = (node, capability) => {
1593
+ return simpleTransformGenerator("object", ["Assets", "Views"], (xlrNode) => {
1594
+ if (!xlrNode.properties.applicability) {
1595
+ xlrNode.properties.applicability = {
1596
+ required: false,
1597
+ node: {
1598
+ type: "or",
1599
+ name: "Applicability",
1600
+ description: "Evaluate the given expression (or boolean) and if falsy, remove this node from the tree. This is re-computed for each change in the data-model",
1601
+ or: [
1602
+ {
1603
+ type: "boolean"
1604
+ },
1605
+ {
1606
+ type: "ref",
1607
+ ref: "Expression"
1608
+ }
1609
+ ]
1610
+ }
1611
+ };
1612
+ }
1613
+ if (!xlrNode.properties._comment) {
1614
+ xlrNode.properties._comment = {
1615
+ required: false,
1616
+ node: {
1617
+ description: "Adds a comment for the given node",
1618
+ type: "string"
1619
+ }
1620
+ };
1621
+ }
1622
+ return xlrNode;
1623
+ })(node, capability);
1624
+ };
1625
+ var applyAssetWrapperOrSwitch = (node, capability) => {
1626
+ return simpleTransformGenerator("ref", ["Assets", "Views"], (xlrNode) => {
1627
+ if (xlrNode.ref.includes("AssetWrapper")) {
1628
+ return {
1629
+ ...xlrNode,
1630
+ ref: xlrNode.ref.replace("AssetWrapper", "AssetWrapperOrSwitch")
1631
+ };
1632
+ }
1633
+ return xlrNode;
1634
+ })(node, capability);
1635
+ };
1636
+ var applyValueRefs = (node, capability) => {
1637
+ return simpleTransformGenerator(
1638
+ "object",
1639
+ ["Assets", "Views"],
1640
+ (inputNode) => {
1641
+ const xlrNode = { ...inputNode };
1642
+ for (const key in xlrNode.properties) {
1643
+ if (key === "id") {
1644
+ continue;
1645
+ }
1646
+ const value = xlrNode.properties[key];
1647
+ if (value.node.type === "or") {
1648
+ value.node.or.push({
1649
+ type: "ref",
1650
+ ref: "ExpressionRef"
1651
+ });
1652
+ value.node.or.push({
1653
+ type: "ref",
1654
+ ref: "BindingRef"
1655
+ });
1656
+ } else if (isPrimitiveTypeNode(value.node)) {
1657
+ const newUnionType = {
1658
+ type: "or",
1659
+ description: value.node.description,
1660
+ or: [
1661
+ value.node,
1662
+ {
1663
+ type: "ref",
1664
+ ref: "ExpressionRef"
1665
+ },
1666
+ {
1667
+ type: "ref",
1668
+ ref: "BindingRef"
1669
+ }
1670
+ ]
1671
+ };
1672
+ value.node = newUnionType;
1673
+ }
1674
+ }
1675
+ return xlrNode;
1676
+ }
1677
+ )(node, capability);
1678
+ };
1679
+ var applyTemplateProperty = (node, capability) => {
1680
+ return simpleTransformGenerator(
1681
+ "object",
1682
+ ["Assets", "Views"],
1683
+ (inputNode) => {
1684
+ const templateTypes = [];
1685
+ const xlrNode = { ...inputNode };
1686
+ for (const key in xlrNode.properties) {
1687
+ const value = xlrNode.properties[key];
1688
+ if (value.node.type === "array") {
1689
+ value.required = false;
1690
+ templateTypes.push({
1691
+ type: "ref",
1692
+ ref: `Template<${value.node.elementType.type === "ref" ? value.node.elementType.ref : value.node.elementType.name}, "${key}">`,
1693
+ genericArguments: [
1694
+ value.node.elementType,
1695
+ {
1696
+ type: "string",
1697
+ const: key
1698
+ }
1699
+ ]
1700
+ });
1701
+ }
1702
+ }
1703
+ if (templateTypes.length > 0) {
1704
+ const templateType = {
1705
+ type: "array",
1706
+ elementType: templateTypes.length > 1 ? { type: "or", or: templateTypes } : templateTypes[0],
1707
+ description: "A list of templates to process for this node"
1708
+ };
1709
+ xlrNode.properties.template = {
1710
+ required: false,
1711
+ node: templateType
1712
+ };
1713
+ }
1714
+ return xlrNode;
1715
+ }
1716
+ )(node, capability);
1717
+ };
1718
+
1719
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-service/src/constants.ts
1720
+ var PLUGINS = [
1721
+ new DuplicateIDPlugin(),
1722
+ new ViewNodePlugin(),
1723
+ new SchemaInfoPlugin(),
1724
+ new AssetWrapperArrayPlugin(),
1725
+ new NavStatePlugin(),
1726
+ new MissingAssetWrapperPlugin(),
1727
+ new XLRPlugin()
1728
+ ];
1729
+ var DEFAULT_FILTERS = {
1730
+ typeFilter: "Transformed"
1731
+ };
1732
+ var TRANSFORM_FUNCTIONS = [
1733
+ applyAssetWrapperOrSwitch,
1734
+ applyValueRefs,
1735
+ applyCommonProps,
1736
+ applyTemplateProperty
1737
+ ];
1738
+
1739
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-service/src/xlr/registry.ts
1740
+ import { BasicXLRRegistry } from "@xlr-lib/xlr-sdk";
1741
+ var PlayerXLRRegistry = class extends BasicXLRRegistry {
1742
+ /** Keeps the mapping of how a type is referenced by Player to the underlying XLR */
1743
+ registrationMap;
1744
+ constructor() {
1745
+ super();
1746
+ this.registrationMap = /* @__PURE__ */ new Map();
1747
+ }
1748
+ get(id) {
1749
+ const realNames = this.registrationMap.get(id);
1750
+ if (realNames === void 0) {
1751
+ return void 0;
1752
+ }
1753
+ if (Array.isArray(realNames)) {
1754
+ return {
1755
+ name: `${id}PartialMatchType`,
1756
+ source: "registry.ts",
1757
+ type: "or",
1758
+ or: realNames.map(
1759
+ (partialMatchID) => super.get(partialMatchID)
1760
+ )
1761
+ };
1762
+ }
1763
+ return super.get(realNames);
1764
+ }
1765
+ add(type, plugin, capability) {
1766
+ let registeredName = type.name;
1767
+ if ((capability === "Assets" || capability === "Views") && type.type === "object" && type.extends?.genericArguments?.[0]?.type === "string" && type.extends?.genericArguments?.[0]?.const) {
1768
+ this.registrationMap.set(registeredName, type.name);
1769
+ registeredName = type.extends.genericArguments[0].const;
1770
+ }
1771
+ if (this.registrationMap.has(registeredName)) {
1772
+ const current = this.registrationMap.get(registeredName);
1773
+ if (Array.isArray(current)) {
1774
+ current.push(registeredName);
1775
+ } else {
1776
+ this.registrationMap.set(registeredName, [current, type.name]);
1777
+ }
1778
+ } else {
1779
+ this.registrationMap.set(registeredName, type.name);
1780
+ }
1781
+ super.add(type, plugin, capability);
1782
+ }
1783
+ has(id) {
1784
+ return this.registrationMap.has(id);
1785
+ }
1786
+ list(filterArgs) {
1787
+ return super.list(filterArgs);
1788
+ }
1789
+ info(id) {
1790
+ const realNames = this.registrationMap.get(id);
1791
+ if (realNames === void 0) {
1792
+ return void 0;
1793
+ }
1794
+ if (Array.isArray(realNames)) {
1795
+ const metaDataArrays = realNames.map((name) => super.info(name));
1796
+ const firstElement = metaDataArrays[0];
1797
+ const equal = metaDataArrays.every(
1798
+ (metaData) => metaData?.plugin === firstElement?.plugin && metaData?.capability === firstElement?.capability
1799
+ );
1800
+ if (equal) {
1801
+ return firstElement;
1802
+ }
1803
+ throw Error(
1804
+ `Error: can't determine accurate info for type ${id} as it is provided by multiple plugins/capabilities`
1805
+ );
1806
+ }
1807
+ return super.info(realNames);
1808
+ }
1809
+ };
1810
+
1811
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-service/src/xlr/service.ts
1812
+ import { XLRSDK } from "@xlr-lib/xlr-sdk";
1813
+ var XLRService = class {
1814
+ baseTypes = [
1815
+ "asset",
1816
+ "view",
1817
+ "flow",
1818
+ "content",
1819
+ "navigation",
1820
+ "state"
1821
+ ];
1822
+ XLRSDK;
1823
+ constructor() {
1824
+ this.XLRSDK = new XLRSDK(new PlayerXLRRegistry());
1825
+ }
1826
+ walker(n, path) {
1827
+ if (this.baseTypes.indexOf(n.type) > -1) {
1828
+ if (n.type === "asset") {
1829
+ const name = this.XLRSDK.hasType(n.assetType?.valueNode?.value ?? "") ? n.assetType?.valueNode?.value : "Asset";
1830
+ return {
1831
+ name,
1832
+ path
1833
+ };
1834
+ }
1835
+ if (n.type === "view") {
1836
+ const name = this.XLRSDK.hasType(n.viewType?.valueNode?.value ?? "") ? n.viewType?.valueNode?.value : "View";
1837
+ return { name, path };
1838
+ }
1839
+ if (n.type === "state") {
1840
+ if (n.stateType?.valueNode?.value) {
1841
+ const flowStateType = mapFlowStateToType(
1842
+ n.stateType?.valueNode?.value
1843
+ );
1844
+ if (flowStateType) {
1845
+ return { name: flowStateType, path };
1846
+ }
1847
+ }
1848
+ }
1849
+ if (n.type === "content") {
1850
+ return { name: "Flow", path };
1851
+ }
1852
+ if (n.type === "flow") {
1853
+ return { name: "NavigationFlow", path };
1854
+ }
1855
+ if (n.type === "navigation") {
1856
+ return { name: "Navigation", path };
1857
+ }
1858
+ }
1859
+ if (n.parent) {
1860
+ path.push(n.parent);
1861
+ return this.walker(n.parent, path);
1862
+ }
1863
+ return void 0;
1864
+ }
1865
+ getTypeInfoAtPosition(node) {
1866
+ if (!node) return;
1867
+ const pointer = node;
1868
+ const xlrInfo = this.walker(pointer, []);
1869
+ if (!xlrInfo) return;
1870
+ const activeNode = this.XLRSDK.getType(xlrInfo.name);
1871
+ if (!activeNode) return;
1872
+ let nearestObjectTypes = [activeNode];
1873
+ let pointers = [];
1874
+ if (activeNode.type === "and") {
1875
+ pointers = activeNode.and;
1876
+ } else if (activeNode.type === "or") {
1877
+ pointers = activeNode.or;
1878
+ } else {
1879
+ pointers = [activeNode];
1880
+ }
1881
+ for (const pathSegment of xlrInfo.path.reverse()) {
1882
+ const newPointers = [];
1883
+ for (let nodePointer of pointers) {
1884
+ let newNode;
1885
+ if (nodePointer.type === "ref") {
1886
+ if (this.XLRSDK.hasType(nodePointer.ref)) {
1887
+ nodePointer = this.XLRSDK.getType(nodePointer.ref);
1888
+ } else {
1889
+ continue;
1890
+ }
1891
+ }
1892
+ if (pathSegment.type === "property" && nodePointer.type === "object") {
1893
+ if (nodePointer?.properties[pathSegment.keyNode.value]) {
1894
+ newNode = nodePointer?.properties[pathSegment.keyNode.value]?.node;
1895
+ } else if (nodePointer?.additionalProperties) {
1896
+ const adNode = nodePointer?.additionalProperties;
1897
+ if (typeof adNode !== "boolean") {
1898
+ newNode = adNode;
1899
+ }
1900
+ }
1901
+ } else if (pathSegment.type === "object" || this.baseTypes.indexOf(pathSegment.type) !== -1) {
1902
+ newNode = nodePointer;
1903
+ } else if (pathSegment.type === "array") {
1904
+ newNode = nodePointer.elementType;
1905
+ }
1906
+ if (!newNode) {
1907
+ continue;
1908
+ } else if (newNode.type === "or") {
1909
+ newPointers.push(...newNode.or);
1910
+ } else if (newNode.type === "and") {
1911
+ newPointers.push(...newNode.and);
1912
+ } else if (newNode.type === "ref" && this.XLRSDK.hasType(newNode.ref)) {
1913
+ newPointers.push(this.XLRSDK.getType(newNode.ref));
1914
+ } else {
1915
+ newPointers.push(newNode);
1916
+ }
1917
+ }
1918
+ if (newPointers.filter((n) => n).length === 0) {
1919
+ break;
1920
+ }
1921
+ const newObjectTypes = newPointers.filter(
1922
+ (n) => n.type === "object"
1923
+ );
1924
+ if (newObjectTypes.length > 0) {
1925
+ nearestObjectTypes = newObjectTypes;
1926
+ }
1927
+ pointers = newPointers;
1928
+ }
1929
+ return {
1930
+ name: xlrInfo.name,
1931
+ nodes: pointers,
1932
+ nearestObjects: nearestObjectTypes
1933
+ };
1934
+ }
1935
+ };
1936
+
1937
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-service/src/types.ts
1938
+ var LOG_TYPES = ["debug", "info", "warn", "error"];
1939
+
1940
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/lsp/json-language-service/src/index.ts
1941
+ var PlayerLanguageService = class {
1942
+ XLRService;
1943
+ parseCache = /* @__PURE__ */ new Map();
1944
+ fixableViolationsForDocument = /* @__PURE__ */ new Map();
1945
+ hooks = {
1946
+ onDocumentUpdate: new SyncHook(),
1947
+ validate: new AsyncParallelHook(),
1948
+ onValidateEnd: new SyncWaterfallHook(),
1949
+ complete: new AsyncParallelHook(),
1950
+ hover: new SyncBailHook(),
1951
+ definition: new SyncBailHook()
1952
+ };
1953
+ constructor(config) {
1954
+ this.XLRService = new XLRService();
1955
+ PLUGINS.forEach((p) => p.apply(this));
1956
+ config?.plugins?.forEach((p) => p.apply(this));
1957
+ }
1958
+ parseTextDocument(document) {
1959
+ if (!this.parseCache.has(document.uri)) {
1960
+ const parsed = parse(document);
1961
+ this.parseCache.set(document.uri, { version: document.version, parsed });
1962
+ return parsed;
1963
+ }
1964
+ const cached = this.parseCache.get(document.uri);
1965
+ if (!cached || cached.version < document.version) {
1966
+ this.parseCache.delete(document.uri);
1967
+ return this.parseTextDocument(document);
1968
+ }
1969
+ return cached.parsed;
1970
+ }
1971
+ async updateSource(document) {
1972
+ const parsed = this.parseTextDocument(document);
1973
+ const documentContext = {
1974
+ log: {
1975
+ debug: console.log,
1976
+ info: console.log,
1977
+ warn: console.warn,
1978
+ error: console.error
1979
+ },
1980
+ document,
1981
+ PlayerContent: parsed
1982
+ };
1983
+ const ctx = {
1984
+ ...documentContext
1985
+ };
1986
+ this.hooks.onDocumentUpdate.call(ctx);
1987
+ return ctx;
1988
+ }
1989
+ async getJSONPositionInfo(ctx, position) {
1990
+ const { document, PlayerContent: PlayerContent2 } = ctx;
1991
+ const node = PlayerContent2.getNodeFromOffset(document.offsetAt(position));
1992
+ return {
1993
+ node
1994
+ };
1995
+ }
1996
+ async updateSourceWithPosition(document, position) {
1997
+ const ctx = await this.updateSource(document);
1998
+ const { node } = await this.getJSONPositionInfo(ctx, position);
1999
+ const XLRInfo = this.XLRService.getTypeInfoAtPosition(node);
2000
+ if (!node || !XLRInfo) {
2001
+ return void 0;
2002
+ }
2003
+ return {
2004
+ ...ctx,
2005
+ node,
2006
+ position,
2007
+ XLR: XLRInfo
2008
+ };
2009
+ }
2010
+ onClose(document) {
2011
+ this.fixableViolationsForDocument.delete(document.uri);
2012
+ this.parseCache.delete(document.uri);
2013
+ }
2014
+ async formatTextDocument(document, options, range) {
2015
+ const formattingOptions = {
2016
+ tabSize: options.tabSize,
2017
+ insertSpaces: options.insertSpaces
2018
+ };
2019
+ let formatRange;
2020
+ if (range) {
2021
+ const startOffset = document.offsetAt(range.start);
2022
+ formatRange = {
2023
+ offset: startOffset,
2024
+ length: document.offsetAt(range.end) - startOffset
2025
+ };
2026
+ }
2027
+ return formatJSON(document.getText(), formatRange, formattingOptions).map(
2028
+ (edit) => {
2029
+ return TextEdit2.replace(
2030
+ Range4.create(
2031
+ document.positionAt(edit.offset),
2032
+ document.positionAt(edit.offset + edit.length)
2033
+ ),
2034
+ edit.content
2035
+ );
2036
+ }
2037
+ );
2038
+ }
2039
+ async validateTextDocument(document) {
2040
+ const ctx = await this.updateSource(document);
2041
+ this.fixableViolationsForDocument.delete(document.uri);
2042
+ if (!isKnownRootType(ctx.PlayerContent)) {
2043
+ return;
2044
+ }
2045
+ const diagnostics = [...ctx.PlayerContent.syntaxErrors];
2046
+ const astVisitors = [];
2047
+ const addFixableViolation = (diagnostic, violation) => {
2048
+ if (!this.fixableViolationsForDocument.has(document.uri)) {
2049
+ this.fixableViolationsForDocument.set(document.uri, /* @__PURE__ */ new Map());
2050
+ }
2051
+ const fixableDiags = this.fixableViolationsForDocument.get(document.uri);
2052
+ fixableDiags?.set(diagnostic, violation);
2053
+ };
2054
+ if (ctx.PlayerContent.root) {
2055
+ const validationContext = {
2056
+ addViolation: (violation) => {
2057
+ const { message, node, severity, fix } = violation;
2058
+ const range = toRange(document, node);
2059
+ const diagnostic = {
2060
+ message,
2061
+ severity,
2062
+ range
2063
+ };
2064
+ if (fix) {
2065
+ addFixableViolation(diagnostic, violation);
2066
+ }
2067
+ diagnostics.push(diagnostic);
2068
+ },
2069
+ useASTVisitor: (visitor) => {
2070
+ astVisitors.push(visitor);
2071
+ },
2072
+ addDiagnostic(d) {
2073
+ diagnostics.push(d);
2074
+ }
2075
+ };
2076
+ await this.hooks.validate.call(ctx, validationContext);
2077
+ await walk(ctx.PlayerContent.root, async (node) => {
2078
+ const visitorProp = typeToVisitorMap[node.type];
2079
+ astVisitors.forEach(async (visitor) => {
2080
+ try {
2081
+ await visitor[visitorProp]?.(node);
2082
+ } catch (e) {
2083
+ ctx.log?.error(
2084
+ `Error running rules for ${visitorProp}: ${e.message}, Stack ${e.stack}`
2085
+ );
2086
+ }
2087
+ });
2088
+ return false;
2089
+ });
2090
+ }
2091
+ return this.hooks.onValidateEnd.call(diagnostics, {
2092
+ documentContext: ctx,
2093
+ addFixableViolation
2094
+ });
2095
+ }
2096
+ async getCompletionsAtPosition(document, position) {
2097
+ const ctxWithPos = await this.updateSourceWithPosition(document, position);
2098
+ if (!ctxWithPos) {
2099
+ return CompletionList.create();
2100
+ }
2101
+ const completionItems = [];
2102
+ const completionContext = {
2103
+ addCompletionItem: (i) => {
2104
+ completionItems.push(i);
2105
+ }
2106
+ };
2107
+ await this.hooks.complete.call(ctxWithPos, completionContext);
2108
+ return CompletionList.create(completionItems);
2109
+ }
2110
+ async resolveCompletionItem(completionItem) {
2111
+ return completionItem;
2112
+ }
2113
+ async getHoverInfoAtPosition(document, position) {
2114
+ const context = await this.updateSourceWithPosition(document, position);
2115
+ if (!context) {
2116
+ return void 0;
2117
+ }
2118
+ return this.hooks.hover.call(context);
2119
+ }
2120
+ async getCodeActionsInRange(document, context) {
2121
+ const diagsForDocument = this.fixableViolationsForDocument.get(
2122
+ document.uri
2123
+ );
2124
+ if (!diagsForDocument || diagsForDocument.size === 0 || context.diagnostics.length === 0) {
2125
+ return [];
2126
+ }
2127
+ const actions = [];
2128
+ diagsForDocument.forEach((violation, diagnostic) => {
2129
+ const matching = context.diagnostics.find(
2130
+ (diag) => containsRange(diagnostic.range, diag.range)
2131
+ );
2132
+ const fixedAction = violation.fix?.();
2133
+ if (!matching || !fixedAction) {
2134
+ return;
2135
+ }
2136
+ actions.push({
2137
+ title: fixedAction.name,
2138
+ kind: CodeActionKind.QuickFix,
2139
+ edit: {
2140
+ changes: {
2141
+ [document.uri]: [toTextEdit(document, fixedAction.edit)]
2142
+ }
2143
+ }
2144
+ });
2145
+ });
2146
+ return actions;
2147
+ }
2148
+ async getDefinitionAtPosition(document, position) {
2149
+ const context = await this.updateSourceWithPosition(document, position);
2150
+ if (!context) {
2151
+ return void 0;
2152
+ }
2153
+ return this.hooks.definition.call(context);
2154
+ }
2155
+ addXLRTransforms(transforms) {
2156
+ Object.entries(transforms).forEach(
2157
+ ([name, fn]) => this.XLRService.XLRSDK.addTransformFunction(name, fn)
2158
+ );
2159
+ }
2160
+ addLSPPlugin(plugin) {
2161
+ plugin.apply(this);
2162
+ }
2163
+ async setAssetTypes(typeFiles) {
2164
+ typeFiles.forEach((file) => {
2165
+ if (file.includes("types")) {
2166
+ this.XLRService.XLRSDK.loadDefinitionsFromDisk(file, {});
2167
+ } else {
2168
+ this.XLRService.XLRSDK.loadDefinitionsFromDisk(
2169
+ file,
2170
+ DEFAULT_FILTERS,
2171
+ TRANSFORM_FUNCTIONS
2172
+ );
2173
+ }
2174
+ });
2175
+ }
2176
+ async setAssetTypesFromModule(manifest) {
2177
+ await Promise.allSettled(
2178
+ manifest.map((m) => {
2179
+ if (m.capabilities["Types"]?.length) {
2180
+ return this.XLRService.XLRSDK.loadDefinitionsFromModule(m);
2181
+ } else {
2182
+ return this.XLRService.XLRSDK.loadDefinitionsFromModule(
2183
+ m,
2184
+ DEFAULT_FILTERS,
2185
+ TRANSFORM_FUNCTIONS
2186
+ );
2187
+ }
2188
+ })
2189
+ );
2190
+ }
2191
+ };
2192
+ export {
2193
+ ASTNodeImpl,
2194
+ ArrayASTNodeImpl,
2195
+ AssetASTNodeImpl,
2196
+ BooleanASTNodeImpl,
2197
+ ContentASTNodeImpl,
2198
+ DEFAULT_FILTERS,
2199
+ FlowASTNodeImpl,
2200
+ FlowStateASTNodeImpl,
2201
+ LOG_TYPES,
2202
+ NavigationASTNodeImpl,
2203
+ NullASTNodeImpl,
2204
+ NumberASTNodeImpl,
2205
+ ObjType,
2206
+ ObjectASTNodeImpl,
2207
+ PLUGINS,
2208
+ PlayerContent,
2209
+ PlayerLanguageService,
2210
+ PlayerXLRRegistry,
2211
+ PropertyASTNodeImpl,
2212
+ StringASTNodeImpl,
2213
+ TRANSFORM_FUNCTIONS,
2214
+ ViewASTNodeImpl,
2215
+ XLRService,
2216
+ applyAssetWrapperOrSwitch,
2217
+ applyCommonProps,
2218
+ applyTemplateProperty,
2219
+ applyValueRefs,
2220
+ containsRange,
2221
+ formatLikeNode,
2222
+ getContentNode,
2223
+ getLSLocationOfNode,
2224
+ getNodeValue,
2225
+ getPropForValNode,
2226
+ getProperty,
2227
+ getValForKey,
2228
+ getViewNode,
2229
+ isFlowNode,
2230
+ isKeyNode,
2231
+ isKnownRootType,
2232
+ isNavigationNode,
2233
+ isObjectNode,
2234
+ isPropertyCompletion,
2235
+ isPropertyNode,
2236
+ isStateNode,
2237
+ isValueCompletion,
2238
+ isValueNode,
2239
+ isViewNode,
2240
+ mapFlowStateToType,
2241
+ parse,
2242
+ replaceString,
2243
+ toRange,
2244
+ toTextDocument,
2245
+ toTextEdit,
2246
+ typeToVisitorMap,
2247
+ walk
2248
+ };
2249
+ //# sourceMappingURL=index.mjs.map