@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/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LRParser, LocalTokenGroup } from '@lezer/lr';
|
|
2
|
-
import { syntaxTree, LRLanguage, indentNodeProp,
|
|
2
|
+
import { syntaxTree, LRLanguage, indentNodeProp, foldNodeProp, delimitedIndent, LanguageSupport } from '@codemirror/language';
|
|
3
3
|
import { styleTags, tags } from '@lezer/highlight';
|
|
4
|
-
import { linter } from '@codemirror/lint';
|
|
4
|
+
import { linter as linter$1 } from '@codemirror/lint';
|
|
5
5
|
import { insertCompletionText } from '@codemirror/autocomplete';
|
|
6
6
|
import { StateField } from '@codemirror/state';
|
|
7
7
|
import { showTooltip, hoverTooltip, EditorView } from '@codemirror/view';
|
|
@@ -12,35 +12,54 @@ const t = {
|
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
15
|
-
const spec_word = {__proto__:null,true:
|
|
16
|
-
const spec_Operator = {__proto__:null,"?":
|
|
17
|
-
const parser = LRParser.deserialize({
|
|
15
|
+
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};
|
|
16
|
+
const spec_Operator = {__proto__:null,"?":109, "!":131, "~":133, "+":135, "-":137};
|
|
17
|
+
const parser = /*@__PURE__*/LRParser.deserialize({
|
|
18
18
|
version: 14,
|
|
19
|
-
states: ")
|
|
20
|
-
stateData: "
|
|
21
|
-
goto: "%
|
|
22
|
-
nodeNames: "⚠ BlockComment Expression
|
|
23
|
-
maxTerm:
|
|
19
|
+
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",
|
|
20
|
+
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~",
|
|
21
|
+
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",
|
|
22
|
+
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",
|
|
23
|
+
maxTerm: 68,
|
|
24
24
|
nodeProps: [
|
|
25
|
-
[t,
|
|
25
|
+
[t, 13,"number",14,"string",15,"bool",16,"null",17,"object",18,"array"]
|
|
26
26
|
],
|
|
27
|
-
skippedNodes: [0,1,
|
|
27
|
+
skippedNodes: [0,1,27],
|
|
28
28
|
repeatNodeCount: 3,
|
|
29
|
-
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#{~#
|
|
30
|
-
tokenizers: [1, new LocalTokenGroup("j~RQYZXz{^~^
|
|
29
|
+
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~",
|
|
30
|
+
tokenizers: [1, /*@__PURE__*/new LocalTokenGroup("j~RQYZXz{^~^Os~~aP!P!Qd~iOt~~", 25, 34)],
|
|
31
31
|
topRules: {"Expression":[0,2]},
|
|
32
|
-
specialized: [{term:
|
|
33
|
-
tokenPrec:
|
|
32
|
+
specialized: [{term: 38, get: (value) => spec_word[value] || -1},{term: 21, get: (value) => spec_Operator[value] || -1}],
|
|
33
|
+
tokenPrec: 532
|
|
34
34
|
});
|
|
35
35
|
|
|
36
|
-
var ELScalar
|
|
37
|
-
(function (ELScalar) {
|
|
36
|
+
var ELScalar = /*@__PURE__*/(function (ELScalar) {
|
|
38
37
|
ELScalar["Bool"] = "bool";
|
|
39
38
|
ELScalar["Number"] = "number";
|
|
40
39
|
ELScalar["String"] = "string";
|
|
41
40
|
ELScalar["Null"] = "null";
|
|
42
41
|
ELScalar["Any"] = "any";
|
|
43
|
-
})(ELScalar || (ELScalar = {}));
|
|
42
|
+
return ELScalar})(ELScalar || (ELScalar = {}));
|
|
43
|
+
|
|
44
|
+
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
45
|
+
const BlockComment = 1,
|
|
46
|
+
Expression = 2,
|
|
47
|
+
PropertyAccess = 3,
|
|
48
|
+
Property = 6,
|
|
49
|
+
ArrayAccess = 7,
|
|
50
|
+
Call = 8,
|
|
51
|
+
Function = 9,
|
|
52
|
+
Arguments = 10,
|
|
53
|
+
MethodAccess = 11,
|
|
54
|
+
Method = 12,
|
|
55
|
+
String = 14,
|
|
56
|
+
Array$1 = 18,
|
|
57
|
+
Variable = 19,
|
|
58
|
+
TernaryExpression = 20,
|
|
59
|
+
BinaryExpression = 22,
|
|
60
|
+
OperatorKeyword = 23,
|
|
61
|
+
UnaryExpression = 24,
|
|
62
|
+
Application = 26;
|
|
44
63
|
|
|
45
64
|
const createInfoElement = (html) => {
|
|
46
65
|
const dom = document.createElement("div");
|
|
@@ -54,30 +73,30 @@ function resolveFunctionDefinition(node, state, config) {
|
|
|
54
73
|
return undefined;
|
|
55
74
|
}
|
|
56
75
|
let identifier;
|
|
57
|
-
if (node.
|
|
76
|
+
if ((node.type.is(PropertyAccess) || node.type.is(MethodAccess)) && node.lastChild) {
|
|
58
77
|
const leftArgument = (_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.node;
|
|
59
78
|
const types = Array.from(resolveTypes(state, leftArgument, config));
|
|
60
79
|
identifier = state.sliceDoc(node.lastChild.from, node.lastChild.to);
|
|
61
80
|
return types.map(type => { var _a; return resolveCallable(identifier, (_a = config.types) === null || _a === void 0 ? void 0 : _a[type]); }).find(x => x);
|
|
62
81
|
}
|
|
63
|
-
else if (node.
|
|
82
|
+
else if (node.type.is(Function)) {
|
|
64
83
|
identifier = state.sliceDoc(node.from, node.node.firstChild ? node.node.firstChild.from - 1 : node.to);
|
|
65
84
|
return resolveCallable(identifier, config);
|
|
66
85
|
}
|
|
67
86
|
}
|
|
68
87
|
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); };
|
|
69
|
-
const resolveIdentifier = (
|
|
88
|
+
const resolveIdentifier = (nodeTypeId, identifier, config) => {
|
|
70
89
|
var _a;
|
|
71
|
-
switch (
|
|
72
|
-
case
|
|
73
|
-
case
|
|
90
|
+
switch (nodeTypeId) {
|
|
91
|
+
case Method:
|
|
92
|
+
case Function:
|
|
74
93
|
return resolveCallable(identifier, config);
|
|
75
|
-
case
|
|
76
|
-
case
|
|
94
|
+
case Property:
|
|
95
|
+
case Variable:
|
|
77
96
|
return (_a = config === null || config === void 0 ? void 0 : config.identifiers) === null || _a === void 0 ? void 0 : _a.find(x => x.name === identifier);
|
|
78
97
|
}
|
|
79
98
|
};
|
|
80
|
-
function resolveTypes(state, node, config
|
|
99
|
+
function resolveTypes(state, node, config) {
|
|
81
100
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
82
101
|
let types = new Set();
|
|
83
102
|
if (!node) {
|
|
@@ -87,43 +106,43 @@ function resolveTypes(state, node, config, matchExact) {
|
|
|
87
106
|
if (typeof (type = node.type.prop(t)) !== "undefined") {
|
|
88
107
|
types.add(type);
|
|
89
108
|
}
|
|
90
|
-
else if (node.
|
|
109
|
+
else if (node.type.is(Call) && node.firstChild && node.lastChild) {
|
|
91
110
|
resolveTypes(state, node.firstChild, config).forEach(x => types.add(x));
|
|
92
111
|
}
|
|
93
|
-
else if (node.
|
|
112
|
+
else if (node.type.is(Variable)) {
|
|
94
113
|
const varName = state.sliceDoc(node.from, node.to) || '';
|
|
95
114
|
// @ts-ignore
|
|
96
|
-
(_b = (_a = resolveIdentifier(node.
|
|
115
|
+
(_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));
|
|
97
116
|
}
|
|
98
|
-
else if (node.
|
|
117
|
+
else if (node.type.is(Function)) {
|
|
99
118
|
const varName = state.sliceDoc(node.from, node.to) || '';
|
|
100
119
|
// @ts-ignore
|
|
101
|
-
(_d = (_c = resolveIdentifier(node.
|
|
120
|
+
(_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));
|
|
102
121
|
}
|
|
103
|
-
else if (node.
|
|
122
|
+
else if (node.type.is(PropertyAccess) && node.firstChild && ((_e = node.lastChild) === null || _e === void 0 ? void 0 : _e.type.is(Property))) {
|
|
104
123
|
const varName = state.sliceDoc(node.lastChild.from, node.lastChild.to) || '';
|
|
105
124
|
(_f = resolveTypes(state, node.firstChild, config)) === null || _f === void 0 ? void 0 : _f.forEach(baseType => {
|
|
106
125
|
var _a, _b, _c, _d;
|
|
107
126
|
// @ts-ignore
|
|
108
|
-
(_d = (_c = resolveIdentifier((_a = node.lastChild) === null || _a === void 0 ? void 0 : _a.
|
|
127
|
+
(_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));
|
|
109
128
|
});
|
|
110
129
|
}
|
|
111
|
-
else if (node.
|
|
130
|
+
else if (node.type.is(MethodAccess) && node.firstChild && ((_g = node.lastChild) === null || _g === void 0 ? void 0 : _g.type.is(Method))) {
|
|
112
131
|
const varName = state.sliceDoc(node.lastChild.from, node.lastChild.to) || '';
|
|
113
132
|
(_h = resolveTypes(state, node.firstChild, config)) === null || _h === void 0 ? void 0 : _h.forEach(baseType => {
|
|
114
133
|
var _a, _b, _c, _d;
|
|
115
134
|
// @ts-ignore
|
|
116
|
-
(_d = (_c = resolveIdentifier((_a = node.lastChild) === null || _a === void 0 ? void 0 : _a.
|
|
135
|
+
(_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));
|
|
117
136
|
});
|
|
118
137
|
}
|
|
119
|
-
else if (node.
|
|
138
|
+
else if (node.type.is(Application) && node.firstChild) {
|
|
120
139
|
resolveTypes(state, node.firstChild, config).forEach(x => types.add(x));
|
|
121
140
|
}
|
|
122
|
-
else if (node.
|
|
141
|
+
else if (node.type.is(TernaryExpression) && node.firstChild && node.firstChild.nextSibling && node.firstChild.nextSibling.nextSibling) {
|
|
123
142
|
resolveTypes(state, node.firstChild.nextSibling, config).forEach(x => types.add(x));
|
|
124
143
|
resolveTypes(state, node.firstChild.nextSibling.nextSibling, config).forEach(x => types.add(x));
|
|
125
144
|
}
|
|
126
|
-
else if (node.
|
|
145
|
+
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)) {
|
|
127
146
|
const operator = state.sliceDoc(node.firstChild.nextSibling.from, node.firstChild.nextSibling.to);
|
|
128
147
|
if (operator == '?:' || operator == '??' || operator == '?') {
|
|
129
148
|
if (operator == '?:' || operator == '??') {
|
|
@@ -138,7 +157,7 @@ function resolveTypes(state, node, config, matchExact) {
|
|
|
138
157
|
types.add(ELScalar.Number);
|
|
139
158
|
}
|
|
140
159
|
}
|
|
141
|
-
else if (node.
|
|
160
|
+
else if (node.type.is(UnaryExpression) && node.firstChild) {
|
|
142
161
|
const operator = state.sliceDoc(node.firstChild.from, node.firstChild.to);
|
|
143
162
|
if (['not', '!'].includes(operator)) {
|
|
144
163
|
types.add(ELScalar.Bool);
|
|
@@ -168,6 +187,16 @@ const keywords = [
|
|
|
168
187
|
{ name: 'xor' },
|
|
169
188
|
];
|
|
170
189
|
|
|
190
|
+
var utils = /*#__PURE__*//*@__PURE__*/Object.freeze({
|
|
191
|
+
__proto__: null,
|
|
192
|
+
createInfoElement: createInfoElement,
|
|
193
|
+
getExpressionLanguageConfig: getExpressionLanguageConfig,
|
|
194
|
+
keywords: keywords,
|
|
195
|
+
resolveFunctionDefinition: resolveFunctionDefinition,
|
|
196
|
+
resolveIdentifier: resolveIdentifier,
|
|
197
|
+
resolveTypes: resolveTypes
|
|
198
|
+
});
|
|
199
|
+
|
|
171
200
|
/**
|
|
172
201
|
* @internal
|
|
173
202
|
*/
|
|
@@ -175,11 +204,11 @@ const expressionLanguageLinterSource = (state) => {
|
|
|
175
204
|
const config = getExpressionLanguageConfig(state);
|
|
176
205
|
let diagnostics = [];
|
|
177
206
|
syntaxTree(state).cursor().iterate(node => {
|
|
178
|
-
var _a, _b, _c, _d, _e, _f
|
|
179
|
-
const { from, to,
|
|
207
|
+
var _a, _b, _c, _d, _e, _f;
|
|
208
|
+
const { from, to, type: { id } } = node;
|
|
180
209
|
let identifier;
|
|
181
|
-
switch (
|
|
182
|
-
case
|
|
210
|
+
switch (id) {
|
|
211
|
+
case 0:
|
|
183
212
|
if (state.doc.length === 0 || from === 0) {
|
|
184
213
|
// Don't show error on empty doc (even though it is an error)
|
|
185
214
|
return;
|
|
@@ -190,20 +219,25 @@ const expressionLanguageLinterSource = (state) => {
|
|
|
190
219
|
}
|
|
191
220
|
else {
|
|
192
221
|
const type = /^[a-zA-Z_]+[a-zA-Z_0-9]*$/.test(identifier) ? 'identifier' : 'operator';
|
|
193
|
-
diagnostics.push({ from, to, severity: 'error', message: `Unexpected ${type}
|
|
222
|
+
diagnostics.push({ from, to, severity: 'error', message: `Unexpected ${type} <code>${identifier}</code>` });
|
|
194
223
|
}
|
|
195
224
|
return;
|
|
196
|
-
case
|
|
197
|
-
const
|
|
225
|
+
case Arguments:
|
|
226
|
+
const fn = resolveFunctionDefinition(node.node.prevSibling, state, config);
|
|
227
|
+
const args = fn === null || fn === void 0 ? void 0 : fn.args;
|
|
198
228
|
if (!args) {
|
|
199
229
|
return;
|
|
200
230
|
}
|
|
201
|
-
|
|
202
|
-
|
|
231
|
+
const argCountMin = args.reduce((count, arg) => count + Number(!arg.optional), 0);
|
|
232
|
+
const argCountMax = args.length;
|
|
233
|
+
const argumentCountHintFn = () => `<code>${fn.name}</code> takes ${argCountMin == argCountMax ? `exactly ${argCountMax}` : `${argCountMin}–${argCountMax}`} argument${argCountMax == 1 ? '' : 's'}`;
|
|
234
|
+
let i = 0;
|
|
235
|
+
for (let n = node.node.firstChild; n != null; n = n.nextSibling) {
|
|
236
|
+
if (n.type.is(BlockComment)) {
|
|
203
237
|
continue;
|
|
204
238
|
}
|
|
205
|
-
if (i >
|
|
206
|
-
diagnostics.push({ from: n.from, to: n.to, severity: '
|
|
239
|
+
if (i > argCountMax - 1) {
|
|
240
|
+
diagnostics.push({ from: n.from, to: n.to, severity: 'warning', message: `Unexpected argument – ${argumentCountHintFn()}` });
|
|
207
241
|
continue;
|
|
208
242
|
}
|
|
209
243
|
const typesUsed = Array.from(resolveTypes(state, n, config));
|
|
@@ -213,26 +247,29 @@ const expressionLanguageLinterSource = (state) => {
|
|
|
213
247
|
}
|
|
214
248
|
i++;
|
|
215
249
|
}
|
|
250
|
+
if (i < argCountMin) {
|
|
251
|
+
diagnostics.push({ from: node.from, to: node.to, severity: 'error', message: `Too few arguments – ${argumentCountHintFn()}` });
|
|
252
|
+
}
|
|
216
253
|
break;
|
|
217
|
-
case
|
|
218
|
-
case
|
|
219
|
-
const leftArgument = (
|
|
254
|
+
case Property:
|
|
255
|
+
case Method:
|
|
256
|
+
const leftArgument = (_e = (_d = node.node.parent) === null || _d === void 0 ? void 0 : _d.firstChild) === null || _e === void 0 ? void 0 : _e.node;
|
|
220
257
|
const types = Array.from(resolveTypes(state, leftArgument, config));
|
|
221
258
|
identifier = state.sliceDoc(from, to);
|
|
222
|
-
if (!types.find(type => { var _a; return resolveIdentifier(
|
|
223
|
-
diagnostics.push({ from, to, severity: 'error', message: `${node.name}
|
|
259
|
+
if (!types.find(type => { var _a; return resolveIdentifier(id, identifier, (_a = config.types) === null || _a === void 0 ? void 0 : _a[type]); })) {
|
|
260
|
+
diagnostics.push({ from, to, severity: 'error', message: `${node.name} <code>${identifier}</code> not found in <code>${types.join('|')}</code>` });
|
|
224
261
|
}
|
|
225
262
|
break;
|
|
226
|
-
case
|
|
227
|
-
case
|
|
263
|
+
case Variable:
|
|
264
|
+
case Function:
|
|
228
265
|
identifier = state.sliceDoc(from, node.node.firstChild ? node.node.firstChild.from - 1 : to);
|
|
229
|
-
if (!resolveIdentifier(
|
|
230
|
-
diagnostics.push({ from, to, severity: 'error', message: `${node.node.name}
|
|
266
|
+
if (!resolveIdentifier(id, identifier, config)) {
|
|
267
|
+
diagnostics.push({ from, to, severity: 'error', message: `${node.node.name} <code>${identifier}</code> not found` });
|
|
231
268
|
}
|
|
232
269
|
break;
|
|
233
270
|
}
|
|
234
|
-
if (identifier && ((
|
|
235
|
-
diagnostics.push({ from, to, severity: 'error', message: `Unexpected identifier
|
|
271
|
+
if (identifier && ((_f = node.node.parent) === null || _f === void 0 ? void 0 : _f.type.isError)) {
|
|
272
|
+
diagnostics.push({ from, to, severity: 'error', message: `Unexpected identifier <code>${identifier}</code>` });
|
|
236
273
|
}
|
|
237
274
|
});
|
|
238
275
|
diagnostics.forEach(d => {
|
|
@@ -244,15 +281,21 @@ const expressionLanguageLinterSource = (state) => {
|
|
|
244
281
|
});
|
|
245
282
|
return diagnostics;
|
|
246
283
|
};
|
|
247
|
-
const expressionLanguageLinter = linter(view => expressionLanguageLinterSource(view.state));
|
|
284
|
+
const expressionLanguageLinter = /*@__PURE__*/linter$1(view => expressionLanguageLinterSource(view.state));
|
|
285
|
+
|
|
286
|
+
var linter = /*#__PURE__*//*@__PURE__*/Object.freeze({
|
|
287
|
+
__proto__: null,
|
|
288
|
+
expressionLanguageLinter: expressionLanguageLinter,
|
|
289
|
+
expressionLanguageLinterSource: expressionLanguageLinterSource
|
|
290
|
+
});
|
|
248
291
|
|
|
249
292
|
const autocompleteFunction = (x) => {
|
|
250
293
|
var _a, _b, _c;
|
|
251
294
|
return ({
|
|
252
295
|
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(',')) || ''})`,
|
|
253
296
|
apply: (view, completion, from, to) => {
|
|
254
|
-
var _a;
|
|
255
|
-
view.dispatch(Object.assign(Object.assign({}, 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) } }));
|
|
297
|
+
var _a, _b;
|
|
298
|
+
view.dispatch(Object.assign(Object.assign({}, 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) } }));
|
|
256
299
|
},
|
|
257
300
|
detail: (_c = x.returnType) === null || _c === void 0 ? void 0 : _c.join('|'),
|
|
258
301
|
info: x.info,
|
|
@@ -296,8 +339,8 @@ function completeIdentifier(state, config, tree, from, to) {
|
|
|
296
339
|
};
|
|
297
340
|
}
|
|
298
341
|
function completeMember(state, config, tree, from, to, explicit) {
|
|
299
|
-
var _a, _b, _c, _d;
|
|
300
|
-
if (((_a = tree.parent) === null || _a === void 0 ? void 0 : _a.
|
|
342
|
+
var _a, _b, _c, _d, _e, _f;
|
|
343
|
+
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)) {
|
|
301
344
|
return null;
|
|
302
345
|
}
|
|
303
346
|
const types = resolveTypes(state, tree.parent.firstChild.node, config);
|
|
@@ -306,8 +349,8 @@ function completeMember(state, config, tree, from, to, explicit) {
|
|
|
306
349
|
}
|
|
307
350
|
let options = [];
|
|
308
351
|
for (const type of types) {
|
|
309
|
-
const typeDeclaration = (
|
|
310
|
-
options.push(...(((
|
|
352
|
+
const typeDeclaration = (_d = config.types) === null || _d === void 0 ? void 0 : _d[type];
|
|
353
|
+
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)) || []));
|
|
311
354
|
}
|
|
312
355
|
return {
|
|
313
356
|
from,
|
|
@@ -317,34 +360,39 @@ function completeMember(state, config, tree, from, to, explicit) {
|
|
|
317
360
|
};
|
|
318
361
|
}
|
|
319
362
|
function expressionLanguageCompletion(context) {
|
|
320
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k
|
|
363
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
321
364
|
const { state, pos, explicit } = context;
|
|
322
365
|
const tree = syntaxTree(state);
|
|
323
366
|
const lastChar = state.sliceDoc(pos - 1, pos);
|
|
324
367
|
const prevNode = tree.resolveInner(pos, lastChar === ')' ? 0 : -1);
|
|
325
368
|
const config = getExpressionLanguageConfig(state);
|
|
326
|
-
const isIdentifier = (node) =>
|
|
327
|
-
const isMember = (node) =>
|
|
328
|
-
if (prevNode.
|
|
369
|
+
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));
|
|
370
|
+
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));
|
|
371
|
+
if (prevNode.type.is(String) || prevNode.type.is(BlockComment)) {
|
|
329
372
|
return null;
|
|
330
373
|
}
|
|
331
|
-
if (((_a = prevNode.parent) === null || _a === void 0 ? void 0 : _a.
|
|
374
|
+
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)) {
|
|
332
375
|
return completeMember(state, config, prevNode, isIdentifier(prevNode) || isMember(prevNode) ? prevNode.from : pos, pos);
|
|
333
376
|
}
|
|
334
|
-
if ([
|
|
335
|
-
|| [
|
|
336
|
-
|| [
|
|
337
|
-
|| [
|
|
338
|
-
return completeOperatorKeyword(state, config, prevNode, ![
|
|
377
|
+
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)
|
|
378
|
+
|| [Arguments, Array$1].includes(prevNode.type.id) && prevNode.lastChild && !((_e = prevNode.lastChild) === null || _e === void 0 ? void 0 : _e.type.isError)
|
|
379
|
+
|| [Expression, UnaryExpression, BinaryExpression, TernaryExpression].includes((_f = prevNode.parent) === null || _f === void 0 ? void 0 : _f.type.id) && prevNode.type.isError
|
|
380
|
+
|| [Variable, Function].includes((_g = prevNode.parent) === null || _g === void 0 ? void 0 : _g.type.id) && prevNode.type.isError)) {
|
|
381
|
+
return completeOperatorKeyword(state, config, prevNode, ![Expression, UnaryExpression, BinaryExpression, TernaryExpression, Arguments].includes(prevNode.type.id) ? prevNode.from : pos, pos, explicit);
|
|
339
382
|
}
|
|
340
|
-
if (!/[0-9]/.test(lastChar) && !
|
|
341
|
-
|| [
|
|
342
|
-
||
|
|
383
|
+
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)
|
|
384
|
+
|| [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
|
|
385
|
+
|| prevNode.type.is(Arguments) || prevNode.type.is(Array$1))) {
|
|
343
386
|
return completeIdentifier(state, config, prevNode, isIdentifier(prevNode) ? prevNode.from : pos, pos);
|
|
344
387
|
}
|
|
345
388
|
return null;
|
|
346
389
|
}
|
|
347
390
|
|
|
391
|
+
var complete = /*#__PURE__*//*@__PURE__*/Object.freeze({
|
|
392
|
+
__proto__: null,
|
|
393
|
+
expressionLanguageCompletion: expressionLanguageCompletion
|
|
394
|
+
});
|
|
395
|
+
|
|
348
396
|
function getNodeOrdinal(node) {
|
|
349
397
|
let ordinal = -1;
|
|
350
398
|
// noinspection StatementWithEmptyBodyJS
|
|
@@ -354,7 +402,7 @@ function getNodeOrdinal(node) {
|
|
|
354
402
|
}
|
|
355
403
|
function resolveArguments(node) {
|
|
356
404
|
let c = node;
|
|
357
|
-
while (c && c.
|
|
405
|
+
while (c && !c.type.is(Arguments)) {
|
|
358
406
|
c = c.parent;
|
|
359
407
|
}
|
|
360
408
|
return c;
|
|
@@ -395,7 +443,7 @@ function getCursorTooltips(state) {
|
|
|
395
443
|
};
|
|
396
444
|
}).filter(x => x);
|
|
397
445
|
}
|
|
398
|
-
const cursorTooltipField = StateField.define({
|
|
446
|
+
const cursorTooltipField = /*@__PURE__*/StateField.define({
|
|
399
447
|
create: (state) => getCursorTooltips(state),
|
|
400
448
|
update(tooltips, tr) {
|
|
401
449
|
if (!tr.docChanged && !tr.selection) {
|
|
@@ -405,11 +453,11 @@ const cursorTooltipField = StateField.define({
|
|
|
405
453
|
},
|
|
406
454
|
provide: f => showTooltip.computeN([f], state => state.field(f))
|
|
407
455
|
});
|
|
408
|
-
const keywordTooltip = hoverTooltip((view, pos, side) => {
|
|
409
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
456
|
+
const keywordTooltip = /*@__PURE__*/hoverTooltip((view, pos, side) => {
|
|
457
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
410
458
|
const config = getExpressionLanguageConfig(view.state);
|
|
411
459
|
const tree = syntaxTree(view.state).resolveInner(pos, side);
|
|
412
|
-
if (tree.
|
|
460
|
+
if (tree.type.is(OperatorKeyword)) {
|
|
413
461
|
const name = view.state.sliceDoc(tree.from, tree.to);
|
|
414
462
|
const info = (_a = keywords.find(x => x.name === name)) === null || _a === void 0 ? void 0 : _a.info;
|
|
415
463
|
if (info) {
|
|
@@ -421,12 +469,12 @@ const keywordTooltip = hoverTooltip((view, pos, side) => {
|
|
|
421
469
|
};
|
|
422
470
|
}
|
|
423
471
|
}
|
|
424
|
-
if (![
|
|
472
|
+
if (![Function, Variable, Method, Property].includes(tree.type.id)) {
|
|
425
473
|
return null;
|
|
426
474
|
}
|
|
427
475
|
const skipEmpty = (x) => x;
|
|
428
476
|
let info;
|
|
429
|
-
if (((_b = tree.parent) === null || _b === void 0 ? void 0 : _b.firstChild) && ((_c = tree.parent) === null || _c === void 0 ? void 0 : _c.
|
|
477
|
+
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) {
|
|
430
478
|
const node = tree.parent.firstChild;
|
|
431
479
|
const types = Array.from(resolveTypes(view.state, node, config));
|
|
432
480
|
const name = view.state.sliceDoc(tree.from, tree.to);
|
|
@@ -438,8 +486,8 @@ const keywordTooltip = hoverTooltip((view, pos, side) => {
|
|
|
438
486
|
else {
|
|
439
487
|
const name = view.state.sliceDoc(tree.from, tree.to);
|
|
440
488
|
info = [
|
|
441
|
-
...[(
|
|
442
|
-
...[(
|
|
489
|
+
...[(_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),
|
|
490
|
+
...[(_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),
|
|
443
491
|
].join('\n');
|
|
444
492
|
}
|
|
445
493
|
if (!info) {
|
|
@@ -453,7 +501,13 @@ const keywordTooltip = hoverTooltip((view, pos, side) => {
|
|
|
453
501
|
};
|
|
454
502
|
});
|
|
455
503
|
|
|
456
|
-
|
|
504
|
+
var tooltip = /*#__PURE__*//*@__PURE__*/Object.freeze({
|
|
505
|
+
__proto__: null,
|
|
506
|
+
cursorTooltipField: cursorTooltipField,
|
|
507
|
+
keywordTooltip: keywordTooltip
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
const baseTheme = /*@__PURE__*/EditorView.baseTheme({
|
|
457
511
|
".cm-tooltip.cm-tooltip-cursor": {
|
|
458
512
|
boxShadow: 'rgba(0, 0, 0, .15) 0 1px 2px',
|
|
459
513
|
border: "1px solid rgba(127, 127, 127, .2)",
|
|
@@ -482,24 +536,24 @@ const baseTheme = EditorView.baseTheme({
|
|
|
482
536
|
},
|
|
483
537
|
});
|
|
484
538
|
|
|
485
|
-
const ELLanguage = LRLanguage.define({
|
|
486
|
-
parser: parser.configure({
|
|
539
|
+
const ELLanguage = /*@__PURE__*/LRLanguage.define({
|
|
540
|
+
parser: /*@__PURE__*/parser.configure({
|
|
487
541
|
props: [
|
|
488
|
-
indentNodeProp.add({
|
|
489
|
-
Application: delimitedIndent({ closing: ")", align: false }),
|
|
490
|
-
Arguments: delimitedIndent({ closing: ")", align: false }),
|
|
491
|
-
Object: delimitedIndent({ closing: "}", align: false }),
|
|
542
|
+
/*@__PURE__*/indentNodeProp.add({
|
|
543
|
+
Application: /*@__PURE__*/delimitedIndent({ closing: ")", align: false }),
|
|
544
|
+
Arguments: /*@__PURE__*/delimitedIndent({ closing: ")", align: false }),
|
|
545
|
+
Object: /*@__PURE__*/delimitedIndent({ closing: "}", align: false }),
|
|
492
546
|
}),
|
|
493
|
-
foldNodeProp.add({
|
|
547
|
+
/*@__PURE__*/foldNodeProp.add({
|
|
494
548
|
Application: ({ from, to }) => ({ from: from + 1, to: to - 1 }),
|
|
495
549
|
Arguments: ({ from, to }) => ({ from: from + 1, to: to - 1 }),
|
|
496
550
|
Object: ({ from, to }) => ({ from: from + 1, to: to - 1 }),
|
|
497
551
|
}),
|
|
498
|
-
styleTags({
|
|
552
|
+
/*@__PURE__*/styleTags({
|
|
499
553
|
Property: tags.propertyName,
|
|
500
554
|
Variable: tags.variableName,
|
|
501
|
-
Function: tags.function(tags.variableName),
|
|
502
|
-
Method: tags.function(tags.propertyName),
|
|
555
|
+
Function: /*@__PURE__*/tags.function(tags.variableName),
|
|
556
|
+
Method: /*@__PURE__*/tags.function(tags.propertyName),
|
|
503
557
|
Boolean: tags.bool,
|
|
504
558
|
String: tags.string,
|
|
505
559
|
Number: tags.number,
|
|
@@ -533,4 +587,4 @@ function expressionlanguage(config = {}, extensions = []) {
|
|
|
533
587
|
]);
|
|
534
588
|
}
|
|
535
589
|
|
|
536
|
-
export { ELLanguage, expressionlanguage };
|
|
590
|
+
export { ELLanguage, ELScalar, complete as _complete, linter as _linter, tooltip as _tooltip, utils as _utils, expressionlanguage };
|
package/package.json
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"name": "@valtzu/codemirror-lang-el",
|
|
3
3
|
"description": "Symfony Expression Language language support for CodeMirror",
|
|
4
4
|
"scripts": {
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"prepare": "
|
|
5
|
+
"pretest": "npm run-script prepare",
|
|
6
|
+
"test": "cm-runtests",
|
|
7
|
+
"prepare": "cm-buildhelper src/index.ts"
|
|
8
8
|
},
|
|
9
9
|
"type": "module",
|
|
10
10
|
"main": "dist/index.cjs",
|
|
@@ -19,20 +19,15 @@
|
|
|
19
19
|
"@codemirror/autocomplete": "^6.9.0",
|
|
20
20
|
"@codemirror/language": "^6.0.0",
|
|
21
21
|
"@codemirror/lint": "^6.4.2",
|
|
22
|
-
"@codemirror/view": "^6.26.3",
|
|
23
22
|
"@codemirror/state": "^6.2.1",
|
|
23
|
+
"@codemirror/view": "^6.26.3",
|
|
24
24
|
"@lezer/highlight": "^1.0.0",
|
|
25
25
|
"@lezer/lr": "^1.0.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@
|
|
29
|
-
"@types/mocha": "^10.0.
|
|
30
|
-
"
|
|
31
|
-
"mocha": "10.4.0",
|
|
32
|
-
"rollup": "^2.60.2",
|
|
33
|
-
"rollup-plugin-dts": "^4.0.1",
|
|
34
|
-
"rollup-plugin-ts": "^3.0.2",
|
|
35
|
-
"typescript": "^4.3.4"
|
|
28
|
+
"@codemirror/buildhelper": "^1.0.0",
|
|
29
|
+
"@types/mocha": "^10.0.10",
|
|
30
|
+
"@types/node": "^22.10.5"
|
|
36
31
|
},
|
|
37
32
|
"license": "MIT",
|
|
38
33
|
"repository": {
|
|
@@ -43,5 +38,5 @@
|
|
|
43
38
|
"access": "public",
|
|
44
39
|
"registry": "https://registry.npmjs.org/"
|
|
45
40
|
},
|
|
46
|
-
"version": "0.
|
|
41
|
+
"version": "0.10.0"
|
|
47
42
|
}
|