@valtzu/codemirror-lang-el 0.7.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 +18 -25
- package/dist/index.cjs +181 -112
- package/dist/index.d.cts +73 -4
- package/dist/index.d.ts +73 -4
- package/dist/index.js +189 -123
- 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 -207
- package/dist/linter.d.cts +0 -8
- package/dist/linter.d.ts +0 -8
- package/dist/linter.js +0 -202
- 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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X!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",
|
|
27
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'|z{(R{|#{|}(Z}!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!_!`#{~+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,72 +207,93 @@ 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
|
-
let i = 0;
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
234
|
+
for (let n = node.node.firstChild, i = 0; n != null; n = n.nextSibling) {
|
|
235
|
+
if (n.type.is(BlockComment)) {
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
if (i > args.length - 1) {
|
|
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'}` });
|
|
240
|
+
continue;
|
|
210
241
|
}
|
|
211
|
-
|
|
242
|
+
const typesUsed = Array.from(resolveTypes(state, n, config));
|
|
243
|
+
const typesExpected = args[i].type;
|
|
244
|
+
if (typesExpected && !typesExpected.includes(exports.ELScalar.Any) && !typesUsed.some(x => typesExpected.includes(x))) {
|
|
245
|
+
diagnostics.push({ from: n.from, to: n.to, severity: 'error', message: `<code>${typesExpected.join('|')}</code> expected, got <code>${typesUsed.join('|')}</code>` });
|
|
246
|
+
}
|
|
247
|
+
i++;
|
|
212
248
|
}
|
|
213
249
|
break;
|
|
214
|
-
case
|
|
215
|
-
case
|
|
216
|
-
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;
|
|
217
253
|
const types = Array.from(resolveTypes(state, leftArgument, config));
|
|
218
254
|
identifier = state.sliceDoc(from, to);
|
|
219
|
-
if (!types.find(type => { var _a; return resolveIdentifier(
|
|
220
|
-
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>` });
|
|
221
257
|
}
|
|
222
258
|
break;
|
|
223
|
-
case
|
|
224
|
-
case
|
|
259
|
+
case Variable:
|
|
260
|
+
case Function:
|
|
225
261
|
identifier = state.sliceDoc(from, node.node.firstChild ? node.node.firstChild.from - 1 : to);
|
|
226
|
-
if (!resolveIdentifier(
|
|
227
|
-
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` });
|
|
228
264
|
}
|
|
229
265
|
break;
|
|
230
266
|
}
|
|
231
|
-
if (identifier && ((
|
|
232
|
-
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>` });
|
|
233
269
|
}
|
|
234
270
|
});
|
|
271
|
+
diagnostics.forEach(d => {
|
|
272
|
+
d.renderMessage = () => {
|
|
273
|
+
const span = document.createElement('span');
|
|
274
|
+
span.innerHTML = d.message;
|
|
275
|
+
return span;
|
|
276
|
+
};
|
|
277
|
+
});
|
|
235
278
|
return diagnostics;
|
|
236
279
|
};
|
|
237
280
|
const expressionLanguageLinter = lint.linter(view => expressionLanguageLinterSource(view.state));
|
|
238
281
|
|
|
282
|
+
var linter = /*#__PURE__*/Object.freeze({
|
|
283
|
+
__proto__: null,
|
|
284
|
+
expressionLanguageLinter: expressionLanguageLinter,
|
|
285
|
+
expressionLanguageLinterSource: expressionLanguageLinterSource
|
|
286
|
+
});
|
|
287
|
+
|
|
239
288
|
const autocompleteFunction = (x) => {
|
|
240
289
|
var _a, _b, _c;
|
|
241
290
|
return ({
|
|
242
|
-
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(',')) || ''})`,
|
|
243
292
|
apply: (view, completion, from, to) => {
|
|
244
|
-
var _a;
|
|
245
|
-
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) } }));
|
|
246
295
|
},
|
|
247
|
-
detail: (_c = x.returnType) === null || _c ===
|
|
296
|
+
detail: (_c = x.returnType) === null || _c === undefined ? undefined : _c.join('|'),
|
|
248
297
|
info: x.info,
|
|
249
298
|
type: "function",
|
|
250
299
|
});
|
|
@@ -255,7 +304,7 @@ const autocompleteIdentifier = (x) => {
|
|
|
255
304
|
label: x.name,
|
|
256
305
|
apply: x.name,
|
|
257
306
|
info: x.info,
|
|
258
|
-
detail: x.detail || ((_a = x.type) === null || _a ===
|
|
307
|
+
detail: x.detail || ((_a = x.type) === null || _a === undefined ? undefined : _a.join('|')),
|
|
259
308
|
type: 'variable',
|
|
260
309
|
});
|
|
261
310
|
};
|
|
@@ -270,14 +319,14 @@ function completeOperatorKeyword(state, config, tree, from, to, explicit) {
|
|
|
270
319
|
info: info,
|
|
271
320
|
detail,
|
|
272
321
|
type: "keyword"
|
|
273
|
-
}))) !== null && _a !==
|
|
274
|
-
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; },
|
|
275
324
|
};
|
|
276
325
|
}
|
|
277
326
|
function completeIdentifier(state, config, tree, from, to) {
|
|
278
327
|
var _a, _b;
|
|
279
|
-
const identifiers = (_a = config.identifiers) !== null && _a !==
|
|
280
|
-
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)) ?? [];
|
|
281
330
|
return {
|
|
282
331
|
from,
|
|
283
332
|
to,
|
|
@@ -286,18 +335,18 @@ function completeIdentifier(state, config, tree, from, to) {
|
|
|
286
335
|
};
|
|
287
336
|
}
|
|
288
337
|
function completeMember(state, config, tree, from, to, explicit) {
|
|
289
|
-
var _a, _b, _c, _d;
|
|
290
|
-
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)) {
|
|
291
340
|
return null;
|
|
292
341
|
}
|
|
293
342
|
const types = resolveTypes(state, tree.parent.firstChild.node, config);
|
|
294
|
-
if (!(types === null || types ===
|
|
343
|
+
if (!(types === null || types === undefined ? undefined : types.size)) {
|
|
295
344
|
return null;
|
|
296
345
|
}
|
|
297
346
|
let options = [];
|
|
298
347
|
for (const type of types) {
|
|
299
|
-
const typeDeclaration = (
|
|
300
|
-
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)) || []));
|
|
301
350
|
}
|
|
302
351
|
return {
|
|
303
352
|
from,
|
|
@@ -307,34 +356,39 @@ function completeMember(state, config, tree, from, to, explicit) {
|
|
|
307
356
|
};
|
|
308
357
|
}
|
|
309
358
|
function expressionLanguageCompletion(context) {
|
|
310
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k
|
|
359
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
311
360
|
const { state, pos, explicit } = context;
|
|
312
361
|
const tree = language.syntaxTree(state);
|
|
313
362
|
const lastChar = state.sliceDoc(pos - 1, pos);
|
|
314
363
|
const prevNode = tree.resolveInner(pos, lastChar === ')' ? 0 : -1);
|
|
315
364
|
const config = getExpressionLanguageConfig(state);
|
|
316
|
-
const isIdentifier = (node) =>
|
|
317
|
-
const isMember = (node) =>
|
|
318
|
-
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)) {
|
|
319
368
|
return null;
|
|
320
369
|
}
|
|
321
|
-
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)) {
|
|
322
371
|
return completeMember(state, config, prevNode, isIdentifier(prevNode) || isMember(prevNode) ? prevNode.from : pos, pos);
|
|
323
372
|
}
|
|
324
|
-
if ([
|
|
325
|
-
|| [
|
|
326
|
-
|| [
|
|
327
|
-
|| [
|
|
328
|
-
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);
|
|
329
378
|
}
|
|
330
|
-
if (!/[0-9]/.test(lastChar) && !
|
|
331
|
-
|| [
|
|
332
|
-
||
|
|
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))) {
|
|
333
382
|
return completeIdentifier(state, config, prevNode, isIdentifier(prevNode) ? prevNode.from : pos, pos);
|
|
334
383
|
}
|
|
335
384
|
return null;
|
|
336
385
|
}
|
|
337
386
|
|
|
387
|
+
var complete = /*#__PURE__*/Object.freeze({
|
|
388
|
+
__proto__: null,
|
|
389
|
+
expressionLanguageCompletion: expressionLanguageCompletion
|
|
390
|
+
});
|
|
391
|
+
|
|
338
392
|
function getNodeOrdinal(node) {
|
|
339
393
|
let ordinal = -1;
|
|
340
394
|
// noinspection StatementWithEmptyBodyJS
|
|
@@ -344,7 +398,7 @@ function getNodeOrdinal(node) {
|
|
|
344
398
|
}
|
|
345
399
|
function resolveArguments(node) {
|
|
346
400
|
let c = node;
|
|
347
|
-
while (c && c.
|
|
401
|
+
while (c && !c.type.is(Arguments)) {
|
|
348
402
|
c = c.parent;
|
|
349
403
|
}
|
|
350
404
|
return c;
|
|
@@ -367,7 +421,7 @@ function getCursorTooltips(state) {
|
|
|
367
421
|
return null;
|
|
368
422
|
}
|
|
369
423
|
const n = args.childAfter(range.from - 1);
|
|
370
|
-
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;
|
|
371
425
|
if (n && n.from !== range.from || !argName) {
|
|
372
426
|
return null;
|
|
373
427
|
}
|
|
@@ -396,12 +450,12 @@ const cursorTooltipField = state.StateField.define({
|
|
|
396
450
|
provide: f => view.showTooltip.computeN([f], state => state.field(f))
|
|
397
451
|
});
|
|
398
452
|
const keywordTooltip = view.hoverTooltip((view, pos, side) => {
|
|
399
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
453
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
400
454
|
const config = getExpressionLanguageConfig(view.state);
|
|
401
455
|
const tree = language.syntaxTree(view.state).resolveInner(pos, side);
|
|
402
|
-
if (tree.
|
|
456
|
+
if (tree.type.is(OperatorKeyword)) {
|
|
403
457
|
const name = view.state.sliceDoc(tree.from, tree.to);
|
|
404
|
-
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;
|
|
405
459
|
if (info) {
|
|
406
460
|
return {
|
|
407
461
|
pos: tree.from,
|
|
@@ -411,25 +465,25 @@ const keywordTooltip = view.hoverTooltip((view, pos, side) => {
|
|
|
411
465
|
};
|
|
412
466
|
}
|
|
413
467
|
}
|
|
414
|
-
if (![
|
|
468
|
+
if (![Function, Variable, Method, Property].includes(tree.type.id)) {
|
|
415
469
|
return null;
|
|
416
470
|
}
|
|
417
471
|
const skipEmpty = (x) => x;
|
|
418
472
|
let info;
|
|
419
|
-
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) {
|
|
420
474
|
const node = tree.parent.firstChild;
|
|
421
475
|
const types = Array.from(resolveTypes(view.state, node, config));
|
|
422
476
|
const name = view.state.sliceDoc(tree.from, tree.to);
|
|
423
477
|
info = [
|
|
424
|
-
...types.map(type => { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = config.types) === null || _a ===
|
|
425
|
-
...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),
|
|
426
480
|
].join('\n');
|
|
427
481
|
}
|
|
428
482
|
else {
|
|
429
483
|
const name = view.state.sliceDoc(tree.from, tree.to);
|
|
430
484
|
info = [
|
|
431
|
-
...[(
|
|
432
|
-
...[(
|
|
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),
|
|
433
487
|
].join('\n');
|
|
434
488
|
}
|
|
435
489
|
if (!info) {
|
|
@@ -443,6 +497,12 @@ const keywordTooltip = view.hoverTooltip((view, pos, side) => {
|
|
|
443
497
|
};
|
|
444
498
|
});
|
|
445
499
|
|
|
500
|
+
var tooltip = /*#__PURE__*/Object.freeze({
|
|
501
|
+
__proto__: null,
|
|
502
|
+
cursorTooltipField: cursorTooltipField,
|
|
503
|
+
keywordTooltip: keywordTooltip
|
|
504
|
+
});
|
|
505
|
+
|
|
446
506
|
const baseTheme = view.EditorView.baseTheme({
|
|
447
507
|
".cm-tooltip.cm-tooltip-cursor": {
|
|
448
508
|
boxShadow: 'rgba(0, 0, 0, .15) 0 1px 2px',
|
|
@@ -465,6 +525,11 @@ const baseTheme = view.EditorView.baseTheme({
|
|
|
465
525
|
opacity: 0.5,
|
|
466
526
|
fontStyle: "inherit !important",
|
|
467
527
|
},
|
|
528
|
+
"code": {
|
|
529
|
+
fontSize: ".8em",
|
|
530
|
+
fontStyle: "monospace",
|
|
531
|
+
backgroundColor: "rgba(127, 127, 127, .3)",
|
|
532
|
+
},
|
|
468
533
|
});
|
|
469
534
|
|
|
470
535
|
const ELLanguage = language.LRLanguage.define({
|
|
@@ -519,4 +584,8 @@ function expressionlanguage(config = {}, extensions = []) {
|
|
|
519
584
|
}
|
|
520
585
|
|
|
521
586
|
exports.ELLanguage = ELLanguage;
|
|
587
|
+
exports._complete = complete;
|
|
588
|
+
exports._linter = linter;
|
|
589
|
+
exports._tooltip = tooltip;
|
|
590
|
+
exports._utils = utils;
|
|
522
591
|
exports.expressionlanguage = expressionlanguage;
|