@player-tools/json-language-service 0.4.2--canary.69.1573 → 0.4.2-next.1
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/index.cjs.js +40 -41
- package/dist/index.d.ts +4 -2
- package/dist/index.esm.js +40 -41
- package/package.json +4 -4
- package/src/index.ts +11 -0
- package/src/xlr/transforms.ts +73 -76
package/dist/index.cjs.js
CHANGED
|
@@ -1863,48 +1863,41 @@ var __spreadValues$1 = (a, b) => {
|
|
|
1863
1863
|
return a;
|
|
1864
1864
|
};
|
|
1865
1865
|
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
1866
|
-
const applyCommonProps = (
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
}
|
|
1887
|
-
};
|
|
1888
|
-
}
|
|
1866
|
+
const applyCommonProps = (node, capability) => {
|
|
1867
|
+
return xlrSdk.simpleTransformGenerator("object", ["Assets", "Views"], (xlrNode) => {
|
|
1868
|
+
if (!xlrNode.properties.applicability) {
|
|
1869
|
+
xlrNode.properties.applicability = {
|
|
1870
|
+
required: false,
|
|
1871
|
+
node: {
|
|
1872
|
+
type: "or",
|
|
1873
|
+
name: "Applicability",
|
|
1874
|
+
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",
|
|
1875
|
+
or: [
|
|
1876
|
+
{
|
|
1877
|
+
type: "boolean"
|
|
1878
|
+
},
|
|
1879
|
+
{
|
|
1880
|
+
type: "ref",
|
|
1881
|
+
ref: "Expression"
|
|
1882
|
+
}
|
|
1883
|
+
]
|
|
1884
|
+
}
|
|
1885
|
+
};
|
|
1889
1886
|
}
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
}
|
|
1898
|
-
}
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
} else if (outputNode.type === "or") {
|
|
1902
|
-
outputNode.or.map((n) => applyCommonProps(n, capability));
|
|
1903
|
-
}
|
|
1904
|
-
return outputNode;
|
|
1887
|
+
if (!xlrNode.properties._comment) {
|
|
1888
|
+
xlrNode.properties._comment = {
|
|
1889
|
+
required: false,
|
|
1890
|
+
node: {
|
|
1891
|
+
description: "Adds a comment for the given node",
|
|
1892
|
+
type: "string"
|
|
1893
|
+
}
|
|
1894
|
+
};
|
|
1895
|
+
}
|
|
1896
|
+
return xlrNode;
|
|
1897
|
+
})(node, capability);
|
|
1905
1898
|
};
|
|
1906
1899
|
const applyAssetWrapperOrSwitch = (node, capability) => {
|
|
1907
|
-
return xlrSdk.simpleTransformGenerator("ref", "Assets", (xlrNode) => {
|
|
1900
|
+
return xlrSdk.simpleTransformGenerator("ref", ["Assets", "Views"], (xlrNode) => {
|
|
1908
1901
|
if (xlrNode.ref.includes("AssetWrapper")) {
|
|
1909
1902
|
return __spreadProps$1(__spreadValues$1({}, xlrNode), {
|
|
1910
1903
|
ref: xlrNode.ref.replace("AssetWrapper", "AssetWrapperOrSwitch")
|
|
@@ -1953,8 +1946,8 @@ const applyValueRefs = (node, capability) => {
|
|
|
1953
1946
|
})(node, capability);
|
|
1954
1947
|
};
|
|
1955
1948
|
const applyTemplateProperty = (node, capability) => {
|
|
1956
|
-
|
|
1957
|
-
|
|
1949
|
+
return xlrSdk.simpleTransformGenerator("object", ["Assets", "Views"], (inputNode) => {
|
|
1950
|
+
const templateTypes = [];
|
|
1958
1951
|
const xlrNode = __spreadValues$1({}, inputNode);
|
|
1959
1952
|
for (const key in xlrNode.properties) {
|
|
1960
1953
|
const value = xlrNode.properties[key];
|
|
@@ -2449,6 +2442,12 @@ class PlayerLanguageService {
|
|
|
2449
2442
|
return this.hooks.definition.call(context);
|
|
2450
2443
|
});
|
|
2451
2444
|
}
|
|
2445
|
+
addXLRTransforms(transforms) {
|
|
2446
|
+
Object.entries(transforms).forEach(([name, fn]) => this.XLRService.XLRSDK.addTransformFunction(name, fn));
|
|
2447
|
+
}
|
|
2448
|
+
addLSPPlugin(plugin) {
|
|
2449
|
+
plugin.apply(this);
|
|
2450
|
+
}
|
|
2452
2451
|
setAssetTypes(typeFiles) {
|
|
2453
2452
|
return __async(this, null, function* () {
|
|
2454
2453
|
typeFiles.forEach((file) => {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
2
2
|
import { SyncHook, AsyncParallelHook, SyncWaterfallHook, SyncBailHook } from 'tapable-ts';
|
|
3
3
|
import { Diagnostic, Range, TextEdit, Position, DiagnosticSeverity, CompletionItem, Location, Hover, FormattingOptions, CompletionList, CodeActionContext, CodeAction } from 'vscode-languageserver-types';
|
|
4
|
-
import { Node } from 'jsonc-parser';
|
|
5
|
-
import { BasicXLRRegistry, Filters, TypeMetadata, XLRSDK } from '@player-tools/xlr-sdk';
|
|
6
4
|
import * as _player_tools_xlr from '@player-tools/xlr';
|
|
7
5
|
import { NamedType, NodeType, ObjectType, TransformFunction } from '@player-tools/xlr';
|
|
6
|
+
import { Node } from 'jsonc-parser';
|
|
7
|
+
import { BasicXLRRegistry, Filters, TypeMetadata, XLRSDK } from '@player-tools/xlr-sdk';
|
|
8
8
|
|
|
9
9
|
declare type ASTNode = StringASTNode | NumberASTNode | BooleanASTNode | ArrayASTNode | NullASTNode | PropertyASTNode | ObjectASTNode | AssetASTNode | ViewASTNode | ContentASTNode | NavigationASTNode | FlowASTNode | EmptyASTNode | FlowStateASTNode;
|
|
10
10
|
interface BaseASTNode<T extends string> {
|
|
@@ -443,6 +443,8 @@ declare class PlayerLanguageService {
|
|
|
443
443
|
getHoverInfoAtPosition(document: TextDocument, position: Position): Promise<Hover | undefined | null>;
|
|
444
444
|
getCodeActionsInRange(document: TextDocument, context: CodeActionContext): Promise<CodeAction[]>;
|
|
445
445
|
getDefinitionAtPosition(document: TextDocument, position: Position): Promise<Location | undefined | null>;
|
|
446
|
+
addXLRTransforms(transforms: Record<string, TransformFunction>): void;
|
|
447
|
+
addLSPPlugin(plugin: PlayerLanguageServicePlugin): void;
|
|
446
448
|
setAssetTypes(typeFiles: Array<string>): Promise<void>;
|
|
447
449
|
}
|
|
448
450
|
|
package/dist/index.esm.js
CHANGED
|
@@ -1855,48 +1855,41 @@ var __spreadValues$1 = (a, b) => {
|
|
|
1855
1855
|
return a;
|
|
1856
1856
|
};
|
|
1857
1857
|
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
1858
|
-
const applyCommonProps = (
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
}
|
|
1879
|
-
};
|
|
1880
|
-
}
|
|
1858
|
+
const applyCommonProps = (node, capability) => {
|
|
1859
|
+
return simpleTransformGenerator("object", ["Assets", "Views"], (xlrNode) => {
|
|
1860
|
+
if (!xlrNode.properties.applicability) {
|
|
1861
|
+
xlrNode.properties.applicability = {
|
|
1862
|
+
required: false,
|
|
1863
|
+
node: {
|
|
1864
|
+
type: "or",
|
|
1865
|
+
name: "Applicability",
|
|
1866
|
+
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",
|
|
1867
|
+
or: [
|
|
1868
|
+
{
|
|
1869
|
+
type: "boolean"
|
|
1870
|
+
},
|
|
1871
|
+
{
|
|
1872
|
+
type: "ref",
|
|
1873
|
+
ref: "Expression"
|
|
1874
|
+
}
|
|
1875
|
+
]
|
|
1876
|
+
}
|
|
1877
|
+
};
|
|
1881
1878
|
}
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
}
|
|
1890
|
-
}
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
} else if (outputNode.type === "or") {
|
|
1894
|
-
outputNode.or.map((n) => applyCommonProps(n, capability));
|
|
1895
|
-
}
|
|
1896
|
-
return outputNode;
|
|
1879
|
+
if (!xlrNode.properties._comment) {
|
|
1880
|
+
xlrNode.properties._comment = {
|
|
1881
|
+
required: false,
|
|
1882
|
+
node: {
|
|
1883
|
+
description: "Adds a comment for the given node",
|
|
1884
|
+
type: "string"
|
|
1885
|
+
}
|
|
1886
|
+
};
|
|
1887
|
+
}
|
|
1888
|
+
return xlrNode;
|
|
1889
|
+
})(node, capability);
|
|
1897
1890
|
};
|
|
1898
1891
|
const applyAssetWrapperOrSwitch = (node, capability) => {
|
|
1899
|
-
return simpleTransformGenerator("ref", "Assets", (xlrNode) => {
|
|
1892
|
+
return simpleTransformGenerator("ref", ["Assets", "Views"], (xlrNode) => {
|
|
1900
1893
|
if (xlrNode.ref.includes("AssetWrapper")) {
|
|
1901
1894
|
return __spreadProps$1(__spreadValues$1({}, xlrNode), {
|
|
1902
1895
|
ref: xlrNode.ref.replace("AssetWrapper", "AssetWrapperOrSwitch")
|
|
@@ -1945,8 +1938,8 @@ const applyValueRefs = (node, capability) => {
|
|
|
1945
1938
|
})(node, capability);
|
|
1946
1939
|
};
|
|
1947
1940
|
const applyTemplateProperty = (node, capability) => {
|
|
1948
|
-
|
|
1949
|
-
|
|
1941
|
+
return simpleTransformGenerator("object", ["Assets", "Views"], (inputNode) => {
|
|
1942
|
+
const templateTypes = [];
|
|
1950
1943
|
const xlrNode = __spreadValues$1({}, inputNode);
|
|
1951
1944
|
for (const key in xlrNode.properties) {
|
|
1952
1945
|
const value = xlrNode.properties[key];
|
|
@@ -2441,6 +2434,12 @@ class PlayerLanguageService {
|
|
|
2441
2434
|
return this.hooks.definition.call(context);
|
|
2442
2435
|
});
|
|
2443
2436
|
}
|
|
2437
|
+
addXLRTransforms(transforms) {
|
|
2438
|
+
Object.entries(transforms).forEach(([name, fn]) => this.XLRService.XLRSDK.addTransformFunction(name, fn));
|
|
2439
|
+
}
|
|
2440
|
+
addLSPPlugin(plugin) {
|
|
2441
|
+
plugin.apply(this);
|
|
2442
|
+
}
|
|
2444
2443
|
setAssetTypes(typeFiles) {
|
|
2445
2444
|
return __async(this, null, function* () {
|
|
2446
2445
|
typeFiles.forEach((file) => {
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@player-tools/json-language-service",
|
|
3
|
-
"version": "0.4.2
|
|
3
|
+
"version": "0.4.2-next.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
7
7
|
},
|
|
8
8
|
"peerDependencies": {},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@player-tools/xlr": "0.4.2
|
|
11
|
-
"@player-tools/xlr-sdk": "0.4.2
|
|
12
|
-
"@player-tools/xlr-utils": "0.4.2
|
|
10
|
+
"@player-tools/xlr": "0.4.2-next.1",
|
|
11
|
+
"@player-tools/xlr-sdk": "0.4.2-next.1",
|
|
12
|
+
"@player-tools/xlr-utils": "0.4.2-next.1",
|
|
13
13
|
"change-case": "^4.1.1",
|
|
14
14
|
"cross-fetch": "^3.0.5",
|
|
15
15
|
"detect-indent": "^6.0.0",
|
package/src/index.ts
CHANGED
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
CodeActionKind,
|
|
28
28
|
} from 'vscode-languageserver-types';
|
|
29
29
|
|
|
30
|
+
import type { TransformFunction } from '@player-tools/xlr';
|
|
30
31
|
import type {
|
|
31
32
|
DocumentContext,
|
|
32
33
|
ValidationContext,
|
|
@@ -415,6 +416,16 @@ export class PlayerLanguageService {
|
|
|
415
416
|
return this.hooks.definition.call(context);
|
|
416
417
|
}
|
|
417
418
|
|
|
419
|
+
public addXLRTransforms(transforms: Record<string, TransformFunction>): void {
|
|
420
|
+
Object.entries(transforms).forEach(([name, fn]) =>
|
|
421
|
+
this.XLRService.XLRSDK.addTransformFunction(name, fn)
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
public addLSPPlugin(plugin: PlayerLanguageServicePlugin) {
|
|
426
|
+
plugin.apply(this);
|
|
427
|
+
}
|
|
428
|
+
|
|
418
429
|
async setAssetTypes(typeFiles: Array<string>) {
|
|
419
430
|
// await this.typescriptService.setAssetTypes(typeFiles);
|
|
420
431
|
typeFiles.forEach((file) => {
|
package/src/xlr/transforms.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* eslint-disable guard-for-in */
|
|
2
2
|
/* eslint-disable no-restricted-syntax */
|
|
3
|
-
|
|
3
|
+
|
|
4
4
|
import type {
|
|
5
5
|
ArrayType,
|
|
6
6
|
NamedType,
|
|
@@ -15,51 +15,44 @@ import { isPrimitiveTypeNode } from '@player-tools/xlr-utils';
|
|
|
15
15
|
/**
|
|
16
16
|
* Adds applicability and _comment properties to Assets
|
|
17
17
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
'
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
],
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
}
|
|
18
|
+
|
|
19
|
+
export const applyCommonProps: TransformFunction = (node, capability) => {
|
|
20
|
+
return simpleTransformGenerator('object', ['Assets', 'Views'], (xlrNode) => {
|
|
21
|
+
if (!xlrNode.properties.applicability) {
|
|
22
|
+
// eslint-disable-next-line no-param-reassign
|
|
23
|
+
xlrNode.properties.applicability = {
|
|
24
|
+
required: false,
|
|
25
|
+
node: {
|
|
26
|
+
type: 'or',
|
|
27
|
+
name: 'Applicability',
|
|
28
|
+
description:
|
|
29
|
+
'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',
|
|
30
|
+
or: [
|
|
31
|
+
{
|
|
32
|
+
type: 'boolean',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
type: 'ref',
|
|
36
|
+
ref: 'Expression',
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
};
|
|
45
41
|
}
|
|
46
|
-
}
|
|
47
42
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
} else if (outputNode.type === 'or') {
|
|
59
|
-
outputNode.or.map((n) => applyCommonProps(n, capability));
|
|
60
|
-
}
|
|
43
|
+
if (!xlrNode.properties._comment) {
|
|
44
|
+
// eslint-disable-next-line no-param-reassign
|
|
45
|
+
xlrNode.properties._comment = {
|
|
46
|
+
required: false,
|
|
47
|
+
node: {
|
|
48
|
+
description: 'Adds a comment for the given node',
|
|
49
|
+
type: 'string',
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
61
53
|
|
|
62
|
-
|
|
54
|
+
return xlrNode;
|
|
55
|
+
})(node, capability);
|
|
63
56
|
};
|
|
64
57
|
|
|
65
58
|
/**
|
|
@@ -69,7 +62,7 @@ export const applyAssetWrapperOrSwitch: TransformFunction = (
|
|
|
69
62
|
node,
|
|
70
63
|
capability
|
|
71
64
|
) => {
|
|
72
|
-
return simpleTransformGenerator('ref', 'Assets', (xlrNode) => {
|
|
65
|
+
return simpleTransformGenerator('ref', ['Assets', 'Views'], (xlrNode) => {
|
|
73
66
|
if (xlrNode.ref.includes('AssetWrapper')) {
|
|
74
67
|
return {
|
|
75
68
|
...xlrNode,
|
|
@@ -130,39 +123,43 @@ export const applyValueRefs: TransformFunction = (node, capability) => {
|
|
|
130
123
|
* Computes possible template keys and adds them to an Asset
|
|
131
124
|
*/
|
|
132
125
|
export const applyTemplateProperty: TransformFunction = (node, capability) => {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
126
|
+
return simpleTransformGenerator(
|
|
127
|
+
'object',
|
|
128
|
+
['Assets', 'Views'],
|
|
129
|
+
(inputNode) => {
|
|
130
|
+
const templateTypes: Array<RefType> = [];
|
|
131
|
+
const xlrNode = { ...inputNode };
|
|
132
|
+
for (const key in xlrNode.properties) {
|
|
133
|
+
const value = xlrNode.properties[key];
|
|
134
|
+
if (value.node.type === 'array') {
|
|
135
|
+
value.required = false;
|
|
136
|
+
templateTypes.push({
|
|
137
|
+
type: 'ref',
|
|
138
|
+
ref: `Template<${
|
|
139
|
+
value.node.elementType.type === 'ref'
|
|
140
|
+
? value.node.elementType.ref
|
|
141
|
+
: value.node.elementType.name
|
|
142
|
+
}, "${key}">`,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
148
145
|
}
|
|
149
|
-
}
|
|
150
146
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
147
|
+
if (templateTypes.length > 0) {
|
|
148
|
+
const templateType: ArrayType = {
|
|
149
|
+
type: 'array',
|
|
150
|
+
elementType:
|
|
151
|
+
templateTypes.length > 1
|
|
152
|
+
? { type: 'or', or: templateTypes }
|
|
153
|
+
: templateTypes[0],
|
|
154
|
+
description: 'A list of templates to process for this node',
|
|
155
|
+
};
|
|
156
|
+
xlrNode.properties.template = {
|
|
157
|
+
required: false,
|
|
158
|
+
node: templateType,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
165
161
|
|
|
166
|
-
|
|
167
|
-
|
|
162
|
+
return xlrNode;
|
|
163
|
+
}
|
|
164
|
+
)(node, capability);
|
|
168
165
|
};
|