@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.
- package/dist/cjs/index.cjs +86 -43
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +86 -43
- package/dist/index.mjs +86 -43
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/__snapshots__/service.test.ts.snap +14 -0
- package/src/plugins/__tests__/asset-wrapper-array-plugin.test.ts +15 -0
- package/src/plugins/__tests__/duplicate-id-plugin.test.ts +89 -0
- package/src/plugins/__tests__/missing-asset-wrapper-plugin.test.ts +16 -1
- package/src/plugins/duplicate-id-plugin.ts +41 -1
- package/src/plugins/xlr-plugin.ts +32 -9
- package/src/xlr/__tests__/__snapshots__/transform.test.ts.snap +17 -3
- package/src/xlr/transforms.ts +40 -36
package/dist/index.legacy-esm.js
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)
|
|
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:
|
|
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)
|
|
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:
|
|
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(
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
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
|
-
|
|
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)
|
|
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:
|
|
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)
|
|
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:
|
|
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(
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
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
|
-
|
|
1634
|
-
})(node, capability);
|
|
1677
|
+
)(node, capability);
|
|
1635
1678
|
};
|
|
1636
1679
|
var applyTemplateProperty = (node, capability) => {
|
|
1637
1680
|
return simpleTransformGenerator(
|