@player-tools/json-language-service 0.9.0 → 0.9.1--canary.196.4186

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.
@@ -934,6 +934,9 @@ import {
934
934
  DiagnosticSeverity as DiagnosticSeverity3,
935
935
  MarkupKind
936
936
  } from "vscode-languageserver-types";
937
+ function isError(issue) {
938
+ return issue.severity === DiagnosticSeverity3.Error;
939
+ }
937
940
  var findErrorNode = (rootNode, nodeToFind) => {
938
941
  const children = [rootNode];
939
942
  while (children.length > 0) {
@@ -947,6 +950,9 @@ var findErrorNode = (rootNode, nodeToFind) => {
947
950
  }
948
951
  return rootNode;
949
952
  };
953
+ var translateSeverity = (severity) => {
954
+ return severity;
955
+ };
950
956
  function createValidationVisitor(ctx, sdk) {
951
957
  const nodesWithErrors = /* @__PURE__ */ new Set();
952
958
  return {
@@ -965,13 +971,15 @@ function createValidationVisitor(ctx, sdk) {
965
971
  assetNode.jsonNode
966
972
  );
967
973
  validationIssues.forEach((issue) => {
968
- if (!nodesWithErrors.has(issue.node) || issue.type === "missing") {
969
- nodesWithErrors.add(issue.node);
974
+ if (!(nodesWithErrors.has(issue.node) && isError(issue))) {
970
975
  ctx.addViolation({
971
976
  node: findErrorNode(assetNode, issue.node),
972
- message: `Asset Validation Error - ${issue.type}: ${issue.message}`,
973
- severity: DiagnosticSeverity3.Error
977
+ message: isError(issue) ? `Asset Validation Error - ${issue.type}: ${issue.message}` : issue.message,
978
+ severity: translateSeverity(issue.severity)
974
979
  });
980
+ if (isError(issue)) {
981
+ nodesWithErrors.add(issue.node);
982
+ }
975
983
  }
976
984
  });
977
985
  },
@@ -990,13 +998,15 @@ function createValidationVisitor(ctx, sdk) {
990
998
  viewNode.jsonNode
991
999
  );
992
1000
  validationIssues.forEach((issue) => {
993
- if (!nodesWithErrors.has(issue.node) || issue.type === "missing") {
994
- nodesWithErrors.add(issue.node);
1001
+ if (!(nodesWithErrors.has(issue.node) && isError(issue))) {
995
1002
  ctx.addViolation({
996
1003
  node: findErrorNode(viewNode, issue.node),
997
- message: `View Validation Error - ${issue.type}: ${issue.message}`,
998
- severity: DiagnosticSeverity3.Error
1004
+ message: isError(issue) ? `View Validation Error - ${issue.type}: ${issue.message}` : issue.message,
1005
+ severity: translateSeverity(issue.severity)
999
1006
  });
1007
+ if (isError(issue)) {
1008
+ nodesWithErrors.add(issue.node);
1009
+ }
1000
1010
  }
1001
1011
  });
1002
1012
  },
@@ -1193,6 +1203,16 @@ var XLRPlugin = class {
1193
1203
 
1194
1204
  // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/json-language-service/src/plugins/duplicate-id-plugin.ts
1195
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
+ };
1196
1216
  var generateID = (node) => {
1197
1217
  if (!node || node.type === "view") {
1198
1218
  return "";
@@ -1243,6 +1263,25 @@ var createValidationVisitor2 = (ctx) => {
1243
1263
  }
1244
1264
  const assetIDMap = viewInfo.get(view);
1245
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
+ }
1246
1285
  if (idInfo) {
1247
1286
  if (!idInfo.handled) {
1248
1287
  const origViolation = createViolation(idInfo.original);
@@ -1595,43 +1634,47 @@ var applyAssetWrapperOrSwitch = (node, capability) => {
1595
1634
  })(node, capability);
1596
1635
  };
1597
1636
  var applyValueRefs = (node, capability) => {
1598
- return simpleTransformGenerator("object", "Assets", (inputNode) => {
1599
- const xlrNode = { ...inputNode };
1600
- for (const key in xlrNode.properties) {
1601
- if (key === "id" || key === "type") {
1602
- continue;
1603
- }
1604
- const value = xlrNode.properties[key];
1605
- if (value.node.type === "or") {
1606
- value.node.or.push({
1607
- type: "ref",
1608
- ref: "ExpressionRef"
1609
- });
1610
- value.node.or.push({
1611
- type: "ref",
1612
- ref: "BindingRef"
1613
- });
1614
- } else if (isPrimitiveTypeNode(value.node)) {
1615
- const newUnionType = {
1616
- type: "or",
1617
- description: value.node.description,
1618
- or: [
1619
- value.node,
1620
- {
1621
- type: "ref",
1622
- ref: "ExpressionRef"
1623
- },
1624
- {
1625
- type: "ref",
1626
- ref: "BindingRef"
1627
- }
1628
- ]
1629
- };
1630
- value.node = newUnionType;
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
+ }
1631
1674
  }
1675
+ return xlrNode;
1632
1676
  }
1633
- return xlrNode;
1634
- })(node, capability);
1677
+ )(node, capability);
1635
1678
  };
1636
1679
  var applyTemplateProperty = (node, capability) => {
1637
1680
  return simpleTransformGenerator(
package/dist/index.mjs CHANGED
@@ -934,6 +934,9 @@ import {
934
934
  DiagnosticSeverity as DiagnosticSeverity3,
935
935
  MarkupKind
936
936
  } from "vscode-languageserver-types";
937
+ function isError(issue) {
938
+ return issue.severity === DiagnosticSeverity3.Error;
939
+ }
937
940
  var findErrorNode = (rootNode, nodeToFind) => {
938
941
  const children = [rootNode];
939
942
  while (children.length > 0) {
@@ -947,6 +950,9 @@ var findErrorNode = (rootNode, nodeToFind) => {
947
950
  }
948
951
  return rootNode;
949
952
  };
953
+ var translateSeverity = (severity) => {
954
+ return severity;
955
+ };
950
956
  function createValidationVisitor(ctx, sdk) {
951
957
  const nodesWithErrors = /* @__PURE__ */ new Set();
952
958
  return {
@@ -965,13 +971,15 @@ function createValidationVisitor(ctx, sdk) {
965
971
  assetNode.jsonNode
966
972
  );
967
973
  validationIssues.forEach((issue) => {
968
- if (!nodesWithErrors.has(issue.node) || issue.type === "missing") {
969
- nodesWithErrors.add(issue.node);
974
+ if (!(nodesWithErrors.has(issue.node) && isError(issue))) {
970
975
  ctx.addViolation({
971
976
  node: findErrorNode(assetNode, issue.node),
972
- message: `Asset Validation Error - ${issue.type}: ${issue.message}`,
973
- severity: DiagnosticSeverity3.Error
977
+ message: isError(issue) ? `Asset Validation Error - ${issue.type}: ${issue.message}` : issue.message,
978
+ severity: translateSeverity(issue.severity)
974
979
  });
980
+ if (isError(issue)) {
981
+ nodesWithErrors.add(issue.node);
982
+ }
975
983
  }
976
984
  });
977
985
  },
@@ -990,13 +998,15 @@ function createValidationVisitor(ctx, sdk) {
990
998
  viewNode.jsonNode
991
999
  );
992
1000
  validationIssues.forEach((issue) => {
993
- if (!nodesWithErrors.has(issue.node) || issue.type === "missing") {
994
- nodesWithErrors.add(issue.node);
1001
+ if (!(nodesWithErrors.has(issue.node) && isError(issue))) {
995
1002
  ctx.addViolation({
996
1003
  node: findErrorNode(viewNode, issue.node),
997
- message: `View Validation Error - ${issue.type}: ${issue.message}`,
998
- severity: DiagnosticSeverity3.Error
1004
+ message: isError(issue) ? `View Validation Error - ${issue.type}: ${issue.message}` : issue.message,
1005
+ severity: translateSeverity(issue.severity)
999
1006
  });
1007
+ if (isError(issue)) {
1008
+ nodesWithErrors.add(issue.node);
1009
+ }
1000
1010
  }
1001
1011
  });
1002
1012
  },
@@ -1193,6 +1203,16 @@ var XLRPlugin = class {
1193
1203
 
1194
1204
  // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/json-language-service/src/plugins/duplicate-id-plugin.ts
1195
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
+ };
1196
1216
  var generateID = (node) => {
1197
1217
  if (!node || node.type === "view") {
1198
1218
  return "";
@@ -1243,6 +1263,25 @@ var createValidationVisitor2 = (ctx) => {
1243
1263
  }
1244
1264
  const assetIDMap = viewInfo.get(view);
1245
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
+ }
1246
1285
  if (idInfo) {
1247
1286
  if (!idInfo.handled) {
1248
1287
  const origViolation = createViolation(idInfo.original);
@@ -1595,43 +1634,47 @@ var applyAssetWrapperOrSwitch = (node, capability) => {
1595
1634
  })(node, capability);
1596
1635
  };
1597
1636
  var applyValueRefs = (node, capability) => {
1598
- return simpleTransformGenerator("object", "Assets", (inputNode) => {
1599
- const xlrNode = { ...inputNode };
1600
- for (const key in xlrNode.properties) {
1601
- if (key === "id" || key === "type") {
1602
- continue;
1603
- }
1604
- const value = xlrNode.properties[key];
1605
- if (value.node.type === "or") {
1606
- value.node.or.push({
1607
- type: "ref",
1608
- ref: "ExpressionRef"
1609
- });
1610
- value.node.or.push({
1611
- type: "ref",
1612
- ref: "BindingRef"
1613
- });
1614
- } else if (isPrimitiveTypeNode(value.node)) {
1615
- const newUnionType = {
1616
- type: "or",
1617
- description: value.node.description,
1618
- or: [
1619
- value.node,
1620
- {
1621
- type: "ref",
1622
- ref: "ExpressionRef"
1623
- },
1624
- {
1625
- type: "ref",
1626
- ref: "BindingRef"
1627
- }
1628
- ]
1629
- };
1630
- value.node = newUnionType;
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
+ }
1631
1674
  }
1675
+ return xlrNode;
1632
1676
  }
1633
- return xlrNode;
1634
- })(node, capability);
1677
+ )(node, capability);
1635
1678
  };
1636
1679
  var applyTemplateProperty = (node, capability) => {
1637
1680
  return simpleTransformGenerator(