@valtzu/codemirror-lang-el 0.8.0 → 0.9.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/CHANGELOG.md +13 -0
- package/README.md +17 -3
- package/dist/index.cjs +160 -110
- package/dist/index.d.cts +73 -4
- package/dist/index.d.ts +73 -4
- package/dist/index.js +167 -120
- package/package.json +8 -13
- package/dist/complete.cjs +0 -224
- package/dist/complete.d.cts +0 -3
- package/dist/complete.d.ts +0 -3
- package/dist/complete.js +0 -220
- package/dist/linter.cjs +0 -221
- package/dist/linter.d.cts +0 -8
- package/dist/linter.d.ts +0 -8
- package/dist/linter.js +0 -216
- package/dist/tooltip.cjs +0 -258
- package/dist/tooltip.d.cts +0 -7
- package/dist/tooltip.d.ts +0 -7
- package/dist/tooltip.js +0 -253
- package/dist/utils.cjs +0 -150
- package/dist/utils.d.cts +0 -53
- package/dist/utils.d.ts +0 -53
- package/dist/utils.js +0 -141
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var lr = require('@lezer/lr');
|
|
6
4
|
var language = require('@codemirror/language');
|
|
7
5
|
var highlight = require('@lezer/highlight');
|
|
@@ -16,35 +14,55 @@ const t = {
|
|
|
16
14
|
};
|
|
17
15
|
|
|
18
16
|
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
19
|
-
const spec_word = {__proto__:null,true:
|
|
20
|
-
const spec_Operator = {__proto__:null,"?":
|
|
17
|
+
const spec_word = {__proto__:null,true:90, TRUE:92, false:94, FALSE:96, null:98, NULL:100, starts:110, with:112, ends:114, contains:116, matches:118, not:120, in:122, and:124, or:126, xor:128};
|
|
18
|
+
const spec_Operator = {__proto__:null,"?":109, "!":131, "~":133, "+":135, "-":137};
|
|
21
19
|
const parser = lr.LRParser.deserialize({
|
|
22
20
|
version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gX^gXvgXxgXzgX}gX!OgX!PgX!QgX!RgX!SgX!UgX!^gX!cgX!dgX!egX!fgX~O!VxO~P!fO|yOw{Xy{X~P!fOw{O~Onha!Vhawha|hayha!Tha~P!fOy|O~P!fOy{P~PYOrnOsnOt!PO~OSUXTUXeUXnUXxUXz[X!WUX!XUX!ZUX![UX!]UX!^UX!_UX!`UX!aUX!bUX!VUXwUX|UXyUX!TUX~Ow!QO~P!fOnfi!Vfiwfi|fiyfi!Tfi~P!fO!V!RO~P!fO|yOw{ay{a~Oy!VO~O|!XO!T!ZO~P!fOwla|layla~P!fOndy!Vdywdy|dyydy!Tdy~P!fO|!XO!T!^O~O!V!_O~P!fO|mq!Tmq~P!fO^TeS]vS~",
|
|
23
|
+
goto: "%O|P}P!QPP!b!Q!Q!e!u!e!xPP!Q!Q!Q!Q!Q!QP!Q!{!Q#[!Q#l#r#xPPPPPPP$OPPPPP$xR^PmWOSTUV`ablxy!R!X!_Rr_mXOSTUV`ablxy!R!X!_RmXRs_kaQfhjktuv!S!T!W![!`mUOSTUV`ablxy!R!X!_Qo]R!OoQzhR!UzQ!Y!SR!]!YQQOQfSShTlQjUQkVQt`QuaQvbQ!SxQ!TyQ!W!RQ![!XR!`!_QiTR}l",
|
|
24
|
+
nodeNames: "⚠ BlockComment Expression PropertyAccess MemberOf NullSafeMemberOf Property ArrayAccess Call Function Arguments MethodAccess Method Number String Boolean Null Object Array Variable TernaryExpression Operator BinaryExpression OperatorKeyword UnaryExpression UnaryOperator Application",
|
|
25
|
+
maxTerm: 68,
|
|
28
26
|
nodeProps: [
|
|
29
|
-
[t,
|
|
27
|
+
[t, 13,"number",14,"string",15,"bool",16,"null",17,"object",18,"array"]
|
|
30
28
|
],
|
|
31
|
-
skippedNodes: [0,1,
|
|
29
|
+
skippedNodes: [0,1,27],
|
|
32
30
|
repeatNodeCount: 3,
|
|
33
|
-
tokenData: "-a~RqXY#YYZ#Y]^#Ypq#Yqr#krs$Quv#{vw%zwx&Sxy'wyz'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O!V~~+fQe~!^!_#{!_!`#{~+oP!_!`#s~+wQe~!_!`#{!`!a#{~,SRe~!O!P,]![!]#{!a!b#{~,bOT~~,gSv~!Q![,b!c!},b#R#S,b#T#o,b~,xOx~~,}Ow~~-SO!U~~-XPe~#p#q#{~-aO!T~",
|
|
32
|
+
tokenizers: [1, new lr.LocalTokenGroup("j~RQYZXz{^~^Os~~aP!P!Qd~iOt~~", 25, 34)],
|
|
35
33
|
topRules: {"Expression":[0,2]},
|
|
36
|
-
specialized: [{term:
|
|
37
|
-
tokenPrec:
|
|
34
|
+
specialized: [{term: 38, get: (value) => spec_word[value] || -1},{term: 21, get: (value) => spec_Operator[value] || -1}],
|
|
35
|
+
tokenPrec: 532
|
|
38
36
|
});
|
|
39
37
|
|
|
40
|
-
|
|
38
|
+
exports.ELScalar = void 0;
|
|
41
39
|
(function (ELScalar) {
|
|
42
40
|
ELScalar["Bool"] = "bool";
|
|
43
41
|
ELScalar["Number"] = "number";
|
|
44
42
|
ELScalar["String"] = "string";
|
|
45
43
|
ELScalar["Null"] = "null";
|
|
46
44
|
ELScalar["Any"] = "any";
|
|
47
|
-
})(ELScalar || (ELScalar = {}));
|
|
45
|
+
})(exports.ELScalar || (exports.ELScalar = {}));
|
|
46
|
+
|
|
47
|
+
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
48
|
+
const BlockComment = 1,
|
|
49
|
+
Expression = 2,
|
|
50
|
+
PropertyAccess = 3,
|
|
51
|
+
Property = 6,
|
|
52
|
+
ArrayAccess = 7,
|
|
53
|
+
Call = 8,
|
|
54
|
+
Function = 9,
|
|
55
|
+
Arguments = 10,
|
|
56
|
+
MethodAccess = 11,
|
|
57
|
+
Method = 12,
|
|
58
|
+
String = 14,
|
|
59
|
+
Array$1 = 18,
|
|
60
|
+
Variable = 19,
|
|
61
|
+
TernaryExpression = 20,
|
|
62
|
+
BinaryExpression = 22,
|
|
63
|
+
OperatorKeyword = 23,
|
|
64
|
+
UnaryExpression = 24,
|
|
65
|
+
Application = 26;
|
|
48
66
|
|
|
49
67
|
const createInfoElement = (html) => {
|
|
50
68
|
const dom = document.createElement("div");
|
|
@@ -58,30 +76,30 @@ function resolveFunctionDefinition(node, state, config) {
|
|
|
58
76
|
return undefined;
|
|
59
77
|
}
|
|
60
78
|
let identifier;
|
|
61
|
-
if (node.
|
|
62
|
-
const leftArgument = (_a = node.firstChild) === null || _a ===
|
|
79
|
+
if ((node.type.is(PropertyAccess) || node.type.is(MethodAccess)) && node.lastChild) {
|
|
80
|
+
const leftArgument = (_a = node.firstChild) === null || _a === undefined ? undefined : _a.node;
|
|
63
81
|
const types = Array.from(resolveTypes(state, leftArgument, config));
|
|
64
82
|
identifier = state.sliceDoc(node.lastChild.from, node.lastChild.to);
|
|
65
|
-
return types.map(type => { var _a; return resolveCallable(identifier, (_a = config.types) === null || _a ===
|
|
83
|
+
return types.map(type => { var _a; return resolveCallable(identifier, (_a = config.types) === null || _a === undefined ? undefined : _a[type]); }).find(x => x);
|
|
66
84
|
}
|
|
67
|
-
else if (node.
|
|
85
|
+
else if (node.type.is(Function)) {
|
|
68
86
|
identifier = state.sliceDoc(node.from, node.node.firstChild ? node.node.firstChild.from - 1 : node.to);
|
|
69
87
|
return resolveCallable(identifier, config);
|
|
70
88
|
}
|
|
71
89
|
}
|
|
72
|
-
const resolveCallable = (identifier, config) => { var _a; return (_a = config === null || config ===
|
|
73
|
-
const resolveIdentifier = (
|
|
90
|
+
const resolveCallable = (identifier, config) => { var _a; return (_a = config === null || config === undefined ? undefined : config.functions) === null || _a === undefined ? undefined : _a.find(x => x.name === identifier); };
|
|
91
|
+
const resolveIdentifier = (nodeTypeId, identifier, config) => {
|
|
74
92
|
var _a;
|
|
75
|
-
switch (
|
|
76
|
-
case
|
|
77
|
-
case
|
|
93
|
+
switch (nodeTypeId) {
|
|
94
|
+
case Method:
|
|
95
|
+
case Function:
|
|
78
96
|
return resolveCallable(identifier, config);
|
|
79
|
-
case
|
|
80
|
-
case
|
|
81
|
-
return (_a = config === null || config ===
|
|
97
|
+
case Property:
|
|
98
|
+
case Variable:
|
|
99
|
+
return (_a = config === null || config === undefined ? undefined : config.identifiers) === null || _a === undefined ? undefined : _a.find(x => x.name === identifier);
|
|
82
100
|
}
|
|
83
101
|
};
|
|
84
|
-
function resolveTypes(state, node, config
|
|
102
|
+
function resolveTypes(state, node, config) {
|
|
85
103
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
86
104
|
let types = new Set();
|
|
87
105
|
if (!node) {
|
|
@@ -91,43 +109,43 @@ function resolveTypes(state, node, config, matchExact) {
|
|
|
91
109
|
if (typeof (type = node.type.prop(t)) !== "undefined") {
|
|
92
110
|
types.add(type);
|
|
93
111
|
}
|
|
94
|
-
else if (node.
|
|
112
|
+
else if (node.type.is(Call) && node.firstChild && node.lastChild) {
|
|
95
113
|
resolveTypes(state, node.firstChild, config).forEach(x => types.add(x));
|
|
96
114
|
}
|
|
97
|
-
else if (node.
|
|
115
|
+
else if (node.type.is(Variable)) {
|
|
98
116
|
const varName = state.sliceDoc(node.from, node.to) || '';
|
|
99
117
|
// @ts-ignore
|
|
100
|
-
(_b = (_a = resolveIdentifier(node.
|
|
118
|
+
(_b = (_a = resolveIdentifier(node.type.id, varName, config)) === null || _a === undefined ? undefined : _a.type) === null || _b === undefined ? undefined : _b.forEach((x) => types.add(x));
|
|
101
119
|
}
|
|
102
|
-
else if (node.
|
|
120
|
+
else if (node.type.is(Function)) {
|
|
103
121
|
const varName = state.sliceDoc(node.from, node.to) || '';
|
|
104
122
|
// @ts-ignore
|
|
105
|
-
(_d = (_c = resolveIdentifier(node.
|
|
123
|
+
(_d = (_c = resolveIdentifier(node.type.id, varName, config)) === null || _c === undefined ? undefined : _c.returnType) === null || _d === undefined ? undefined : _d.forEach((x) => types.add(x));
|
|
106
124
|
}
|
|
107
|
-
else if (node.
|
|
125
|
+
else if (node.type.is(PropertyAccess) && node.firstChild && ((_e = node.lastChild) === null || _e === undefined ? undefined : _e.type.is(Property))) {
|
|
108
126
|
const varName = state.sliceDoc(node.lastChild.from, node.lastChild.to) || '';
|
|
109
|
-
(_f = resolveTypes(state, node.firstChild, config)) === null || _f ===
|
|
127
|
+
(_f = resolveTypes(state, node.firstChild, config)) === null || _f === undefined ? undefined : _f.forEach(baseType => {
|
|
110
128
|
var _a, _b, _c, _d;
|
|
111
129
|
// @ts-ignore
|
|
112
|
-
(_d = (_c = resolveIdentifier((_a = node.lastChild) === null || _a ===
|
|
130
|
+
(_d = (_c = resolveIdentifier((_a = node.lastChild) === null || _a === undefined ? undefined : _a.type.id, varName, (_b = config.types) === null || _b === undefined ? undefined : _b[baseType])) === null || _c === undefined ? undefined : _c.type) === null || _d === undefined ? undefined : _d.forEach((x) => types.add(x));
|
|
113
131
|
});
|
|
114
132
|
}
|
|
115
|
-
else if (node.
|
|
133
|
+
else if (node.type.is(MethodAccess) && node.firstChild && ((_g = node.lastChild) === null || _g === undefined ? undefined : _g.type.is(Method))) {
|
|
116
134
|
const varName = state.sliceDoc(node.lastChild.from, node.lastChild.to) || '';
|
|
117
|
-
(_h = resolveTypes(state, node.firstChild, config)) === null || _h ===
|
|
135
|
+
(_h = resolveTypes(state, node.firstChild, config)) === null || _h === undefined ? undefined : _h.forEach(baseType => {
|
|
118
136
|
var _a, _b, _c, _d;
|
|
119
137
|
// @ts-ignore
|
|
120
|
-
(_d = (_c = resolveIdentifier((_a = node.lastChild) === null || _a ===
|
|
138
|
+
(_d = (_c = resolveIdentifier((_a = node.lastChild) === null || _a === undefined ? undefined : _a.type.id, varName, (_b = config.types) === null || _b === undefined ? undefined : _b[baseType])) === null || _c === undefined ? undefined : _c.returnType) === null || _d === undefined ? undefined : _d.forEach((x) => types.add(x));
|
|
121
139
|
});
|
|
122
140
|
}
|
|
123
|
-
else if (node.
|
|
141
|
+
else if (node.type.is(Application) && node.firstChild) {
|
|
124
142
|
resolveTypes(state, node.firstChild, config).forEach(x => types.add(x));
|
|
125
143
|
}
|
|
126
|
-
else if (node.
|
|
144
|
+
else if (node.type.is(TernaryExpression) && node.firstChild && node.firstChild.nextSibling && node.firstChild.nextSibling.nextSibling) {
|
|
127
145
|
resolveTypes(state, node.firstChild.nextSibling, config).forEach(x => types.add(x));
|
|
128
146
|
resolveTypes(state, node.firstChild.nextSibling.nextSibling, config).forEach(x => types.add(x));
|
|
129
147
|
}
|
|
130
|
-
else if (node.
|
|
148
|
+
else if (node.type.is(BinaryExpression) && ((_j = node.firstChild) === null || _j === undefined ? undefined : _j.nextSibling) && ((_l = (_k = node.firstChild) === null || _k === undefined ? undefined : _k.nextSibling) === null || _l === undefined ? undefined : _l.nextSibling)) {
|
|
131
149
|
const operator = state.sliceDoc(node.firstChild.nextSibling.from, node.firstChild.nextSibling.to);
|
|
132
150
|
if (operator == '?:' || operator == '??' || operator == '?') {
|
|
133
151
|
if (operator == '?:' || operator == '??') {
|
|
@@ -136,23 +154,23 @@ function resolveTypes(state, node, config, matchExact) {
|
|
|
136
154
|
resolveTypes(state, node.firstChild.nextSibling.nextSibling, config).forEach(x => types.add(x));
|
|
137
155
|
}
|
|
138
156
|
else if (['||', '&&', '==', '!=', '===', '!==', '>=', '<=', '>', '<'].includes(operator) || keywords.find(x => x.name == operator)) {
|
|
139
|
-
types.add(ELScalar.Bool);
|
|
157
|
+
types.add(exports.ELScalar.Bool);
|
|
140
158
|
}
|
|
141
159
|
else if (['**', '|', '^', '&', '<<', '>>', '+', '-', '*', '/', '%'].includes(operator)) {
|
|
142
|
-
types.add(ELScalar.Number);
|
|
160
|
+
types.add(exports.ELScalar.Number);
|
|
143
161
|
}
|
|
144
162
|
}
|
|
145
|
-
else if (node.
|
|
163
|
+
else if (node.type.is(UnaryExpression) && node.firstChild) {
|
|
146
164
|
const operator = state.sliceDoc(node.firstChild.from, node.firstChild.to);
|
|
147
165
|
if (['not', '!'].includes(operator)) {
|
|
148
|
-
types.add(ELScalar.Bool);
|
|
166
|
+
types.add(exports.ELScalar.Bool);
|
|
149
167
|
}
|
|
150
168
|
else if (['+', '-'].includes(operator)) {
|
|
151
|
-
types.add(ELScalar.Number);
|
|
169
|
+
types.add(exports.ELScalar.Number);
|
|
152
170
|
}
|
|
153
171
|
}
|
|
154
172
|
if (types.size === 0) {
|
|
155
|
-
types.add(ELScalar.Any);
|
|
173
|
+
types.add(exports.ELScalar.Any);
|
|
156
174
|
}
|
|
157
175
|
return types;
|
|
158
176
|
}
|
|
@@ -172,6 +190,16 @@ const keywords = [
|
|
|
172
190
|
{ name: 'xor' },
|
|
173
191
|
];
|
|
174
192
|
|
|
193
|
+
var utils = /*#__PURE__*/Object.freeze({
|
|
194
|
+
__proto__: null,
|
|
195
|
+
createInfoElement: createInfoElement,
|
|
196
|
+
getExpressionLanguageConfig: getExpressionLanguageConfig,
|
|
197
|
+
keywords: keywords,
|
|
198
|
+
resolveFunctionDefinition: resolveFunctionDefinition,
|
|
199
|
+
resolveIdentifier: resolveIdentifier,
|
|
200
|
+
resolveTypes: resolveTypes
|
|
201
|
+
});
|
|
202
|
+
|
|
175
203
|
/**
|
|
176
204
|
* @internal
|
|
177
205
|
*/
|
|
@@ -179,64 +207,65 @@ const expressionLanguageLinterSource = (state) => {
|
|
|
179
207
|
const config = getExpressionLanguageConfig(state);
|
|
180
208
|
let diagnostics = [];
|
|
181
209
|
language.syntaxTree(state).cursor().iterate(node => {
|
|
182
|
-
var _a, _b, _c, _d, _e, _f
|
|
183
|
-
const { from, to,
|
|
210
|
+
var _a, _b, _c, _d, _e, _f;
|
|
211
|
+
const { from, to, type: { id } } = node;
|
|
184
212
|
let identifier;
|
|
185
|
-
switch (
|
|
186
|
-
case
|
|
213
|
+
switch (id) {
|
|
214
|
+
case 0:
|
|
187
215
|
if (state.doc.length === 0 || from === 0) {
|
|
188
216
|
// Don't show error on empty doc (even though it is an error)
|
|
189
217
|
return;
|
|
190
218
|
}
|
|
191
219
|
identifier = state.sliceDoc(from, to);
|
|
192
220
|
if (identifier.length === 0) {
|
|
193
|
-
diagnostics.push({ from, to: (_c = (_b = (_a = node.node.parent) === null || _a ===
|
|
221
|
+
diagnostics.push({ from, to: (_c = (_b = (_a = node.node.parent) === null || _a === undefined ? undefined : _a.parent) === null || _b === undefined ? undefined : _b.to) !== null && _c !== undefined ? _c : to, severity: 'error', message: `Expression expected` });
|
|
194
222
|
}
|
|
195
223
|
else {
|
|
196
224
|
const type = /^[a-zA-Z_]+[a-zA-Z_0-9]*$/.test(identifier) ? 'identifier' : 'operator';
|
|
197
|
-
diagnostics.push({ from, to, severity: 'error', message: `Unexpected ${type}
|
|
225
|
+
diagnostics.push({ from, to, severity: 'error', message: `Unexpected ${type} <code>${identifier}</code>` });
|
|
198
226
|
}
|
|
199
227
|
return;
|
|
200
|
-
case
|
|
201
|
-
const
|
|
228
|
+
case Arguments:
|
|
229
|
+
const fn = resolveFunctionDefinition(node.node.prevSibling, state, config);
|
|
230
|
+
const args = fn === null || fn === undefined ? undefined : fn.args;
|
|
202
231
|
if (!args) {
|
|
203
232
|
return;
|
|
204
233
|
}
|
|
205
234
|
for (let n = node.node.firstChild, i = 0; n != null; n = n.nextSibling) {
|
|
206
|
-
if (n.
|
|
235
|
+
if (n.type.is(BlockComment)) {
|
|
207
236
|
continue;
|
|
208
237
|
}
|
|
209
238
|
if (i > args.length - 1) {
|
|
210
|
-
diagnostics.push({ from: n.from, to: n.to, severity: '
|
|
239
|
+
diagnostics.push({ from: n.from, to: n.to, severity: 'warning', message: `Unexpected argument – <code>${fn.name}</code> takes ${args.length} argument${args.length == 1 ? '' : 's'}` });
|
|
211
240
|
continue;
|
|
212
241
|
}
|
|
213
242
|
const typesUsed = Array.from(resolveTypes(state, n, config));
|
|
214
243
|
const typesExpected = args[i].type;
|
|
215
|
-
if (typesExpected && !typesExpected.includes(ELScalar.Any) && !typesUsed.some(x => typesExpected.includes(x))) {
|
|
244
|
+
if (typesExpected && !typesExpected.includes(exports.ELScalar.Any) && !typesUsed.some(x => typesExpected.includes(x))) {
|
|
216
245
|
diagnostics.push({ from: n.from, to: n.to, severity: 'error', message: `<code>${typesExpected.join('|')}</code> expected, got <code>${typesUsed.join('|')}</code>` });
|
|
217
246
|
}
|
|
218
247
|
i++;
|
|
219
248
|
}
|
|
220
249
|
break;
|
|
221
|
-
case
|
|
222
|
-
case
|
|
223
|
-
const leftArgument = (
|
|
250
|
+
case Property:
|
|
251
|
+
case Method:
|
|
252
|
+
const leftArgument = (_e = (_d = node.node.parent) === null || _d === undefined ? undefined : _d.firstChild) === null || _e === undefined ? undefined : _e.node;
|
|
224
253
|
const types = Array.from(resolveTypes(state, leftArgument, config));
|
|
225
254
|
identifier = state.sliceDoc(from, to);
|
|
226
|
-
if (!types.find(type => { var _a; return resolveIdentifier(
|
|
227
|
-
diagnostics.push({ from, to, severity: 'error', message: `${node.name}
|
|
255
|
+
if (!types.find(type => { var _a; return resolveIdentifier(id, identifier, (_a = config.types) === null || _a === undefined ? undefined : _a[type]); })) {
|
|
256
|
+
diagnostics.push({ from, to, severity: 'error', message: `${node.name} <code>${identifier}</code> not found in <code>${types.join('|')}</code>` });
|
|
228
257
|
}
|
|
229
258
|
break;
|
|
230
|
-
case
|
|
231
|
-
case
|
|
259
|
+
case Variable:
|
|
260
|
+
case Function:
|
|
232
261
|
identifier = state.sliceDoc(from, node.node.firstChild ? node.node.firstChild.from - 1 : to);
|
|
233
|
-
if (!resolveIdentifier(
|
|
234
|
-
diagnostics.push({ from, to, severity: 'error', message: `${node.node.name}
|
|
262
|
+
if (!resolveIdentifier(id, identifier, config)) {
|
|
263
|
+
diagnostics.push({ from, to, severity: 'error', message: `${node.node.name} <code>${identifier}</code> not found` });
|
|
235
264
|
}
|
|
236
265
|
break;
|
|
237
266
|
}
|
|
238
|
-
if (identifier && ((
|
|
239
|
-
diagnostics.push({ from, to, severity: 'error', message: `Unexpected identifier
|
|
267
|
+
if (identifier && ((_f = node.node.parent) === null || _f === undefined ? undefined : _f.type.isError)) {
|
|
268
|
+
diagnostics.push({ from, to, severity: 'error', message: `Unexpected identifier <code>${identifier}</code>` });
|
|
240
269
|
}
|
|
241
270
|
});
|
|
242
271
|
diagnostics.forEach(d => {
|
|
@@ -250,15 +279,21 @@ const expressionLanguageLinterSource = (state) => {
|
|
|
250
279
|
};
|
|
251
280
|
const expressionLanguageLinter = lint.linter(view => expressionLanguageLinterSource(view.state));
|
|
252
281
|
|
|
282
|
+
var linter = /*#__PURE__*/Object.freeze({
|
|
283
|
+
__proto__: null,
|
|
284
|
+
expressionLanguageLinter: expressionLanguageLinter,
|
|
285
|
+
expressionLanguageLinterSource: expressionLanguageLinterSource
|
|
286
|
+
});
|
|
287
|
+
|
|
253
288
|
const autocompleteFunction = (x) => {
|
|
254
289
|
var _a, _b, _c;
|
|
255
290
|
return ({
|
|
256
|
-
label: `${x.name}(${((_b = (_a = x.args) === null || _a ===
|
|
291
|
+
label: `${x.name}(${((_b = (_a = x.args) === null || _a === undefined ? undefined : _a.map(x => x.name)) === null || _b === undefined ? undefined : _b.join(',')) || ''})`,
|
|
257
292
|
apply: (view, completion, from, to) => {
|
|
258
|
-
var _a;
|
|
259
|
-
view.dispatch(Object.assign(Object.assign({}, autocomplete.insertCompletionText(view.state, `${x.name}()`, from, to)), { selection: { anchor: from + x.name.length + (((_a = x.args) === null || _a ===
|
|
293
|
+
var _a, _b;
|
|
294
|
+
view.dispatch(Object.assign(Object.assign({}, autocomplete.insertCompletionText(view.state, `${x.name}()`, from, to)), { selection: { anchor: from + x.name.length + (((_b = (_a = x.args) === null || _a === undefined ? undefined : _a.length) !== null && _b !== undefined ? _b : 0) > 0 ? 1 : 2) } }));
|
|
260
295
|
},
|
|
261
|
-
detail: (_c = x.returnType) === null || _c ===
|
|
296
|
+
detail: (_c = x.returnType) === null || _c === undefined ? undefined : _c.join('|'),
|
|
262
297
|
info: x.info,
|
|
263
298
|
type: "function",
|
|
264
299
|
});
|
|
@@ -269,7 +304,7 @@ const autocompleteIdentifier = (x) => {
|
|
|
269
304
|
label: x.name,
|
|
270
305
|
apply: x.name,
|
|
271
306
|
info: x.info,
|
|
272
|
-
detail: x.detail || ((_a = x.type) === null || _a ===
|
|
307
|
+
detail: x.detail || ((_a = x.type) === null || _a === undefined ? undefined : _a.join('|')),
|
|
273
308
|
type: 'variable',
|
|
274
309
|
});
|
|
275
310
|
};
|
|
@@ -284,14 +319,14 @@ function completeOperatorKeyword(state, config, tree, from, to, explicit) {
|
|
|
284
319
|
info: info,
|
|
285
320
|
detail,
|
|
286
321
|
type: "keyword"
|
|
287
|
-
}))) !== null && _a !==
|
|
288
|
-
validFor: (text) => { var _a; return (_a = keywords.some(({ name }) => explicit || name.includes(text))) !== null && _a !==
|
|
322
|
+
}))) !== null && _a !== undefined ? _a : [],
|
|
323
|
+
validFor: (text) => { var _a; return (_a = keywords.some(({ name }) => explicit || name.includes(text))) !== null && _a !== undefined ? _a : false; },
|
|
289
324
|
};
|
|
290
325
|
}
|
|
291
326
|
function completeIdentifier(state, config, tree, from, to) {
|
|
292
327
|
var _a, _b;
|
|
293
|
-
const identifiers = (_a = config.identifiers) !== null && _a !==
|
|
294
|
-
const functions = (_b = config.functions) !== null && _b !==
|
|
328
|
+
const identifiers = (_a = config.identifiers) !== null && _a !== undefined ? _a : []; //?.filter(({ name }) => explicit || name.toLowerCase().startsWith(text)) ?? [];
|
|
329
|
+
const functions = (_b = config.functions) !== null && _b !== undefined ? _b : []; //?.filter(({ name }) => explicit || name.toLowerCase().startsWith(text)) ?? [];
|
|
295
330
|
return {
|
|
296
331
|
from,
|
|
297
332
|
to,
|
|
@@ -300,18 +335,18 @@ function completeIdentifier(state, config, tree, from, to) {
|
|
|
300
335
|
};
|
|
301
336
|
}
|
|
302
337
|
function completeMember(state, config, tree, from, to, explicit) {
|
|
303
|
-
var _a, _b, _c, _d;
|
|
304
|
-
if (((_a = tree.parent) === null || _a ===
|
|
338
|
+
var _a, _b, _c, _d, _e, _f;
|
|
339
|
+
if (!(((_a = tree.parent) === null || _a === undefined ? undefined : _a.type.is(PropertyAccess)) || ((_b = tree.parent) === null || _b === undefined ? undefined : _b.type.is(MethodAccess))) || !((_c = tree.parent) === null || _c === undefined ? undefined : _c.firstChild)) {
|
|
305
340
|
return null;
|
|
306
341
|
}
|
|
307
342
|
const types = resolveTypes(state, tree.parent.firstChild.node, config);
|
|
308
|
-
if (!(types === null || types ===
|
|
343
|
+
if (!(types === null || types === undefined ? undefined : types.size)) {
|
|
309
344
|
return null;
|
|
310
345
|
}
|
|
311
346
|
let options = [];
|
|
312
347
|
for (const type of types) {
|
|
313
|
-
const typeDeclaration = (
|
|
314
|
-
options.push(...(((
|
|
348
|
+
const typeDeclaration = (_d = config.types) === null || _d === undefined ? undefined : _d[type];
|
|
349
|
+
options.push(...(((_e = typeDeclaration === null || typeDeclaration === undefined ? undefined : typeDeclaration.identifiers) === null || _e === undefined ? undefined : _e.map(autocompleteIdentifier)) || []), ...(((_f = typeDeclaration === null || typeDeclaration === undefined ? undefined : typeDeclaration.functions) === null || _f === undefined ? undefined : _f.map(autocompleteFunction)) || []));
|
|
315
350
|
}
|
|
316
351
|
return {
|
|
317
352
|
from,
|
|
@@ -321,34 +356,39 @@ function completeMember(state, config, tree, from, to, explicit) {
|
|
|
321
356
|
};
|
|
322
357
|
}
|
|
323
358
|
function expressionLanguageCompletion(context) {
|
|
324
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k
|
|
359
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
325
360
|
const { state, pos, explicit } = context;
|
|
326
361
|
const tree = language.syntaxTree(state);
|
|
327
362
|
const lastChar = state.sliceDoc(pos - 1, pos);
|
|
328
363
|
const prevNode = tree.resolveInner(pos, lastChar === ')' ? 0 : -1);
|
|
329
364
|
const config = getExpressionLanguageConfig(state);
|
|
330
|
-
const isIdentifier = (node) =>
|
|
331
|
-
const isMember = (node) =>
|
|
332
|
-
if (prevNode.
|
|
365
|
+
const isIdentifier = (node) => (node === null || node === undefined ? undefined : node.type.is(Variable)) || (node === null || node === undefined ? undefined : node.type.is(Function));
|
|
366
|
+
const isMember = (node) => (node === null || node === undefined ? undefined : node.type.is(Property)) || (node === null || node === undefined ? undefined : node.type.is(Method));
|
|
367
|
+
if (prevNode.type.is(String) || prevNode.type.is(BlockComment)) {
|
|
333
368
|
return null;
|
|
334
369
|
}
|
|
335
|
-
if (((_a = prevNode.parent) === null || _a ===
|
|
370
|
+
if ((((_a = prevNode.parent) === null || _a === undefined ? undefined : _a.type.is(PropertyAccess)) || ((_b = prevNode.parent) === null || _b === undefined ? undefined : _b.type.is(MethodAccess))) && [PropertyAccess, MethodAccess, ArrayAccess, Variable, Call, Application].includes((_c = prevNode.parent.firstChild) === null || _c === undefined ? undefined : _c.type.id)) {
|
|
336
371
|
return completeMember(state, config, prevNode, isIdentifier(prevNode) || isMember(prevNode) ? prevNode.from : pos, pos);
|
|
337
372
|
}
|
|
338
|
-
if ([
|
|
339
|
-
|| [
|
|
340
|
-
|| [
|
|
341
|
-
|| [
|
|
342
|
-
return completeOperatorKeyword(state, config, prevNode, ![
|
|
373
|
+
if (/^[\sa-z]*$/.test(lastChar) && ([Expression, UnaryExpression, BinaryExpression, TernaryExpression].includes(prevNode.type.id) && prevNode.lastChild && !((_d = prevNode.lastChild) === null || _d === undefined ? undefined : _d.type.isError)
|
|
374
|
+
|| [Arguments, Array$1].includes(prevNode.type.id) && prevNode.lastChild && !((_e = prevNode.lastChild) === null || _e === undefined ? undefined : _e.type.isError)
|
|
375
|
+
|| [Expression, UnaryExpression, BinaryExpression, TernaryExpression].includes((_f = prevNode.parent) === null || _f === undefined ? undefined : _f.type.id) && prevNode.type.isError
|
|
376
|
+
|| [Variable, Function].includes((_g = prevNode.parent) === null || _g === undefined ? undefined : _g.type.id) && prevNode.type.isError)) {
|
|
377
|
+
return completeOperatorKeyword(state, config, prevNode, ![Expression, UnaryExpression, BinaryExpression, TernaryExpression, Arguments].includes(prevNode.type.id) ? prevNode.from : pos, pos, explicit);
|
|
343
378
|
}
|
|
344
|
-
if (!/[0-9]/.test(lastChar) && !
|
|
345
|
-
|| [
|
|
346
|
-
||
|
|
379
|
+
if (!/[0-9]/.test(lastChar) && !prevNode.type.is(OperatorKeyword) && ([Expression, UnaryExpression, BinaryExpression, TernaryExpression].includes(prevNode.type.id) && ((_h = prevNode.lastChild) === null || _h === undefined ? undefined : _h.type.isError)
|
|
380
|
+
|| [Expression, UnaryExpression, BinaryExpression, TernaryExpression, Arguments].includes((_k = (_j = prevNode.parent) === null || _j === undefined ? undefined : _j.type.id) !== null && _k !== undefined ? _k : -1) && !prevNode.type.isError
|
|
381
|
+
|| prevNode.type.is(Arguments) || prevNode.type.is(Array$1))) {
|
|
347
382
|
return completeIdentifier(state, config, prevNode, isIdentifier(prevNode) ? prevNode.from : pos, pos);
|
|
348
383
|
}
|
|
349
384
|
return null;
|
|
350
385
|
}
|
|
351
386
|
|
|
387
|
+
var complete = /*#__PURE__*/Object.freeze({
|
|
388
|
+
__proto__: null,
|
|
389
|
+
expressionLanguageCompletion: expressionLanguageCompletion
|
|
390
|
+
});
|
|
391
|
+
|
|
352
392
|
function getNodeOrdinal(node) {
|
|
353
393
|
let ordinal = -1;
|
|
354
394
|
// noinspection StatementWithEmptyBodyJS
|
|
@@ -358,7 +398,7 @@ function getNodeOrdinal(node) {
|
|
|
358
398
|
}
|
|
359
399
|
function resolveArguments(node) {
|
|
360
400
|
let c = node;
|
|
361
|
-
while (c && c.
|
|
401
|
+
while (c && !c.type.is(Arguments)) {
|
|
362
402
|
c = c.parent;
|
|
363
403
|
}
|
|
364
404
|
return c;
|
|
@@ -381,7 +421,7 @@ function getCursorTooltips(state) {
|
|
|
381
421
|
return null;
|
|
382
422
|
}
|
|
383
423
|
const n = args.childAfter(range.from - 1);
|
|
384
|
-
const argName = (_b = (_a = fn.args) === null || _a ===
|
|
424
|
+
const argName = (_b = (_a = fn.args) === null || _a === undefined ? undefined : _a[n ? getNodeOrdinal(n) : 0]) === null || _b === undefined ? undefined : _b.name;
|
|
385
425
|
if (n && n.from !== range.from || !argName) {
|
|
386
426
|
return null;
|
|
387
427
|
}
|
|
@@ -410,12 +450,12 @@ const cursorTooltipField = state.StateField.define({
|
|
|
410
450
|
provide: f => view.showTooltip.computeN([f], state => state.field(f))
|
|
411
451
|
});
|
|
412
452
|
const keywordTooltip = view.hoverTooltip((view, pos, side) => {
|
|
413
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
453
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
414
454
|
const config = getExpressionLanguageConfig(view.state);
|
|
415
455
|
const tree = language.syntaxTree(view.state).resolveInner(pos, side);
|
|
416
|
-
if (tree.
|
|
456
|
+
if (tree.type.is(OperatorKeyword)) {
|
|
417
457
|
const name = view.state.sliceDoc(tree.from, tree.to);
|
|
418
|
-
const info = (_a = keywords.find(x => x.name === name)) === null || _a ===
|
|
458
|
+
const info = (_a = keywords.find(x => x.name === name)) === null || _a === undefined ? undefined : _a.info;
|
|
419
459
|
if (info) {
|
|
420
460
|
return {
|
|
421
461
|
pos: tree.from,
|
|
@@ -425,25 +465,25 @@ const keywordTooltip = view.hoverTooltip((view, pos, side) => {
|
|
|
425
465
|
};
|
|
426
466
|
}
|
|
427
467
|
}
|
|
428
|
-
if (![
|
|
468
|
+
if (![Function, Variable, Method, Property].includes(tree.type.id)) {
|
|
429
469
|
return null;
|
|
430
470
|
}
|
|
431
471
|
const skipEmpty = (x) => x;
|
|
432
472
|
let info;
|
|
433
|
-
if (((_b = tree.parent) === null || _b ===
|
|
473
|
+
if (((_b = tree.parent) === null || _b === undefined ? undefined : _b.firstChild) && (((_c = tree.parent) === null || _c === undefined ? undefined : _c.type.is(PropertyAccess)) || ((_d = tree.parent) === null || _d === undefined ? undefined : _d.type.is(MethodAccess))) && tree.prevSibling) {
|
|
434
474
|
const node = tree.parent.firstChild;
|
|
435
475
|
const types = Array.from(resolveTypes(view.state, node, config));
|
|
436
476
|
const name = view.state.sliceDoc(tree.from, tree.to);
|
|
437
477
|
info = [
|
|
438
|
-
...types.map(type => { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = config.types) === null || _a ===
|
|
439
|
-
...types.map(type => { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = config.types) === null || _a ===
|
|
478
|
+
...types.map(type => { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = config.types) === null || _a === undefined ? undefined : _a[type]) === null || _b === undefined ? undefined : _b.identifiers) === null || _c === undefined ? undefined : _c.find(x => x.name === name)) === null || _d === undefined ? undefined : _d.info; }).filter(skipEmpty),
|
|
479
|
+
...types.map(type => { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = config.types) === null || _a === undefined ? undefined : _a[type]) === null || _b === undefined ? undefined : _b.functions) === null || _c === undefined ? undefined : _c.find(x => x.name === name)) === null || _d === undefined ? undefined : _d.info; }).filter(skipEmpty),
|
|
440
480
|
].join('\n');
|
|
441
481
|
}
|
|
442
482
|
else {
|
|
443
483
|
const name = view.state.sliceDoc(tree.from, tree.to);
|
|
444
484
|
info = [
|
|
445
|
-
...[(
|
|
446
|
-
...[(
|
|
485
|
+
...[(_f = (_e = config.identifiers) === null || _e === undefined ? undefined : _e.find(x => x.name === name)) === null || _f === undefined ? undefined : _f.info].filter(skipEmpty),
|
|
486
|
+
...[(_h = (_g = config.functions) === null || _g === undefined ? undefined : _g.find(x => x.name === name)) === null || _h === undefined ? undefined : _h.info].filter(skipEmpty),
|
|
447
487
|
].join('\n');
|
|
448
488
|
}
|
|
449
489
|
if (!info) {
|
|
@@ -457,6 +497,12 @@ const keywordTooltip = view.hoverTooltip((view, pos, side) => {
|
|
|
457
497
|
};
|
|
458
498
|
});
|
|
459
499
|
|
|
500
|
+
var tooltip = /*#__PURE__*/Object.freeze({
|
|
501
|
+
__proto__: null,
|
|
502
|
+
cursorTooltipField: cursorTooltipField,
|
|
503
|
+
keywordTooltip: keywordTooltip
|
|
504
|
+
});
|
|
505
|
+
|
|
460
506
|
const baseTheme = view.EditorView.baseTheme({
|
|
461
507
|
".cm-tooltip.cm-tooltip-cursor": {
|
|
462
508
|
boxShadow: 'rgba(0, 0, 0, .15) 0 1px 2px',
|
|
@@ -538,4 +584,8 @@ function expressionlanguage(config = {}, extensions = []) {
|
|
|
538
584
|
}
|
|
539
585
|
|
|
540
586
|
exports.ELLanguage = ELLanguage;
|
|
587
|
+
exports._complete = complete;
|
|
588
|
+
exports._linter = linter;
|
|
589
|
+
exports._tooltip = tooltip;
|
|
590
|
+
exports._utils = utils;
|
|
541
591
|
exports.expressionlanguage = expressionlanguage;
|