@player-tools/typescript-expression-plugin 0.4.2-next.1 → 0.5.0-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.
- package/dist/cjs/index.cjs +389 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/{index.esm.js → index.legacy-esm.js} +103 -115
- package/dist/index.mjs +358 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +25 -28
- package/src/__tests__/service.test.ts +185 -0
- package/src/index.ts +5 -5
- package/src/logger.ts +2 -2
- package/src/service.ts +18 -18
- package/src/transforms.ts +7 -7
- package/src/utils.ts +9 -9
- package/src/virtual-service-host.ts +4 -4
- package/{dist → types}/index.d.ts +3 -4
- package/types/logger.d.ts +8 -0
- package/types/service.d.ts +31 -0
- package/types/transforms.d.ts +2 -0
- package/types/utils.d.ts +14 -0
- package/types/virtual-service-host.d.ts +20 -0
- package/dist/index.cjs.js +0 -392
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import { createTSDocString } from '@player-tools/xlr-utils';
|
|
4
|
-
import { simpleTransformGenerator, XLRSDK } from '@player-tools/xlr-sdk';
|
|
5
|
-
import { parseExpression } from '@player-ui/player';
|
|
6
|
-
import { parseTree } from 'jsonc-parser';
|
|
1
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/typescript-expression-plugin/src/index.ts
|
|
2
|
+
import { decorateWithTemplateLanguageService } from "typescript-template-language-service-decorator";
|
|
7
3
|
|
|
4
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/typescript-expression-plugin/src/service.ts
|
|
5
|
+
import ts from "typescript/lib/tsserverlibrary";
|
|
6
|
+
import { createTSDocString } from "@player-tools/xlr-utils";
|
|
7
|
+
import { XLRSDK } from "@player-tools/xlr-sdk";
|
|
8
|
+
import { parseExpression } from "@player-ui/player";
|
|
9
|
+
|
|
10
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/typescript-expression-plugin/src/utils.ts
|
|
11
|
+
import { parseTree } from "jsonc-parser";
|
|
8
12
|
function isInRange(position, location) {
|
|
9
13
|
return position.character >= location.start.character && position.character <= location.end.character;
|
|
10
14
|
}
|
|
11
15
|
function getTokenAtPosition(node, position) {
|
|
12
|
-
var _a;
|
|
13
16
|
if (node.type === "CallExpression") {
|
|
14
17
|
const anyArgs = node.args.find((arg) => {
|
|
15
18
|
return getTokenAtPosition(arg, position);
|
|
@@ -23,7 +26,7 @@ function getTokenAtPosition(node, position) {
|
|
|
23
26
|
}
|
|
24
27
|
}
|
|
25
28
|
if (node.type === "Assignment") {
|
|
26
|
-
const asTarget =
|
|
29
|
+
const asTarget = getTokenAtPosition(node.left, position) ?? getTokenAtPosition(node.right, position);
|
|
27
30
|
if (asTarget) {
|
|
28
31
|
return asTarget;
|
|
29
32
|
}
|
|
@@ -33,9 +36,8 @@ function getTokenAtPosition(node, position) {
|
|
|
33
36
|
}
|
|
34
37
|
}
|
|
35
38
|
function toTSLocation(node) {
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
const end = (_b = node.location) == null ? void 0 : _b.end.character;
|
|
39
|
+
const start = node.location?.start.character;
|
|
40
|
+
const end = node.location?.end.character;
|
|
39
41
|
if (start === void 0 || end === void 0) {
|
|
40
42
|
return {
|
|
41
43
|
start: 0,
|
|
@@ -69,72 +71,41 @@ function convertExprToJSONNode(exprNode) {
|
|
|
69
71
|
return parseTree(JSON.stringify(val));
|
|
70
72
|
}
|
|
71
73
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
var
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
for (var prop in b || (b = {}))
|
|
81
|
-
if (__hasOwnProp$1.call(b, prop))
|
|
82
|
-
__defNormalProp$1(a, prop, b[prop]);
|
|
83
|
-
if (__getOwnPropSymbols$1)
|
|
84
|
-
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
85
|
-
if (__propIsEnum$1.call(b, prop))
|
|
86
|
-
__defNormalProp$1(a, prop, b[prop]);
|
|
74
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/typescript-expression-plugin/src/transforms.ts
|
|
75
|
+
import { simpleTransformGenerator } from "@player-tools/xlr-sdk";
|
|
76
|
+
var toFunction = simpleTransformGenerator(
|
|
77
|
+
"ref",
|
|
78
|
+
"Expressions",
|
|
79
|
+
(exp) => {
|
|
80
|
+
if (!exp.genericArguments || exp.ref !== "ExpressionHandler") {
|
|
81
|
+
return exp;
|
|
87
82
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
83
|
+
const [args, returnType] = exp.genericArguments;
|
|
84
|
+
const parameters = (args.type === "tuple" ? args.elementTypes : []).map((elementType, index) => {
|
|
85
|
+
return {
|
|
86
|
+
name: elementType.name ?? elementType.type.name ?? elementType.type.title ?? `arg_${index}`,
|
|
87
|
+
type: {
|
|
88
|
+
name: elementType.name ?? elementType.type.name ?? elementType.type.title ?? `arg_${index}`,
|
|
89
|
+
...elementType.type
|
|
90
|
+
},
|
|
91
|
+
optional: elementType.optional === true ? elementType.optional : void 0
|
|
92
|
+
};
|
|
93
|
+
});
|
|
98
94
|
return {
|
|
99
|
-
|
|
100
|
-
type:
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
optional: elementType.optional === true ? elementType.optional : void 0
|
|
95
|
+
...exp,
|
|
96
|
+
type: "function",
|
|
97
|
+
parameters,
|
|
98
|
+
returnType
|
|
104
99
|
};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
type: "function",
|
|
108
|
-
parameters,
|
|
109
|
-
returnType
|
|
110
|
-
});
|
|
111
|
-
});
|
|
100
|
+
}
|
|
101
|
+
);
|
|
112
102
|
|
|
113
|
-
|
|
114
|
-
var
|
|
115
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
116
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
117
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
118
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
119
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
120
|
-
var __spreadValues = (a, b) => {
|
|
121
|
-
for (var prop in b || (b = {}))
|
|
122
|
-
if (__hasOwnProp.call(b, prop))
|
|
123
|
-
__defNormalProp(a, prop, b[prop]);
|
|
124
|
-
if (__getOwnPropSymbols)
|
|
125
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
126
|
-
if (__propIsEnum.call(b, prop))
|
|
127
|
-
__defNormalProp(a, prop, b[prop]);
|
|
128
|
-
}
|
|
129
|
-
return a;
|
|
130
|
-
};
|
|
131
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
132
|
-
class ExpressionLanguageService {
|
|
103
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/typescript-expression-plugin/src/service.ts
|
|
104
|
+
var ExpressionLanguageService = class {
|
|
133
105
|
constructor(options) {
|
|
134
106
|
this._plugins = [];
|
|
135
|
-
|
|
136
|
-
this.
|
|
137
|
-
this._plugins = (_a = options == null ? void 0 : options.plugins) != null ? _a : [];
|
|
107
|
+
this.logger = options?.logger;
|
|
108
|
+
this._plugins = options?.plugins ?? [];
|
|
138
109
|
this.xlr = new XLRSDK();
|
|
139
110
|
this._plugins.forEach((p) => {
|
|
140
111
|
this.xlr.loadDefinitionsFromModule(p, void 0, [toFunction]);
|
|
@@ -150,11 +121,13 @@ class ExpressionLanguageService {
|
|
|
150
121
|
this._expressions = this.reduceExpression();
|
|
151
122
|
}
|
|
152
123
|
reduceExpression() {
|
|
153
|
-
const expressions = new Map();
|
|
124
|
+
const expressions = /* @__PURE__ */ new Map();
|
|
154
125
|
this.xlr.listTypes().forEach((type) => {
|
|
155
126
|
const typeInfo = this.xlr.getTypeInfo(type.name);
|
|
156
|
-
const source = this._plugins.find(
|
|
157
|
-
|
|
127
|
+
const source = this._plugins.find(
|
|
128
|
+
(value) => value.pluginName === typeInfo?.plugin
|
|
129
|
+
);
|
|
130
|
+
if (type.type === "function" && typeInfo?.capability === "Expressions" && source) {
|
|
158
131
|
expressions.set(type.name, {
|
|
159
132
|
name: type.name,
|
|
160
133
|
description: type.description,
|
|
@@ -166,7 +139,6 @@ class ExpressionLanguageService {
|
|
|
166
139
|
return expressions;
|
|
167
140
|
}
|
|
168
141
|
getCompletionsAtPosition(context, position) {
|
|
169
|
-
var _a, _b;
|
|
170
142
|
const completionInfo = {
|
|
171
143
|
isGlobalCompletion: false,
|
|
172
144
|
isMemberCompletion: false,
|
|
@@ -188,7 +160,7 @@ class ExpressionLanguageService {
|
|
|
188
160
|
const line = context.text.split(/\n/g)[position.line];
|
|
189
161
|
const parsed = parseExpression(line, { strict: false });
|
|
190
162
|
const token = getTokenAtPosition(parsed, position);
|
|
191
|
-
if (
|
|
163
|
+
if (token?.type === "Compound" && token.error) {
|
|
192
164
|
this._expressions.forEach((exp) => {
|
|
193
165
|
completionInfo.entries.push({
|
|
194
166
|
name: exp.name,
|
|
@@ -200,10 +172,12 @@ class ExpressionLanguageService {
|
|
|
200
172
|
});
|
|
201
173
|
return completionInfo;
|
|
202
174
|
}
|
|
203
|
-
if (
|
|
204
|
-
const start =
|
|
175
|
+
if (token?.type === "Identifier") {
|
|
176
|
+
const start = token.location?.start ?? { character: 0 };
|
|
205
177
|
const wordFromStart = line.slice(start.character, position.character);
|
|
206
|
-
const allCompletions = Array.from(this._expressions.keys()).filter(
|
|
178
|
+
const allCompletions = Array.from(this._expressions.keys()).filter(
|
|
179
|
+
(key) => key.startsWith(wordFromStart)
|
|
180
|
+
);
|
|
207
181
|
allCompletions.forEach((c) => {
|
|
208
182
|
completionInfo.entries.push({
|
|
209
183
|
name: c,
|
|
@@ -217,7 +191,6 @@ class ExpressionLanguageService {
|
|
|
217
191
|
return completionInfo;
|
|
218
192
|
}
|
|
219
193
|
getCompletionEntryDetails(context, position, name) {
|
|
220
|
-
var _a;
|
|
221
194
|
const expression = this._expressions.get(name);
|
|
222
195
|
const completionDetails = {
|
|
223
196
|
name,
|
|
@@ -226,7 +199,7 @@ class ExpressionLanguageService {
|
|
|
226
199
|
documentation: [
|
|
227
200
|
{
|
|
228
201
|
kind: "text",
|
|
229
|
-
text:
|
|
202
|
+
text: expression?.type.description ?? ""
|
|
230
203
|
}
|
|
231
204
|
],
|
|
232
205
|
displayParts: expression ? createTSDocString(expression.type) : []
|
|
@@ -236,13 +209,18 @@ class ExpressionLanguageService {
|
|
|
236
209
|
getQuickInfoAtPosition(context, position) {
|
|
237
210
|
const parsed = parseExpression(context.text, { strict: false });
|
|
238
211
|
const token = getTokenAtPosition(parsed, position);
|
|
239
|
-
if (
|
|
212
|
+
if (token?.type === "Identifier") {
|
|
240
213
|
const expression = this._expressions.get(token.name);
|
|
241
214
|
if (expression) {
|
|
242
|
-
const completionDetails = this.getCompletionEntryDetails(
|
|
243
|
-
|
|
215
|
+
const completionDetails = this.getCompletionEntryDetails(
|
|
216
|
+
context,
|
|
217
|
+
position,
|
|
218
|
+
expression.name
|
|
219
|
+
);
|
|
220
|
+
return {
|
|
221
|
+
...completionDetails,
|
|
244
222
|
textSpan: toTSLocation(token)
|
|
245
|
-
}
|
|
223
|
+
};
|
|
246
224
|
}
|
|
247
225
|
}
|
|
248
226
|
return void 0;
|
|
@@ -253,13 +231,13 @@ class ExpressionLanguageService {
|
|
|
253
231
|
if (asJsonNodeValue) {
|
|
254
232
|
const xlrDiags = this.xlr.validateByType(xlrType, asJsonNodeValue);
|
|
255
233
|
xlrDiags.forEach((d) => {
|
|
256
|
-
diagnostics.push(
|
|
257
|
-
file: context.node.getSourceFile()
|
|
258
|
-
|
|
234
|
+
diagnostics.push({
|
|
235
|
+
file: context.node.getSourceFile(),
|
|
236
|
+
...toTSLocation(node),
|
|
259
237
|
messageText: d.message,
|
|
260
238
|
category: ts.DiagnosticCategory.Error,
|
|
261
239
|
code: 1
|
|
262
|
-
})
|
|
240
|
+
});
|
|
263
241
|
});
|
|
264
242
|
}
|
|
265
243
|
return diagnostics;
|
|
@@ -289,23 +267,23 @@ class ExpressionLanguageService {
|
|
|
289
267
|
if (expectedArgs.length > actualArgs.length) {
|
|
290
268
|
const requiredArgs = expectedArgs.filter((a) => !a.optional);
|
|
291
269
|
if (actualArgs.length < requiredArgs.length) {
|
|
292
|
-
diags.push(
|
|
270
|
+
diags.push({
|
|
293
271
|
category: ts.DiagnosticCategory.Error,
|
|
294
272
|
code: 1,
|
|
295
|
-
file: context.node.getSourceFile()
|
|
296
|
-
|
|
273
|
+
file: context.node.getSourceFile(),
|
|
274
|
+
...toTSLocation(node.callTarget),
|
|
297
275
|
messageText: `Expected ${requiredArgs.length} argument(s), got ${actualArgs.length}`
|
|
298
|
-
})
|
|
276
|
+
});
|
|
299
277
|
}
|
|
300
278
|
}
|
|
301
279
|
} else {
|
|
302
|
-
diags.push(
|
|
280
|
+
diags.push({
|
|
303
281
|
category: ts.DiagnosticCategory.Error,
|
|
304
282
|
code: 1,
|
|
305
|
-
file: context.node.getSourceFile()
|
|
306
|
-
|
|
283
|
+
file: context.node.getSourceFile(),
|
|
284
|
+
...toTSLocation(node.callTarget),
|
|
307
285
|
messageText: `Unknown expression ${exprName}`
|
|
308
|
-
})
|
|
286
|
+
});
|
|
309
287
|
}
|
|
310
288
|
}
|
|
311
289
|
return diags;
|
|
@@ -321,29 +299,31 @@ class ExpressionLanguageService {
|
|
|
321
299
|
const parsed = parseExpression(context.text.trim(), { strict: false });
|
|
322
300
|
if (parsed.error) {
|
|
323
301
|
return [
|
|
324
|
-
|
|
302
|
+
{
|
|
325
303
|
category: ts.DiagnosticCategory.Error,
|
|
326
304
|
code: 1,
|
|
327
|
-
file: context.node.getSourceFile()
|
|
328
|
-
|
|
305
|
+
file: context.node.getSourceFile(),
|
|
306
|
+
...toTSLocation(parsed),
|
|
329
307
|
messageText: parsed.error.message
|
|
330
|
-
}
|
|
308
|
+
}
|
|
331
309
|
];
|
|
332
310
|
}
|
|
333
311
|
return [];
|
|
334
312
|
}
|
|
335
|
-
}
|
|
313
|
+
};
|
|
336
314
|
|
|
337
|
-
|
|
315
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/typescript-expression-plugin/src/logger.ts
|
|
316
|
+
var LSPLogger = class {
|
|
338
317
|
constructor(info) {
|
|
339
318
|
this.info = info;
|
|
340
319
|
}
|
|
341
320
|
log(msg) {
|
|
342
321
|
this.info.project.projectService.logger.info(`[player-expr-lsp] ${msg}`);
|
|
343
322
|
}
|
|
344
|
-
}
|
|
323
|
+
};
|
|
345
324
|
|
|
346
|
-
|
|
325
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/typescript-expression-plugin/src/index.ts
|
|
326
|
+
var Plugin = class {
|
|
347
327
|
constructor(initOptions) {
|
|
348
328
|
this.initOptions = initOptions;
|
|
349
329
|
}
|
|
@@ -352,19 +332,27 @@ class Plugin {
|
|
|
352
332
|
this.logger = logger;
|
|
353
333
|
const templateService = new ExpressionLanguageService({ logger });
|
|
354
334
|
this.templateService = templateService;
|
|
355
|
-
return decorateWithTemplateLanguageService(
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
335
|
+
return decorateWithTemplateLanguageService(
|
|
336
|
+
this.initOptions.typescript,
|
|
337
|
+
info.languageService,
|
|
338
|
+
info.project,
|
|
339
|
+
templateService,
|
|
340
|
+
{
|
|
341
|
+
tags: ["e", "expr", "expression"],
|
|
342
|
+
enableForStringWithSubstitutions: true
|
|
343
|
+
},
|
|
344
|
+
{ logger }
|
|
345
|
+
);
|
|
359
346
|
}
|
|
360
347
|
onConfigurationChanged(config) {
|
|
361
|
-
|
|
362
|
-
(_a = this.templateService) == null ? void 0 : _a.setConfig(config);
|
|
348
|
+
this.templateService?.setConfig(config);
|
|
363
349
|
}
|
|
364
|
-
}
|
|
350
|
+
};
|
|
365
351
|
function init(mod) {
|
|
366
352
|
return new Plugin(mod);
|
|
367
353
|
}
|
|
368
|
-
|
|
369
|
-
export {
|
|
370
|
-
|
|
354
|
+
var src_default = init;
|
|
355
|
+
export {
|
|
356
|
+
src_default as default
|
|
357
|
+
};
|
|
358
|
+
//# sourceMappingURL=index.mjs.map
|