@valtzu/codemirror-lang-el 0.8.0 → 0.10.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 +19 -0
- package/README.md +17 -3
- package/dist/index.cjs +150 -93
- package/dist/index.d.cts +73 -4
- package/dist/index.d.ts +73 -4
- package/dist/index.js +158 -104
- 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/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
CHANGELOG
|
|
2
2
|
=========
|
|
3
3
|
|
|
4
|
+
0.10
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
* Exclude optional arguments when linting argument count
|
|
8
|
+
* Lint minimum argument count
|
|
9
|
+
|
|
10
|
+
0.9
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
* **BC BREAK:** Separate files are no longer included in the release (due to using `cm-buildhelper`)
|
|
14
|
+
* Tests are now in TypeScript too
|
|
15
|
+
* Autocomplete is now less aggressive
|
|
16
|
+
* Severity of "too many arguments" linter error was lowered from error -> warning
|
|
17
|
+
|
|
18
|
+
0.8
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
* Lint type of call arguments, if defined
|
|
22
|
+
|
|
4
23
|
0.7
|
|
5
24
|
---
|
|
6
25
|
|
package/README.md
CHANGED
|
@@ -6,19 +6,33 @@
|
|
|
6
6
|
|
|
7
7
|
#### Linting
|
|
8
8
|
|
|
9
|
-

|
|
10
|
+
|
|
11
|
+
1. Lint variable & function names
|
|
12
|
+
1. Lint object properties & methods, even on expression result
|
|
13
|
+
1. Lint argument count
|
|
14
|
+
1. Lint argument types
|
|
10
15
|
|
|
11
16
|
#### Autocompletion
|
|
12
17
|
|
|
13
18
|

|
|
14
19
|
|
|
20
|
+
1. Complete variables & functions
|
|
21
|
+
1. Complete object properties & methods, even on expression result
|
|
22
|
+
1. Complete operator keywords (like `starts with`)
|
|
23
|
+
1. Show list of all available keywords (using `Ctrl+space` by default)
|
|
24
|
+
|
|
15
25
|
#### Hover tooltip
|
|
16
26
|
|
|
17
27
|

|
|
18
28
|
|
|
29
|
+
1. Show description about a variable / function / object member / keyword
|
|
30
|
+
|
|
19
31
|
#### Function argument hints
|
|
20
32
|
|
|
21
|
-

|
|
34
|
+
|
|
35
|
+
1. Show function argument name when the editor cursor is exactly at starting position of the argument
|
|
22
36
|
|
|
23
37
|
---
|
|
24
38
|
|
|
@@ -94,4 +108,4 @@ yarn add @valtzu/codemirror-lang-el
|
|
|
94
108
|
|
|
95
109
|
### Contributing
|
|
96
110
|
|
|
97
|
-
Contributions are
|
|
111
|
+
Contributions are welcome.
|
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: 14,
|
|
23
|
-
states: ")
|
|
24
|
-
stateData: "
|
|
25
|
-
goto: "%
|
|
26
|
-
nodeNames: "⚠ BlockComment Expression
|
|
27
|
-
maxTerm:
|
|
21
|
+
states: ")YOYQPOOP!aOPOOQ!fQPOOO#dQPO'#CeO$wQPO'#CmO%OQPO'#CnOYQPO'#CtOYQPO'#CvOOQO'#DR'#DRO%VQPO'#CdOOQO'#Ck'#CkOOQO'#Cl'#ClOOQO'#Cu'#CuP%[OQO'#C]POOO)C>q)C>qO%gQPO,58yOYQPO,58}OYQPO,59^OYQPO,59[O%lQPO'#CsOOQO'#Cs'#CsO%qQPO'#CsO&{QPO,59XOOQO,59X,59XO'SQPO'#DXO'aQPO,59YO'fQPO,59`O'|QPO,59bO(TQPO'#CfOOQO,59O,59OPOOO'#Cw'#CwP([OQO,58wPOOO,58w,58wO(gQPO'#CbOOQO1G.e1G.eOOQO1G.m1G.mO)zQPO1G.iO*RQPO1G.xO*iQPO1G.vOOQO,59_,59_OYQPO1G.sOYQPO'#CxO*pQPO,59sOOQO1G.t1G.tOOQO1G.|1G.|O*{QPO,59QPOOO-E6u-E6uPOOO1G.c1G.cOOQO7+$T7+$TOYQPO7+$bO+QQPO7+$_O+[QPO,59dOOQO-E6v-E6vOOQO1G.l1G.lO+iQPO<<G|OYQPO'#CyO,PQPO<<GyOOQO<<Gy<<GyO,XQPO,59eOOQO-E6w-E6wOOQOAN=eAN=eOYQPO1G/PO,`QPO7+$k",
|
|
22
|
+
stateData: ",r~OpOSqPQ~O]WO^WOvROxTOzVO}YO!OYO!PYO!QYO!RZO!SZO!USO!^[O!c[O!d[O!e[O!f[O~Oq]O~OS_OT_OeaOx`O!WbO!XcO!ZcO![dO!]dO!^eO!_dO!`dO!adO!bdO~OScXTcXecXncXxcXzXX!WcX!XcX!ZcX![cX!]cX!^cX!_cX!`cX!acX!bcX!VcXwcX|cXycX!TcX~O!TgO~PYOw{P~PYOzlO~OrnOsnOtpO~OvqO~O!YwO~O!_wO]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'|z{(R{|#{|}(Z}!O#{!O!P(`!P!Q(h!Q![(u![!]+[!^!_+a!_!`+l!`!a+r!a!b+}!c!},b!}#O,s#P#Q,x#Q#R#{#R#S,b#T#o,b#o#p,}#p#q-S#q#r-[#r#s#{~#
|
|
34
|
-
tokenizers: [1, new lr.LocalTokenGroup("j~RQYZXz{^~^
|
|
31
|
+
tokenData: "-a~RqXY#YYZ#Y]^#Ypq#Yqr#krs$Quv#{vw%zwx&Sxy'wyz'|z{(R{|#{|}(Z}!O#{!O!P(`!P!Q(h!Q![(u![!]+[!^!_+a!_!`+l!`!a+r!a!b+}!c!},b!}#O,s#P#Q,x#Q#R#{#R#S,b#T#o,b#o#p,}#p#q-S#q#r-[#r#s#{~#_Sp~XY#YYZ#Y]^#Ypq#Y~#pPe~!_!`#s~#xPe~!_!`#{~$QOe~~$TXOr$Qrs$ps#O$Q#O#P$u#P;'S$Q;'S;=`%t<%l~$Q~O$Q~~$p~$uO^~~$xRO;'S$Q;'S;=`%R;=`O$Q~%UYOr$Qrs$ps#O$Q#O#P$u#P;'S$Q;'S;=`%t;=`<%l$Q<%l~$Q~O$Q~~$p~%wP;=`<%l$Q~&PPe~vw#{~&VXOw&Swx$px#O&S#O#P&r#P;'S&S;'S;=`'q<%l~&S~O&S~~$p~&uRO;'S&S;'S;=`'O;=`O&S~'RYOw&Swx$px#O&S#O#P&r#P;'S&S;'S;=`'q;=`<%l&S<%l~&S~O&S~~$p~'tP;=`<%l&S~'|Oz~~(ROy~~(WPe~z{#{~(`O|~~(ePS~!O!P#{~(mPe~z{(p~(uOq~~(zT]~!O!P)Z!Q![(u!g!h*Z#R#S+U#X#Y*Z~)^SO!O)j!P;'S)j;'S;=`+O<%lO)j~)oR]~!Q![)x!g!h*Z#X#Y*Z~)}S]~!Q![)x!g!h*Z#R#S*x#X#Y*Z~*^R{|*g}!O*g!Q![*m~*jP!Q![*m~*rQ]~!Q![*m#R#S*g~*{P!Q![)x~+RP;=`<%l)j~+XP!Q![(u~+aO!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.
|
|
79
|
+
if ((node.type.is(PropertyAccess) || node.type.is(MethodAccess)) && node.lastChild) {
|
|
62
80
|
const leftArgument = (_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.node;
|
|
63
81
|
const types = Array.from(resolveTypes(state, leftArgument, config));
|
|
64
82
|
identifier = state.sliceDoc(node.lastChild.from, node.lastChild.to);
|
|
65
83
|
return types.map(type => { var _a; return resolveCallable(identifier, (_a = config.types) === null || _a === void 0 ? void 0 : _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
90
|
const resolveCallable = (identifier, config) => { var _a; return (_a = config === null || config === void 0 ? void 0 : config.functions) === null || _a === void 0 ? void 0 : _a.find(x => x.name === identifier); };
|
|
73
|
-
const resolveIdentifier = (
|
|
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
|
|
97
|
+
case Property:
|
|
98
|
+
case Variable:
|
|
81
99
|
return (_a = config === null || config === void 0 ? void 0 : config.identifiers) === null || _a === void 0 ? void 0 : _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 === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _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 === void 0 ? void 0 : _c.returnType) === null || _d === void 0 ? void 0 : _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 === void 0 ? void 0 : _e.type.is(Property))) {
|
|
108
126
|
const varName = state.sliceDoc(node.lastChild.from, node.lastChild.to) || '';
|
|
109
127
|
(_f = resolveTypes(state, node.firstChild, config)) === null || _f === void 0 ? void 0 : _f.forEach(baseType => {
|
|
110
128
|
var _a, _b, _c, _d;
|
|
111
129
|
// @ts-ignore
|
|
112
|
-
(_d = (_c = resolveIdentifier((_a = node.lastChild) === null || _a === void 0 ? void 0 : _a.
|
|
130
|
+
(_d = (_c = resolveIdentifier((_a = node.lastChild) === null || _a === void 0 ? void 0 : _a.type.id, varName, (_b = config.types) === null || _b === void 0 ? void 0 : _b[baseType])) === null || _c === void 0 ? void 0 : _c.type) === null || _d === void 0 ? void 0 : _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 === void 0 ? void 0 : _g.type.is(Method))) {
|
|
116
134
|
const varName = state.sliceDoc(node.lastChild.from, node.lastChild.to) || '';
|
|
117
135
|
(_h = resolveTypes(state, node.firstChild, config)) === null || _h === void 0 ? void 0 : _h.forEach(baseType => {
|
|
118
136
|
var _a, _b, _c, _d;
|
|
119
137
|
// @ts-ignore
|
|
120
|
-
(_d = (_c = resolveIdentifier((_a = node.lastChild) === null || _a === void 0 ? void 0 : _a.
|
|
138
|
+
(_d = (_c = resolveIdentifier((_a = node.lastChild) === null || _a === void 0 ? void 0 : _a.type.id, varName, (_b = config.types) === null || _b === void 0 ? void 0 : _b[baseType])) === null || _c === void 0 ? void 0 : _c.returnType) === null || _d === void 0 ? void 0 : _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 === void 0 ? void 0 : _j.nextSibling) && ((_l = (_k = node.firstChild) === null || _k === void 0 ? void 0 : _k.nextSibling) === null || _l === void 0 ? void 0 : _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,11 +207,11 @@ 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;
|
|
@@ -194,49 +222,57 @@ const expressionLanguageLinterSource = (state) => {
|
|
|
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 === void 0 ? void 0 : fn.args;
|
|
202
231
|
if (!args) {
|
|
203
232
|
return;
|
|
204
233
|
}
|
|
205
|
-
|
|
206
|
-
|
|
234
|
+
const argCountMin = args.reduce((count, arg) => count + Number(!arg.optional), 0);
|
|
235
|
+
const argCountMax = args.length;
|
|
236
|
+
const argumentCountHintFn = () => `<code>${fn.name}</code> takes ${argCountMin == argCountMax ? `exactly ${argCountMax}` : `${argCountMin}–${argCountMax}`} argument${argCountMax == 1 ? '' : 's'}`;
|
|
237
|
+
let i = 0;
|
|
238
|
+
for (let n = node.node.firstChild; n != null; n = n.nextSibling) {
|
|
239
|
+
if (n.type.is(BlockComment)) {
|
|
207
240
|
continue;
|
|
208
241
|
}
|
|
209
|
-
if (i >
|
|
210
|
-
diagnostics.push({ from: n.from, to: n.to, severity: '
|
|
242
|
+
if (i > argCountMax - 1) {
|
|
243
|
+
diagnostics.push({ from: n.from, to: n.to, severity: 'warning', message: `Unexpected argument – ${argumentCountHintFn()}` });
|
|
211
244
|
continue;
|
|
212
245
|
}
|
|
213
246
|
const typesUsed = Array.from(resolveTypes(state, n, config));
|
|
214
247
|
const typesExpected = args[i].type;
|
|
215
|
-
if (typesExpected && !typesExpected.includes(ELScalar.Any) && !typesUsed.some(x => typesExpected.includes(x))) {
|
|
248
|
+
if (typesExpected && !typesExpected.includes(exports.ELScalar.Any) && !typesUsed.some(x => typesExpected.includes(x))) {
|
|
216
249
|
diagnostics.push({ from: n.from, to: n.to, severity: 'error', message: `<code>${typesExpected.join('|')}</code> expected, got <code>${typesUsed.join('|')}</code>` });
|
|
217
250
|
}
|
|
218
251
|
i++;
|
|
219
252
|
}
|
|
253
|
+
if (i < argCountMin) {
|
|
254
|
+
diagnostics.push({ from: node.from, to: node.to, severity: 'error', message: `Too few arguments – ${argumentCountHintFn()}` });
|
|
255
|
+
}
|
|
220
256
|
break;
|
|
221
|
-
case
|
|
222
|
-
case
|
|
223
|
-
const leftArgument = (
|
|
257
|
+
case Property:
|
|
258
|
+
case Method:
|
|
259
|
+
const leftArgument = (_e = (_d = node.node.parent) === null || _d === void 0 ? void 0 : _d.firstChild) === null || _e === void 0 ? void 0 : _e.node;
|
|
224
260
|
const types = Array.from(resolveTypes(state, leftArgument, config));
|
|
225
261
|
identifier = state.sliceDoc(from, to);
|
|
226
|
-
if (!types.find(type => { var _a; return resolveIdentifier(
|
|
227
|
-
diagnostics.push({ from, to, severity: 'error', message: `${node.name}
|
|
262
|
+
if (!types.find(type => { var _a; return resolveIdentifier(id, identifier, (_a = config.types) === null || _a === void 0 ? void 0 : _a[type]); })) {
|
|
263
|
+
diagnostics.push({ from, to, severity: 'error', message: `${node.name} <code>${identifier}</code> not found in <code>${types.join('|')}</code>` });
|
|
228
264
|
}
|
|
229
265
|
break;
|
|
230
|
-
case
|
|
231
|
-
case
|
|
266
|
+
case Variable:
|
|
267
|
+
case Function:
|
|
232
268
|
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}
|
|
269
|
+
if (!resolveIdentifier(id, identifier, config)) {
|
|
270
|
+
diagnostics.push({ from, to, severity: 'error', message: `${node.node.name} <code>${identifier}</code> not found` });
|
|
235
271
|
}
|
|
236
272
|
break;
|
|
237
273
|
}
|
|
238
|
-
if (identifier && ((
|
|
239
|
-
diagnostics.push({ from, to, severity: 'error', message: `Unexpected identifier
|
|
274
|
+
if (identifier && ((_f = node.node.parent) === null || _f === void 0 ? void 0 : _f.type.isError)) {
|
|
275
|
+
diagnostics.push({ from, to, severity: 'error', message: `Unexpected identifier <code>${identifier}</code>` });
|
|
240
276
|
}
|
|
241
277
|
});
|
|
242
278
|
diagnostics.forEach(d => {
|
|
@@ -250,13 +286,19 @@ const expressionLanguageLinterSource = (state) => {
|
|
|
250
286
|
};
|
|
251
287
|
const expressionLanguageLinter = lint.linter(view => expressionLanguageLinterSource(view.state));
|
|
252
288
|
|
|
289
|
+
var linter = /*#__PURE__*/Object.freeze({
|
|
290
|
+
__proto__: null,
|
|
291
|
+
expressionLanguageLinter: expressionLanguageLinter,
|
|
292
|
+
expressionLanguageLinterSource: expressionLanguageLinterSource
|
|
293
|
+
});
|
|
294
|
+
|
|
253
295
|
const autocompleteFunction = (x) => {
|
|
254
296
|
var _a, _b, _c;
|
|
255
297
|
return ({
|
|
256
298
|
label: `${x.name}(${((_b = (_a = x.args) === null || _a === void 0 ? void 0 : _a.map(x => x.name)) === null || _b === void 0 ? void 0 : _b.join(',')) || ''})`,
|
|
257
299
|
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 === void 0 ? void 0 : _a.length) > 0 ? 1 : 2) } }));
|
|
300
|
+
var _a, _b;
|
|
301
|
+
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 === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0 ? 1 : 2) } }));
|
|
260
302
|
},
|
|
261
303
|
detail: (_c = x.returnType) === null || _c === void 0 ? void 0 : _c.join('|'),
|
|
262
304
|
info: x.info,
|
|
@@ -300,8 +342,8 @@ function completeIdentifier(state, config, tree, from, to) {
|
|
|
300
342
|
};
|
|
301
343
|
}
|
|
302
344
|
function completeMember(state, config, tree, from, to, explicit) {
|
|
303
|
-
var _a, _b, _c, _d;
|
|
304
|
-
if (((_a = tree.parent) === null || _a === void 0 ? void 0 : _a.
|
|
345
|
+
var _a, _b, _c, _d, _e, _f;
|
|
346
|
+
if (!(((_a = tree.parent) === null || _a === void 0 ? void 0 : _a.type.is(PropertyAccess)) || ((_b = tree.parent) === null || _b === void 0 ? void 0 : _b.type.is(MethodAccess))) || !((_c = tree.parent) === null || _c === void 0 ? void 0 : _c.firstChild)) {
|
|
305
347
|
return null;
|
|
306
348
|
}
|
|
307
349
|
const types = resolveTypes(state, tree.parent.firstChild.node, config);
|
|
@@ -310,8 +352,8 @@ function completeMember(state, config, tree, from, to, explicit) {
|
|
|
310
352
|
}
|
|
311
353
|
let options = [];
|
|
312
354
|
for (const type of types) {
|
|
313
|
-
const typeDeclaration = (
|
|
314
|
-
options.push(...(((
|
|
355
|
+
const typeDeclaration = (_d = config.types) === null || _d === void 0 ? void 0 : _d[type];
|
|
356
|
+
options.push(...(((_e = typeDeclaration === null || typeDeclaration === void 0 ? void 0 : typeDeclaration.identifiers) === null || _e === void 0 ? void 0 : _e.map(autocompleteIdentifier)) || []), ...(((_f = typeDeclaration === null || typeDeclaration === void 0 ? void 0 : typeDeclaration.functions) === null || _f === void 0 ? void 0 : _f.map(autocompleteFunction)) || []));
|
|
315
357
|
}
|
|
316
358
|
return {
|
|
317
359
|
from,
|
|
@@ -321,34 +363,39 @@ function completeMember(state, config, tree, from, to, explicit) {
|
|
|
321
363
|
};
|
|
322
364
|
}
|
|
323
365
|
function expressionLanguageCompletion(context) {
|
|
324
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k
|
|
366
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
325
367
|
const { state, pos, explicit } = context;
|
|
326
368
|
const tree = language.syntaxTree(state);
|
|
327
369
|
const lastChar = state.sliceDoc(pos - 1, pos);
|
|
328
370
|
const prevNode = tree.resolveInner(pos, lastChar === ')' ? 0 : -1);
|
|
329
371
|
const config = getExpressionLanguageConfig(state);
|
|
330
|
-
const isIdentifier = (node) =>
|
|
331
|
-
const isMember = (node) =>
|
|
332
|
-
if (prevNode.
|
|
372
|
+
const isIdentifier = (node) => (node === null || node === void 0 ? void 0 : node.type.is(Variable)) || (node === null || node === void 0 ? void 0 : node.type.is(Function));
|
|
373
|
+
const isMember = (node) => (node === null || node === void 0 ? void 0 : node.type.is(Property)) || (node === null || node === void 0 ? void 0 : node.type.is(Method));
|
|
374
|
+
if (prevNode.type.is(String) || prevNode.type.is(BlockComment)) {
|
|
333
375
|
return null;
|
|
334
376
|
}
|
|
335
|
-
if (((_a = prevNode.parent) === null || _a === void 0 ? void 0 : _a.
|
|
377
|
+
if ((((_a = prevNode.parent) === null || _a === void 0 ? void 0 : _a.type.is(PropertyAccess)) || ((_b = prevNode.parent) === null || _b === void 0 ? void 0 : _b.type.is(MethodAccess))) && [PropertyAccess, MethodAccess, ArrayAccess, Variable, Call, Application].includes((_c = prevNode.parent.firstChild) === null || _c === void 0 ? void 0 : _c.type.id)) {
|
|
336
378
|
return completeMember(state, config, prevNode, isIdentifier(prevNode) || isMember(prevNode) ? prevNode.from : pos, pos);
|
|
337
379
|
}
|
|
338
|
-
if ([
|
|
339
|
-
|| [
|
|
340
|
-
|| [
|
|
341
|
-
|| [
|
|
342
|
-
return completeOperatorKeyword(state, config, prevNode, ![
|
|
380
|
+
if (/^[\sa-z]*$/.test(lastChar) && ([Expression, UnaryExpression, BinaryExpression, TernaryExpression].includes(prevNode.type.id) && prevNode.lastChild && !((_d = prevNode.lastChild) === null || _d === void 0 ? void 0 : _d.type.isError)
|
|
381
|
+
|| [Arguments, Array$1].includes(prevNode.type.id) && prevNode.lastChild && !((_e = prevNode.lastChild) === null || _e === void 0 ? void 0 : _e.type.isError)
|
|
382
|
+
|| [Expression, UnaryExpression, BinaryExpression, TernaryExpression].includes((_f = prevNode.parent) === null || _f === void 0 ? void 0 : _f.type.id) && prevNode.type.isError
|
|
383
|
+
|| [Variable, Function].includes((_g = prevNode.parent) === null || _g === void 0 ? void 0 : _g.type.id) && prevNode.type.isError)) {
|
|
384
|
+
return completeOperatorKeyword(state, config, prevNode, ![Expression, UnaryExpression, BinaryExpression, TernaryExpression, Arguments].includes(prevNode.type.id) ? prevNode.from : pos, pos, explicit);
|
|
343
385
|
}
|
|
344
|
-
if (!/[0-9]/.test(lastChar) && !
|
|
345
|
-
|| [
|
|
346
|
-
||
|
|
386
|
+
if (!/[0-9]/.test(lastChar) && !prevNode.type.is(OperatorKeyword) && ([Expression, UnaryExpression, BinaryExpression, TernaryExpression].includes(prevNode.type.id) && ((_h = prevNode.lastChild) === null || _h === void 0 ? void 0 : _h.type.isError)
|
|
387
|
+
|| [Expression, UnaryExpression, BinaryExpression, TernaryExpression, Arguments].includes((_k = (_j = prevNode.parent) === null || _j === void 0 ? void 0 : _j.type.id) !== null && _k !== void 0 ? _k : -1) && !prevNode.type.isError
|
|
388
|
+
|| prevNode.type.is(Arguments) || prevNode.type.is(Array$1))) {
|
|
347
389
|
return completeIdentifier(state, config, prevNode, isIdentifier(prevNode) ? prevNode.from : pos, pos);
|
|
348
390
|
}
|
|
349
391
|
return null;
|
|
350
392
|
}
|
|
351
393
|
|
|
394
|
+
var complete = /*#__PURE__*/Object.freeze({
|
|
395
|
+
__proto__: null,
|
|
396
|
+
expressionLanguageCompletion: expressionLanguageCompletion
|
|
397
|
+
});
|
|
398
|
+
|
|
352
399
|
function getNodeOrdinal(node) {
|
|
353
400
|
let ordinal = -1;
|
|
354
401
|
// noinspection StatementWithEmptyBodyJS
|
|
@@ -358,7 +405,7 @@ function getNodeOrdinal(node) {
|
|
|
358
405
|
}
|
|
359
406
|
function resolveArguments(node) {
|
|
360
407
|
let c = node;
|
|
361
|
-
while (c && c.
|
|
408
|
+
while (c && !c.type.is(Arguments)) {
|
|
362
409
|
c = c.parent;
|
|
363
410
|
}
|
|
364
411
|
return c;
|
|
@@ -410,10 +457,10 @@ const cursorTooltipField = state.StateField.define({
|
|
|
410
457
|
provide: f => view.showTooltip.computeN([f], state => state.field(f))
|
|
411
458
|
});
|
|
412
459
|
const keywordTooltip = view.hoverTooltip((view, pos, side) => {
|
|
413
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
460
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
414
461
|
const config = getExpressionLanguageConfig(view.state);
|
|
415
462
|
const tree = language.syntaxTree(view.state).resolveInner(pos, side);
|
|
416
|
-
if (tree.
|
|
463
|
+
if (tree.type.is(OperatorKeyword)) {
|
|
417
464
|
const name = view.state.sliceDoc(tree.from, tree.to);
|
|
418
465
|
const info = (_a = keywords.find(x => x.name === name)) === null || _a === void 0 ? void 0 : _a.info;
|
|
419
466
|
if (info) {
|
|
@@ -425,12 +472,12 @@ const keywordTooltip = view.hoverTooltip((view, pos, side) => {
|
|
|
425
472
|
};
|
|
426
473
|
}
|
|
427
474
|
}
|
|
428
|
-
if (![
|
|
475
|
+
if (![Function, Variable, Method, Property].includes(tree.type.id)) {
|
|
429
476
|
return null;
|
|
430
477
|
}
|
|
431
478
|
const skipEmpty = (x) => x;
|
|
432
479
|
let info;
|
|
433
|
-
if (((_b = tree.parent) === null || _b === void 0 ? void 0 : _b.firstChild) && ((_c = tree.parent) === null || _c === void 0 ? void 0 : _c.
|
|
480
|
+
if (((_b = tree.parent) === null || _b === void 0 ? void 0 : _b.firstChild) && (((_c = tree.parent) === null || _c === void 0 ? void 0 : _c.type.is(PropertyAccess)) || ((_d = tree.parent) === null || _d === void 0 ? void 0 : _d.type.is(MethodAccess))) && tree.prevSibling) {
|
|
434
481
|
const node = tree.parent.firstChild;
|
|
435
482
|
const types = Array.from(resolveTypes(view.state, node, config));
|
|
436
483
|
const name = view.state.sliceDoc(tree.from, tree.to);
|
|
@@ -442,8 +489,8 @@ const keywordTooltip = view.hoverTooltip((view, pos, side) => {
|
|
|
442
489
|
else {
|
|
443
490
|
const name = view.state.sliceDoc(tree.from, tree.to);
|
|
444
491
|
info = [
|
|
445
|
-
...[(
|
|
446
|
-
...[(
|
|
492
|
+
...[(_f = (_e = config.identifiers) === null || _e === void 0 ? void 0 : _e.find(x => x.name === name)) === null || _f === void 0 ? void 0 : _f.info].filter(skipEmpty),
|
|
493
|
+
...[(_h = (_g = config.functions) === null || _g === void 0 ? void 0 : _g.find(x => x.name === name)) === null || _h === void 0 ? void 0 : _h.info].filter(skipEmpty),
|
|
447
494
|
].join('\n');
|
|
448
495
|
}
|
|
449
496
|
if (!info) {
|
|
@@ -457,6 +504,12 @@ const keywordTooltip = view.hoverTooltip((view, pos, side) => {
|
|
|
457
504
|
};
|
|
458
505
|
});
|
|
459
506
|
|
|
507
|
+
var tooltip = /*#__PURE__*/Object.freeze({
|
|
508
|
+
__proto__: null,
|
|
509
|
+
cursorTooltipField: cursorTooltipField,
|
|
510
|
+
keywordTooltip: keywordTooltip
|
|
511
|
+
});
|
|
512
|
+
|
|
460
513
|
const baseTheme = view.EditorView.baseTheme({
|
|
461
514
|
".cm-tooltip.cm-tooltip-cursor": {
|
|
462
515
|
boxShadow: 'rgba(0, 0, 0, .15) 0 1px 2px',
|
|
@@ -538,4 +591,8 @@ function expressionlanguage(config = {}, extensions = []) {
|
|
|
538
591
|
}
|
|
539
592
|
|
|
540
593
|
exports.ELLanguage = ELLanguage;
|
|
594
|
+
exports._complete = complete;
|
|
595
|
+
exports._linter = linter;
|
|
596
|
+
exports._tooltip = tooltip;
|
|
597
|
+
exports._utils = utils;
|
|
541
598
|
exports.expressionlanguage = expressionlanguage;
|