@valtzu/codemirror-lang-el 0.9.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 +6 -0
- package/README.md +1 -1
- package/dist/index.cjs +56 -49
- package/dist/index.js +57 -50
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -77,17 +77,17 @@ function resolveFunctionDefinition(node, state, config) {
|
|
|
77
77
|
}
|
|
78
78
|
let identifier;
|
|
79
79
|
if ((node.type.is(PropertyAccess) || node.type.is(MethodAccess)) && node.lastChild) {
|
|
80
|
-
const leftArgument = (_a = node.firstChild) === null || _a ===
|
|
80
|
+
const leftArgument = (_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.node;
|
|
81
81
|
const types = Array.from(resolveTypes(state, leftArgument, config));
|
|
82
82
|
identifier = state.sliceDoc(node.lastChild.from, node.lastChild.to);
|
|
83
|
-
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 === void 0 ? void 0 : _a[type]); }).find(x => x);
|
|
84
84
|
}
|
|
85
85
|
else if (node.type.is(Function)) {
|
|
86
86
|
identifier = state.sliceDoc(node.from, node.node.firstChild ? node.node.firstChild.from - 1 : node.to);
|
|
87
87
|
return resolveCallable(identifier, config);
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
-
const resolveCallable = (identifier, config) => { var _a; return (_a = config === null || config ===
|
|
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); };
|
|
91
91
|
const resolveIdentifier = (nodeTypeId, identifier, config) => {
|
|
92
92
|
var _a;
|
|
93
93
|
switch (nodeTypeId) {
|
|
@@ -96,7 +96,7 @@ const resolveIdentifier = (nodeTypeId, identifier, config) => {
|
|
|
96
96
|
return resolveCallable(identifier, config);
|
|
97
97
|
case Property:
|
|
98
98
|
case Variable:
|
|
99
|
-
return (_a = config === null || config ===
|
|
99
|
+
return (_a = config === null || config === void 0 ? void 0 : config.identifiers) === null || _a === void 0 ? void 0 : _a.find(x => x.name === identifier);
|
|
100
100
|
}
|
|
101
101
|
};
|
|
102
102
|
function resolveTypes(state, node, config) {
|
|
@@ -115,27 +115,27 @@ function resolveTypes(state, node, config) {
|
|
|
115
115
|
else if (node.type.is(Variable)) {
|
|
116
116
|
const varName = state.sliceDoc(node.from, node.to) || '';
|
|
117
117
|
// @ts-ignore
|
|
118
|
-
(_b = (_a = resolveIdentifier(node.type.id, varName, config)) === null || _a ===
|
|
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));
|
|
119
119
|
}
|
|
120
120
|
else if (node.type.is(Function)) {
|
|
121
121
|
const varName = state.sliceDoc(node.from, node.to) || '';
|
|
122
122
|
// @ts-ignore
|
|
123
|
-
(_d = (_c = resolveIdentifier(node.type.id, varName, config)) === null || _c ===
|
|
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));
|
|
124
124
|
}
|
|
125
|
-
else if (node.type.is(PropertyAccess) && node.firstChild && ((_e = node.lastChild) === null || _e ===
|
|
125
|
+
else if (node.type.is(PropertyAccess) && node.firstChild && ((_e = node.lastChild) === null || _e === void 0 ? void 0 : _e.type.is(Property))) {
|
|
126
126
|
const varName = state.sliceDoc(node.lastChild.from, node.lastChild.to) || '';
|
|
127
|
-
(_f = resolveTypes(state, node.firstChild, config)) === null || _f ===
|
|
127
|
+
(_f = resolveTypes(state, node.firstChild, config)) === null || _f === void 0 ? void 0 : _f.forEach(baseType => {
|
|
128
128
|
var _a, _b, _c, _d;
|
|
129
129
|
// @ts-ignore
|
|
130
|
-
(_d = (_c = resolveIdentifier((_a = node.lastChild) === null || _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));
|
|
131
131
|
});
|
|
132
132
|
}
|
|
133
|
-
else if (node.type.is(MethodAccess) && node.firstChild && ((_g = node.lastChild) === null || _g ===
|
|
133
|
+
else if (node.type.is(MethodAccess) && node.firstChild && ((_g = node.lastChild) === null || _g === void 0 ? void 0 : _g.type.is(Method))) {
|
|
134
134
|
const varName = state.sliceDoc(node.lastChild.from, node.lastChild.to) || '';
|
|
135
|
-
(_h = resolveTypes(state, node.firstChild, config)) === null || _h ===
|
|
135
|
+
(_h = resolveTypes(state, node.firstChild, config)) === null || _h === void 0 ? void 0 : _h.forEach(baseType => {
|
|
136
136
|
var _a, _b, _c, _d;
|
|
137
137
|
// @ts-ignore
|
|
138
|
-
(_d = (_c = resolveIdentifier((_a = node.lastChild) === null || _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));
|
|
139
139
|
});
|
|
140
140
|
}
|
|
141
141
|
else if (node.type.is(Application) && node.firstChild) {
|
|
@@ -145,7 +145,7 @@ function resolveTypes(state, node, config) {
|
|
|
145
145
|
resolveTypes(state, node.firstChild.nextSibling, config).forEach(x => types.add(x));
|
|
146
146
|
resolveTypes(state, node.firstChild.nextSibling.nextSibling, config).forEach(x => types.add(x));
|
|
147
147
|
}
|
|
148
|
-
else if (node.type.is(BinaryExpression) && ((_j = node.firstChild) === null || _j ===
|
|
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)) {
|
|
149
149
|
const operator = state.sliceDoc(node.firstChild.nextSibling.from, node.firstChild.nextSibling.to);
|
|
150
150
|
if (operator == '?:' || operator == '??' || operator == '?') {
|
|
151
151
|
if (operator == '?:' || operator == '??') {
|
|
@@ -218,7 +218,7 @@ const expressionLanguageLinterSource = (state) => {
|
|
|
218
218
|
}
|
|
219
219
|
identifier = state.sliceDoc(from, to);
|
|
220
220
|
if (identifier.length === 0) {
|
|
221
|
-
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 === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.to) !== null && _c !== void 0 ? _c : to, severity: 'error', message: `Expression expected` });
|
|
222
222
|
}
|
|
223
223
|
else {
|
|
224
224
|
const type = /^[a-zA-Z_]+[a-zA-Z_0-9]*$/.test(identifier) ? 'identifier' : 'operator';
|
|
@@ -227,16 +227,20 @@ const expressionLanguageLinterSource = (state) => {
|
|
|
227
227
|
return;
|
|
228
228
|
case Arguments:
|
|
229
229
|
const fn = resolveFunctionDefinition(node.node.prevSibling, state, config);
|
|
230
|
-
const args = fn === null || fn ===
|
|
230
|
+
const args = fn === null || fn === void 0 ? void 0 : fn.args;
|
|
231
231
|
if (!args) {
|
|
232
232
|
return;
|
|
233
233
|
}
|
|
234
|
-
|
|
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) {
|
|
235
239
|
if (n.type.is(BlockComment)) {
|
|
236
240
|
continue;
|
|
237
241
|
}
|
|
238
|
-
if (i >
|
|
239
|
-
diagnostics.push({ from: n.from, to: n.to, severity: 'warning', message: `Unexpected argument –
|
|
242
|
+
if (i > argCountMax - 1) {
|
|
243
|
+
diagnostics.push({ from: n.from, to: n.to, severity: 'warning', message: `Unexpected argument – ${argumentCountHintFn()}` });
|
|
240
244
|
continue;
|
|
241
245
|
}
|
|
242
246
|
const typesUsed = Array.from(resolveTypes(state, n, config));
|
|
@@ -246,13 +250,16 @@ const expressionLanguageLinterSource = (state) => {
|
|
|
246
250
|
}
|
|
247
251
|
i++;
|
|
248
252
|
}
|
|
253
|
+
if (i < argCountMin) {
|
|
254
|
+
diagnostics.push({ from: node.from, to: node.to, severity: 'error', message: `Too few arguments – ${argumentCountHintFn()}` });
|
|
255
|
+
}
|
|
249
256
|
break;
|
|
250
257
|
case Property:
|
|
251
258
|
case Method:
|
|
252
|
-
const leftArgument = (_e = (_d = node.node.parent) === null || _d ===
|
|
259
|
+
const leftArgument = (_e = (_d = node.node.parent) === null || _d === void 0 ? void 0 : _d.firstChild) === null || _e === void 0 ? void 0 : _e.node;
|
|
253
260
|
const types = Array.from(resolveTypes(state, leftArgument, config));
|
|
254
261
|
identifier = state.sliceDoc(from, to);
|
|
255
|
-
if (!types.find(type => { var _a; return resolveIdentifier(id, identifier, (_a = config.types) === null || _a ===
|
|
262
|
+
if (!types.find(type => { var _a; return resolveIdentifier(id, identifier, (_a = config.types) === null || _a === void 0 ? void 0 : _a[type]); })) {
|
|
256
263
|
diagnostics.push({ from, to, severity: 'error', message: `${node.name} <code>${identifier}</code> not found in <code>${types.join('|')}</code>` });
|
|
257
264
|
}
|
|
258
265
|
break;
|
|
@@ -264,7 +271,7 @@ const expressionLanguageLinterSource = (state) => {
|
|
|
264
271
|
}
|
|
265
272
|
break;
|
|
266
273
|
}
|
|
267
|
-
if (identifier && ((_f = node.node.parent) === null || _f ===
|
|
274
|
+
if (identifier && ((_f = node.node.parent) === null || _f === void 0 ? void 0 : _f.type.isError)) {
|
|
268
275
|
diagnostics.push({ from, to, severity: 'error', message: `Unexpected identifier <code>${identifier}</code>` });
|
|
269
276
|
}
|
|
270
277
|
});
|
|
@@ -288,12 +295,12 @@ var linter = /*#__PURE__*/Object.freeze({
|
|
|
288
295
|
const autocompleteFunction = (x) => {
|
|
289
296
|
var _a, _b, _c;
|
|
290
297
|
return ({
|
|
291
|
-
label: `${x.name}(${((_b = (_a = x.args) === null || _a ===
|
|
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(',')) || ''})`,
|
|
292
299
|
apply: (view, completion, from, to) => {
|
|
293
300
|
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 ===
|
|
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) } }));
|
|
295
302
|
},
|
|
296
|
-
detail: (_c = x.returnType) === null || _c ===
|
|
303
|
+
detail: (_c = x.returnType) === null || _c === void 0 ? void 0 : _c.join('|'),
|
|
297
304
|
info: x.info,
|
|
298
305
|
type: "function",
|
|
299
306
|
});
|
|
@@ -304,7 +311,7 @@ const autocompleteIdentifier = (x) => {
|
|
|
304
311
|
label: x.name,
|
|
305
312
|
apply: x.name,
|
|
306
313
|
info: x.info,
|
|
307
|
-
detail: x.detail || ((_a = x.type) === null || _a ===
|
|
314
|
+
detail: x.detail || ((_a = x.type) === null || _a === void 0 ? void 0 : _a.join('|')),
|
|
308
315
|
type: 'variable',
|
|
309
316
|
});
|
|
310
317
|
};
|
|
@@ -319,14 +326,14 @@ function completeOperatorKeyword(state, config, tree, from, to, explicit) {
|
|
|
319
326
|
info: info,
|
|
320
327
|
detail,
|
|
321
328
|
type: "keyword"
|
|
322
|
-
}))) !== null && _a !==
|
|
323
|
-
validFor: (text) => { var _a; return (_a = keywords.some(({ name }) => explicit || name.includes(text))) !== null && _a !==
|
|
329
|
+
}))) !== null && _a !== void 0 ? _a : [],
|
|
330
|
+
validFor: (text) => { var _a; return (_a = keywords.some(({ name }) => explicit || name.includes(text))) !== null && _a !== void 0 ? _a : false; },
|
|
324
331
|
};
|
|
325
332
|
}
|
|
326
333
|
function completeIdentifier(state, config, tree, from, to) {
|
|
327
334
|
var _a, _b;
|
|
328
|
-
const identifiers = (_a = config.identifiers) !== null && _a !==
|
|
329
|
-
const functions = (_b = config.functions) !== null && _b !==
|
|
335
|
+
const identifiers = (_a = config.identifiers) !== null && _a !== void 0 ? _a : []; //?.filter(({ name }) => explicit || name.toLowerCase().startsWith(text)) ?? [];
|
|
336
|
+
const functions = (_b = config.functions) !== null && _b !== void 0 ? _b : []; //?.filter(({ name }) => explicit || name.toLowerCase().startsWith(text)) ?? [];
|
|
330
337
|
return {
|
|
331
338
|
from,
|
|
332
339
|
to,
|
|
@@ -336,17 +343,17 @@ function completeIdentifier(state, config, tree, from, to) {
|
|
|
336
343
|
}
|
|
337
344
|
function completeMember(state, config, tree, from, to, explicit) {
|
|
338
345
|
var _a, _b, _c, _d, _e, _f;
|
|
339
|
-
if (!(((_a = tree.parent) === null || _a ===
|
|
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)) {
|
|
340
347
|
return null;
|
|
341
348
|
}
|
|
342
349
|
const types = resolveTypes(state, tree.parent.firstChild.node, config);
|
|
343
|
-
if (!(types === null || types ===
|
|
350
|
+
if (!(types === null || types === void 0 ? void 0 : types.size)) {
|
|
344
351
|
return null;
|
|
345
352
|
}
|
|
346
353
|
let options = [];
|
|
347
354
|
for (const type of types) {
|
|
348
|
-
const typeDeclaration = (_d = config.types) === null || _d ===
|
|
349
|
-
options.push(...(((_e = typeDeclaration === null || typeDeclaration ===
|
|
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)) || []));
|
|
350
357
|
}
|
|
351
358
|
return {
|
|
352
359
|
from,
|
|
@@ -362,22 +369,22 @@ function expressionLanguageCompletion(context) {
|
|
|
362
369
|
const lastChar = state.sliceDoc(pos - 1, pos);
|
|
363
370
|
const prevNode = tree.resolveInner(pos, lastChar === ')' ? 0 : -1);
|
|
364
371
|
const config = getExpressionLanguageConfig(state);
|
|
365
|
-
const isIdentifier = (node) => (node === null || node ===
|
|
366
|
-
const isMember = (node) => (node === null || node ===
|
|
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));
|
|
367
374
|
if (prevNode.type.is(String) || prevNode.type.is(BlockComment)) {
|
|
368
375
|
return null;
|
|
369
376
|
}
|
|
370
|
-
if ((((_a = prevNode.parent) === null || _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)) {
|
|
371
378
|
return completeMember(state, config, prevNode, isIdentifier(prevNode) || isMember(prevNode) ? prevNode.from : pos, pos);
|
|
372
379
|
}
|
|
373
|
-
if (/^[\sa-z]*$/.test(lastChar) && ([Expression, UnaryExpression, BinaryExpression, TernaryExpression].includes(prevNode.type.id) && prevNode.lastChild && !((_d = prevNode.lastChild) === null || _d ===
|
|
374
|
-
|| [Arguments, Array$1].includes(prevNode.type.id) && prevNode.lastChild && !((_e = prevNode.lastChild) === null || _e ===
|
|
375
|
-
|| [Expression, UnaryExpression, BinaryExpression, TernaryExpression].includes((_f = prevNode.parent) === null || _f ===
|
|
376
|
-
|| [Variable, Function].includes((_g = prevNode.parent) === null || _g ===
|
|
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)) {
|
|
377
384
|
return completeOperatorKeyword(state, config, prevNode, ![Expression, UnaryExpression, BinaryExpression, TernaryExpression, Arguments].includes(prevNode.type.id) ? prevNode.from : pos, pos, explicit);
|
|
378
385
|
}
|
|
379
|
-
if (!/[0-9]/.test(lastChar) && !prevNode.type.is(OperatorKeyword) && ([Expression, UnaryExpression, BinaryExpression, TernaryExpression].includes(prevNode.type.id) && ((_h = prevNode.lastChild) === null || _h ===
|
|
380
|
-
|| [Expression, UnaryExpression, BinaryExpression, TernaryExpression, Arguments].includes((_k = (_j = prevNode.parent) === null || _j ===
|
|
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
|
|
381
388
|
|| prevNode.type.is(Arguments) || prevNode.type.is(Array$1))) {
|
|
382
389
|
return completeIdentifier(state, config, prevNode, isIdentifier(prevNode) ? prevNode.from : pos, pos);
|
|
383
390
|
}
|
|
@@ -421,7 +428,7 @@ function getCursorTooltips(state) {
|
|
|
421
428
|
return null;
|
|
422
429
|
}
|
|
423
430
|
const n = args.childAfter(range.from - 1);
|
|
424
|
-
const argName = (_b = (_a = fn.args) === null || _a ===
|
|
431
|
+
const argName = (_b = (_a = fn.args) === null || _a === void 0 ? void 0 : _a[n ? getNodeOrdinal(n) : 0]) === null || _b === void 0 ? void 0 : _b.name;
|
|
425
432
|
if (n && n.from !== range.from || !argName) {
|
|
426
433
|
return null;
|
|
427
434
|
}
|
|
@@ -455,7 +462,7 @@ const keywordTooltip = view.hoverTooltip((view, pos, side) => {
|
|
|
455
462
|
const tree = language.syntaxTree(view.state).resolveInner(pos, side);
|
|
456
463
|
if (tree.type.is(OperatorKeyword)) {
|
|
457
464
|
const name = view.state.sliceDoc(tree.from, tree.to);
|
|
458
|
-
const info = (_a = keywords.find(x => x.name === name)) === null || _a ===
|
|
465
|
+
const info = (_a = keywords.find(x => x.name === name)) === null || _a === void 0 ? void 0 : _a.info;
|
|
459
466
|
if (info) {
|
|
460
467
|
return {
|
|
461
468
|
pos: tree.from,
|
|
@@ -470,20 +477,20 @@ const keywordTooltip = view.hoverTooltip((view, pos, side) => {
|
|
|
470
477
|
}
|
|
471
478
|
const skipEmpty = (x) => x;
|
|
472
479
|
let info;
|
|
473
|
-
if (((_b = tree.parent) === null || _b ===
|
|
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) {
|
|
474
481
|
const node = tree.parent.firstChild;
|
|
475
482
|
const types = Array.from(resolveTypes(view.state, node, config));
|
|
476
483
|
const name = view.state.sliceDoc(tree.from, tree.to);
|
|
477
484
|
info = [
|
|
478
|
-
...types.map(type => { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = config.types) === null || _a ===
|
|
479
|
-
...types.map(type => { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = config.types) === null || _a ===
|
|
485
|
+
...types.map(type => { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = config.types) === null || _a === void 0 ? void 0 : _a[type]) === null || _b === void 0 ? void 0 : _b.identifiers) === null || _c === void 0 ? void 0 : _c.find(x => x.name === name)) === null || _d === void 0 ? void 0 : _d.info; }).filter(skipEmpty),
|
|
486
|
+
...types.map(type => { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = config.types) === null || _a === void 0 ? void 0 : _a[type]) === null || _b === void 0 ? void 0 : _b.functions) === null || _c === void 0 ? void 0 : _c.find(x => x.name === name)) === null || _d === void 0 ? void 0 : _d.info; }).filter(skipEmpty),
|
|
480
487
|
].join('\n');
|
|
481
488
|
}
|
|
482
489
|
else {
|
|
483
490
|
const name = view.state.sliceDoc(tree.from, tree.to);
|
|
484
491
|
info = [
|
|
485
|
-
...[(_f = (_e = config.identifiers) === null || _e ===
|
|
486
|
-
...[(_h = (_g = config.functions) === null || _g ===
|
|
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),
|
|
487
494
|
].join('\n');
|
|
488
495
|
}
|
|
489
496
|
if (!info) {
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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
4
|
import { linter as linter$1 } from '@codemirror/lint';
|
|
5
5
|
import { insertCompletionText } from '@codemirror/autocomplete';
|
|
@@ -74,17 +74,17 @@ function resolveFunctionDefinition(node, state, config) {
|
|
|
74
74
|
}
|
|
75
75
|
let identifier;
|
|
76
76
|
if ((node.type.is(PropertyAccess) || node.type.is(MethodAccess)) && node.lastChild) {
|
|
77
|
-
const leftArgument = (_a = node.firstChild) === null || _a ===
|
|
77
|
+
const leftArgument = (_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.node;
|
|
78
78
|
const types = Array.from(resolveTypes(state, leftArgument, config));
|
|
79
79
|
identifier = state.sliceDoc(node.lastChild.from, node.lastChild.to);
|
|
80
|
-
return types.map(type => { var _a; return resolveCallable(identifier, (_a = config.types) === null || _a ===
|
|
80
|
+
return types.map(type => { var _a; return resolveCallable(identifier, (_a = config.types) === null || _a === void 0 ? void 0 : _a[type]); }).find(x => x);
|
|
81
81
|
}
|
|
82
82
|
else if (node.type.is(Function)) {
|
|
83
83
|
identifier = state.sliceDoc(node.from, node.node.firstChild ? node.node.firstChild.from - 1 : node.to);
|
|
84
84
|
return resolveCallable(identifier, config);
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
const resolveCallable = (identifier, config) => { var _a; return (_a = config === null || config ===
|
|
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); };
|
|
88
88
|
const resolveIdentifier = (nodeTypeId, identifier, config) => {
|
|
89
89
|
var _a;
|
|
90
90
|
switch (nodeTypeId) {
|
|
@@ -93,7 +93,7 @@ const resolveIdentifier = (nodeTypeId, identifier, config) => {
|
|
|
93
93
|
return resolveCallable(identifier, config);
|
|
94
94
|
case Property:
|
|
95
95
|
case Variable:
|
|
96
|
-
return (_a = config === null || config ===
|
|
96
|
+
return (_a = config === null || config === void 0 ? void 0 : config.identifiers) === null || _a === void 0 ? void 0 : _a.find(x => x.name === identifier);
|
|
97
97
|
}
|
|
98
98
|
};
|
|
99
99
|
function resolveTypes(state, node, config) {
|
|
@@ -112,27 +112,27 @@ function resolveTypes(state, node, config) {
|
|
|
112
112
|
else if (node.type.is(Variable)) {
|
|
113
113
|
const varName = state.sliceDoc(node.from, node.to) || '';
|
|
114
114
|
// @ts-ignore
|
|
115
|
-
(_b = (_a = resolveIdentifier(node.type.id, varName, config)) === null || _a ===
|
|
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));
|
|
116
116
|
}
|
|
117
117
|
else if (node.type.is(Function)) {
|
|
118
118
|
const varName = state.sliceDoc(node.from, node.to) || '';
|
|
119
119
|
// @ts-ignore
|
|
120
|
-
(_d = (_c = resolveIdentifier(node.type.id, varName, config)) === null || _c ===
|
|
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));
|
|
121
121
|
}
|
|
122
|
-
else if (node.type.is(PropertyAccess) && node.firstChild && ((_e = node.lastChild) === null || _e ===
|
|
122
|
+
else if (node.type.is(PropertyAccess) && node.firstChild && ((_e = node.lastChild) === null || _e === void 0 ? void 0 : _e.type.is(Property))) {
|
|
123
123
|
const varName = state.sliceDoc(node.lastChild.from, node.lastChild.to) || '';
|
|
124
|
-
(_f = resolveTypes(state, node.firstChild, config)) === null || _f ===
|
|
124
|
+
(_f = resolveTypes(state, node.firstChild, config)) === null || _f === void 0 ? void 0 : _f.forEach(baseType => {
|
|
125
125
|
var _a, _b, _c, _d;
|
|
126
126
|
// @ts-ignore
|
|
127
|
-
(_d = (_c = resolveIdentifier((_a = node.lastChild) === null || _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));
|
|
128
128
|
});
|
|
129
129
|
}
|
|
130
|
-
else if (node.type.is(MethodAccess) && node.firstChild && ((_g = node.lastChild) === null || _g ===
|
|
130
|
+
else if (node.type.is(MethodAccess) && node.firstChild && ((_g = node.lastChild) === null || _g === void 0 ? void 0 : _g.type.is(Method))) {
|
|
131
131
|
const varName = state.sliceDoc(node.lastChild.from, node.lastChild.to) || '';
|
|
132
|
-
(_h = resolveTypes(state, node.firstChild, config)) === null || _h ===
|
|
132
|
+
(_h = resolveTypes(state, node.firstChild, config)) === null || _h === void 0 ? void 0 : _h.forEach(baseType => {
|
|
133
133
|
var _a, _b, _c, _d;
|
|
134
134
|
// @ts-ignore
|
|
135
|
-
(_d = (_c = resolveIdentifier((_a = node.lastChild) === null || _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));
|
|
136
136
|
});
|
|
137
137
|
}
|
|
138
138
|
else if (node.type.is(Application) && node.firstChild) {
|
|
@@ -142,7 +142,7 @@ function resolveTypes(state, node, config) {
|
|
|
142
142
|
resolveTypes(state, node.firstChild.nextSibling, config).forEach(x => types.add(x));
|
|
143
143
|
resolveTypes(state, node.firstChild.nextSibling.nextSibling, config).forEach(x => types.add(x));
|
|
144
144
|
}
|
|
145
|
-
else if (node.type.is(BinaryExpression) && ((_j = node.firstChild) === null || _j ===
|
|
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)) {
|
|
146
146
|
const operator = state.sliceDoc(node.firstChild.nextSibling.from, node.firstChild.nextSibling.to);
|
|
147
147
|
if (operator == '?:' || operator == '??' || operator == '?') {
|
|
148
148
|
if (operator == '?:' || operator == '??') {
|
|
@@ -215,7 +215,7 @@ const expressionLanguageLinterSource = (state) => {
|
|
|
215
215
|
}
|
|
216
216
|
identifier = state.sliceDoc(from, to);
|
|
217
217
|
if (identifier.length === 0) {
|
|
218
|
-
diagnostics.push({ from, to: (_c = (_b = (_a = node.node.parent) === null || _a ===
|
|
218
|
+
diagnostics.push({ from, to: (_c = (_b = (_a = node.node.parent) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.to) !== null && _c !== void 0 ? _c : to, severity: 'error', message: `Expression expected` });
|
|
219
219
|
}
|
|
220
220
|
else {
|
|
221
221
|
const type = /^[a-zA-Z_]+[a-zA-Z_0-9]*$/.test(identifier) ? 'identifier' : 'operator';
|
|
@@ -224,16 +224,20 @@ const expressionLanguageLinterSource = (state) => {
|
|
|
224
224
|
return;
|
|
225
225
|
case Arguments:
|
|
226
226
|
const fn = resolveFunctionDefinition(node.node.prevSibling, state, config);
|
|
227
|
-
const args = fn === null || fn ===
|
|
227
|
+
const args = fn === null || fn === void 0 ? void 0 : fn.args;
|
|
228
228
|
if (!args) {
|
|
229
229
|
return;
|
|
230
230
|
}
|
|
231
|
-
|
|
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) {
|
|
232
236
|
if (n.type.is(BlockComment)) {
|
|
233
237
|
continue;
|
|
234
238
|
}
|
|
235
|
-
if (i >
|
|
236
|
-
diagnostics.push({ from: n.from, to: n.to, severity: 'warning', message: `Unexpected argument –
|
|
239
|
+
if (i > argCountMax - 1) {
|
|
240
|
+
diagnostics.push({ from: n.from, to: n.to, severity: 'warning', message: `Unexpected argument – ${argumentCountHintFn()}` });
|
|
237
241
|
continue;
|
|
238
242
|
}
|
|
239
243
|
const typesUsed = Array.from(resolveTypes(state, n, config));
|
|
@@ -243,13 +247,16 @@ const expressionLanguageLinterSource = (state) => {
|
|
|
243
247
|
}
|
|
244
248
|
i++;
|
|
245
249
|
}
|
|
250
|
+
if (i < argCountMin) {
|
|
251
|
+
diagnostics.push({ from: node.from, to: node.to, severity: 'error', message: `Too few arguments – ${argumentCountHintFn()}` });
|
|
252
|
+
}
|
|
246
253
|
break;
|
|
247
254
|
case Property:
|
|
248
255
|
case Method:
|
|
249
|
-
const leftArgument = (_e = (_d = node.node.parent) === null || _d ===
|
|
256
|
+
const leftArgument = (_e = (_d = node.node.parent) === null || _d === void 0 ? void 0 : _d.firstChild) === null || _e === void 0 ? void 0 : _e.node;
|
|
250
257
|
const types = Array.from(resolveTypes(state, leftArgument, config));
|
|
251
258
|
identifier = state.sliceDoc(from, to);
|
|
252
|
-
if (!types.find(type => { var _a; return resolveIdentifier(id, identifier, (_a = config.types) === null || _a ===
|
|
259
|
+
if (!types.find(type => { var _a; return resolveIdentifier(id, identifier, (_a = config.types) === null || _a === void 0 ? void 0 : _a[type]); })) {
|
|
253
260
|
diagnostics.push({ from, to, severity: 'error', message: `${node.name} <code>${identifier}</code> not found in <code>${types.join('|')}</code>` });
|
|
254
261
|
}
|
|
255
262
|
break;
|
|
@@ -261,7 +268,7 @@ const expressionLanguageLinterSource = (state) => {
|
|
|
261
268
|
}
|
|
262
269
|
break;
|
|
263
270
|
}
|
|
264
|
-
if (identifier && ((_f = node.node.parent) === null || _f ===
|
|
271
|
+
if (identifier && ((_f = node.node.parent) === null || _f === void 0 ? void 0 : _f.type.isError)) {
|
|
265
272
|
diagnostics.push({ from, to, severity: 'error', message: `Unexpected identifier <code>${identifier}</code>` });
|
|
266
273
|
}
|
|
267
274
|
});
|
|
@@ -285,12 +292,12 @@ var linter = /*#__PURE__*//*@__PURE__*/Object.freeze({
|
|
|
285
292
|
const autocompleteFunction = (x) => {
|
|
286
293
|
var _a, _b, _c;
|
|
287
294
|
return ({
|
|
288
|
-
label: `${x.name}(${((_b = (_a = x.args) === null || _a ===
|
|
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(',')) || ''})`,
|
|
289
296
|
apply: (view, completion, from, to) => {
|
|
290
297
|
var _a, _b;
|
|
291
|
-
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 ===
|
|
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) } }));
|
|
292
299
|
},
|
|
293
|
-
detail: (_c = x.returnType) === null || _c ===
|
|
300
|
+
detail: (_c = x.returnType) === null || _c === void 0 ? void 0 : _c.join('|'),
|
|
294
301
|
info: x.info,
|
|
295
302
|
type: "function",
|
|
296
303
|
});
|
|
@@ -301,7 +308,7 @@ const autocompleteIdentifier = (x) => {
|
|
|
301
308
|
label: x.name,
|
|
302
309
|
apply: x.name,
|
|
303
310
|
info: x.info,
|
|
304
|
-
detail: x.detail || ((_a = x.type) === null || _a ===
|
|
311
|
+
detail: x.detail || ((_a = x.type) === null || _a === void 0 ? void 0 : _a.join('|')),
|
|
305
312
|
type: 'variable',
|
|
306
313
|
});
|
|
307
314
|
};
|
|
@@ -316,14 +323,14 @@ function completeOperatorKeyword(state, config, tree, from, to, explicit) {
|
|
|
316
323
|
info: info,
|
|
317
324
|
detail,
|
|
318
325
|
type: "keyword"
|
|
319
|
-
}))) !== null && _a !==
|
|
320
|
-
validFor: (text) => { var _a; return (_a = keywords.some(({ name }) => explicit || name.includes(text))) !== null && _a !==
|
|
326
|
+
}))) !== null && _a !== void 0 ? _a : [],
|
|
327
|
+
validFor: (text) => { var _a; return (_a = keywords.some(({ name }) => explicit || name.includes(text))) !== null && _a !== void 0 ? _a : false; },
|
|
321
328
|
};
|
|
322
329
|
}
|
|
323
330
|
function completeIdentifier(state, config, tree, from, to) {
|
|
324
331
|
var _a, _b;
|
|
325
|
-
const identifiers = (_a = config.identifiers) !== null && _a !==
|
|
326
|
-
const functions = (_b = config.functions) !== null && _b !==
|
|
332
|
+
const identifiers = (_a = config.identifiers) !== null && _a !== void 0 ? _a : []; //?.filter(({ name }) => explicit || name.toLowerCase().startsWith(text)) ?? [];
|
|
333
|
+
const functions = (_b = config.functions) !== null && _b !== void 0 ? _b : []; //?.filter(({ name }) => explicit || name.toLowerCase().startsWith(text)) ?? [];
|
|
327
334
|
return {
|
|
328
335
|
from,
|
|
329
336
|
to,
|
|
@@ -333,17 +340,17 @@ function completeIdentifier(state, config, tree, from, to) {
|
|
|
333
340
|
}
|
|
334
341
|
function completeMember(state, config, tree, from, to, explicit) {
|
|
335
342
|
var _a, _b, _c, _d, _e, _f;
|
|
336
|
-
if (!(((_a = tree.parent) === null || _a ===
|
|
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)) {
|
|
337
344
|
return null;
|
|
338
345
|
}
|
|
339
346
|
const types = resolveTypes(state, tree.parent.firstChild.node, config);
|
|
340
|
-
if (!(types === null || types ===
|
|
347
|
+
if (!(types === null || types === void 0 ? void 0 : types.size)) {
|
|
341
348
|
return null;
|
|
342
349
|
}
|
|
343
350
|
let options = [];
|
|
344
351
|
for (const type of types) {
|
|
345
|
-
const typeDeclaration = (_d = config.types) === null || _d ===
|
|
346
|
-
options.push(...(((_e = typeDeclaration === null || typeDeclaration ===
|
|
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)) || []));
|
|
347
354
|
}
|
|
348
355
|
return {
|
|
349
356
|
from,
|
|
@@ -359,22 +366,22 @@ function expressionLanguageCompletion(context) {
|
|
|
359
366
|
const lastChar = state.sliceDoc(pos - 1, pos);
|
|
360
367
|
const prevNode = tree.resolveInner(pos, lastChar === ')' ? 0 : -1);
|
|
361
368
|
const config = getExpressionLanguageConfig(state);
|
|
362
|
-
const isIdentifier = (node) => (node === null || node ===
|
|
363
|
-
const isMember = (node) => (node === null || node ===
|
|
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));
|
|
364
371
|
if (prevNode.type.is(String) || prevNode.type.is(BlockComment)) {
|
|
365
372
|
return null;
|
|
366
373
|
}
|
|
367
|
-
if ((((_a = prevNode.parent) === null || _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)) {
|
|
368
375
|
return completeMember(state, config, prevNode, isIdentifier(prevNode) || isMember(prevNode) ? prevNode.from : pos, pos);
|
|
369
376
|
}
|
|
370
|
-
if (/^[\sa-z]*$/.test(lastChar) && ([Expression, UnaryExpression, BinaryExpression, TernaryExpression].includes(prevNode.type.id) && prevNode.lastChild && !((_d = prevNode.lastChild) === null || _d ===
|
|
371
|
-
|| [Arguments, Array$1].includes(prevNode.type.id) && prevNode.lastChild && !((_e = prevNode.lastChild) === null || _e ===
|
|
372
|
-
|| [Expression, UnaryExpression, BinaryExpression, TernaryExpression].includes((_f = prevNode.parent) === null || _f ===
|
|
373
|
-
|| [Variable, Function].includes((_g = prevNode.parent) === null || _g ===
|
|
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)) {
|
|
374
381
|
return completeOperatorKeyword(state, config, prevNode, ![Expression, UnaryExpression, BinaryExpression, TernaryExpression, Arguments].includes(prevNode.type.id) ? prevNode.from : pos, pos, explicit);
|
|
375
382
|
}
|
|
376
|
-
if (!/[0-9]/.test(lastChar) && !prevNode.type.is(OperatorKeyword) && ([Expression, UnaryExpression, BinaryExpression, TernaryExpression].includes(prevNode.type.id) && ((_h = prevNode.lastChild) === null || _h ===
|
|
377
|
-
|| [Expression, UnaryExpression, BinaryExpression, TernaryExpression, Arguments].includes((_k = (_j = prevNode.parent) === null || _j ===
|
|
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
|
|
378
385
|
|| prevNode.type.is(Arguments) || prevNode.type.is(Array$1))) {
|
|
379
386
|
return completeIdentifier(state, config, prevNode, isIdentifier(prevNode) ? prevNode.from : pos, pos);
|
|
380
387
|
}
|
|
@@ -418,7 +425,7 @@ function getCursorTooltips(state) {
|
|
|
418
425
|
return null;
|
|
419
426
|
}
|
|
420
427
|
const n = args.childAfter(range.from - 1);
|
|
421
|
-
const argName = (_b = (_a = fn.args) === null || _a ===
|
|
428
|
+
const argName = (_b = (_a = fn.args) === null || _a === void 0 ? void 0 : _a[n ? getNodeOrdinal(n) : 0]) === null || _b === void 0 ? void 0 : _b.name;
|
|
422
429
|
if (n && n.from !== range.from || !argName) {
|
|
423
430
|
return null;
|
|
424
431
|
}
|
|
@@ -452,7 +459,7 @@ const keywordTooltip = /*@__PURE__*/hoverTooltip((view, pos, side) => {
|
|
|
452
459
|
const tree = syntaxTree(view.state).resolveInner(pos, side);
|
|
453
460
|
if (tree.type.is(OperatorKeyword)) {
|
|
454
461
|
const name = view.state.sliceDoc(tree.from, tree.to);
|
|
455
|
-
const info = (_a = keywords.find(x => x.name === name)) === null || _a ===
|
|
462
|
+
const info = (_a = keywords.find(x => x.name === name)) === null || _a === void 0 ? void 0 : _a.info;
|
|
456
463
|
if (info) {
|
|
457
464
|
return {
|
|
458
465
|
pos: tree.from,
|
|
@@ -467,20 +474,20 @@ const keywordTooltip = /*@__PURE__*/hoverTooltip((view, pos, side) => {
|
|
|
467
474
|
}
|
|
468
475
|
const skipEmpty = (x) => x;
|
|
469
476
|
let info;
|
|
470
|
-
if (((_b = tree.parent) === null || _b ===
|
|
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) {
|
|
471
478
|
const node = tree.parent.firstChild;
|
|
472
479
|
const types = Array.from(resolveTypes(view.state, node, config));
|
|
473
480
|
const name = view.state.sliceDoc(tree.from, tree.to);
|
|
474
481
|
info = [
|
|
475
|
-
...types.map(type => { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = config.types) === null || _a ===
|
|
476
|
-
...types.map(type => { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = config.types) === null || _a ===
|
|
482
|
+
...types.map(type => { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = config.types) === null || _a === void 0 ? void 0 : _a[type]) === null || _b === void 0 ? void 0 : _b.identifiers) === null || _c === void 0 ? void 0 : _c.find(x => x.name === name)) === null || _d === void 0 ? void 0 : _d.info; }).filter(skipEmpty),
|
|
483
|
+
...types.map(type => { var _a, _b, _c, _d; return (_d = (_c = (_b = (_a = config.types) === null || _a === void 0 ? void 0 : _a[type]) === null || _b === void 0 ? void 0 : _b.functions) === null || _c === void 0 ? void 0 : _c.find(x => x.name === name)) === null || _d === void 0 ? void 0 : _d.info; }).filter(skipEmpty),
|
|
477
484
|
].join('\n');
|
|
478
485
|
}
|
|
479
486
|
else {
|
|
480
487
|
const name = view.state.sliceDoc(tree.from, tree.to);
|
|
481
488
|
info = [
|
|
482
|
-
...[(_f = (_e = config.identifiers) === null || _e ===
|
|
483
|
-
...[(_h = (_g = config.functions) === null || _g ===
|
|
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),
|
|
484
491
|
].join('\n');
|
|
485
492
|
}
|
|
486
493
|
if (!info) {
|
package/package.json
CHANGED