@valtzu/codemirror-lang-el 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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
- "test": "mocha test/*.js",
6
- "dev": "rollup -c -w",
7
- "prepare": "rollup -c"
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
- "@lezer/generator": "^1.0.0",
29
- "@types/mocha": "^10.0.1",
30
- "ist": "^1.1.7",
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.8.0"
41
+ "version": "0.9.0"
47
42
  }
package/dist/complete.cjs DELETED
@@ -1,224 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var autocomplete = require('@codemirror/autocomplete');
6
- var language = require('@codemirror/language');
7
-
8
- var ELScalar;
9
- (function (ELScalar) {
10
- ELScalar["Bool"] = "bool";
11
- ELScalar["Number"] = "number";
12
- ELScalar["String"] = "string";
13
- ELScalar["Null"] = "null";
14
- ELScalar["Any"] = "any";
15
- })(ELScalar || (ELScalar = {}));
16
-
17
- // @ts-ignore
18
- const t = {
19
- deserialize: (str) => str,
20
- };
21
-
22
- 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); };
23
- const resolveIdentifier = (nodeName, identifier, config) => {
24
- var _a;
25
- switch (nodeName) {
26
- case 'Method':
27
- case 'Function':
28
- return resolveCallable(identifier, config);
29
- case 'Property':
30
- case 'Variable':
31
- return (_a = config === null || config === void 0 ? void 0 : config.identifiers) === null || _a === void 0 ? void 0 : _a.find(x => x.name === identifier);
32
- }
33
- };
34
- function resolveTypes(state, node, config, matchExact) {
35
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
36
- let types = new Set();
37
- if (!node) {
38
- return types;
39
- }
40
- let type;
41
- if (typeof (type = node.type.prop(t)) !== "undefined") {
42
- types.add(type);
43
- }
44
- else if (node.name === 'Call' && node.firstChild && node.lastChild) {
45
- resolveTypes(state, node.firstChild, config).forEach(x => types.add(x));
46
- }
47
- else if (node.name === 'Variable') {
48
- const varName = state.sliceDoc(node.from, node.to) || '';
49
- // @ts-ignore
50
- (_b = (_a = resolveIdentifier(node.name, varName, config)) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.forEach((x) => types.add(x));
51
- }
52
- else if (node.name === 'Function') {
53
- const varName = state.sliceDoc(node.from, node.to) || '';
54
- // @ts-ignore
55
- (_d = (_c = resolveIdentifier(node.name, varName, config)) === null || _c === void 0 ? void 0 : _c.returnType) === null || _d === void 0 ? void 0 : _d.forEach((x) => types.add(x));
56
- }
57
- else if (node.name === 'ObjectAccess' && node.firstChild && ((_e = node.lastChild) === null || _e === void 0 ? void 0 : _e.name) === 'Property') {
58
- const varName = state.sliceDoc(node.lastChild.from, node.lastChild.to) || '';
59
- (_f = resolveTypes(state, node.firstChild, config)) === null || _f === void 0 ? void 0 : _f.forEach(baseType => {
60
- var _a, _b, _c, _d;
61
- // @ts-ignore
62
- (_d = (_c = resolveIdentifier((_a = node.lastChild) === null || _a === void 0 ? void 0 : _a.name, 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));
63
- });
64
- }
65
- else if (node.name === 'ObjectAccess' && node.firstChild && ((_g = node.lastChild) === null || _g === void 0 ? void 0 : _g.name) === 'Method') {
66
- const varName = state.sliceDoc(node.lastChild.from, node.lastChild.to) || '';
67
- (_h = resolveTypes(state, node.firstChild, config)) === null || _h === void 0 ? void 0 : _h.forEach(baseType => {
68
- var _a, _b, _c, _d;
69
- // @ts-ignore
70
- (_d = (_c = resolveIdentifier((_a = node.lastChild) === null || _a === void 0 ? void 0 : _a.name, 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));
71
- });
72
- }
73
- else if (node.name === 'Application' && node.firstChild) {
74
- resolveTypes(state, node.firstChild, config).forEach(x => types.add(x));
75
- }
76
- else if (node.name === 'TernaryExpression' && node.firstChild && node.firstChild.nextSibling && node.firstChild.nextSibling.nextSibling) {
77
- resolveTypes(state, node.firstChild.nextSibling, config).forEach(x => types.add(x));
78
- resolveTypes(state, node.firstChild.nextSibling.nextSibling, config).forEach(x => types.add(x));
79
- }
80
- else if (node.name === '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)) {
81
- const operator = state.sliceDoc(node.firstChild.nextSibling.from, node.firstChild.nextSibling.to);
82
- if (operator == '?:' || operator == '??' || operator == '?') {
83
- if (operator == '?:' || operator == '??') {
84
- resolveTypes(state, node.firstChild, config).forEach(x => types.add(x));
85
- }
86
- resolveTypes(state, node.firstChild.nextSibling.nextSibling, config).forEach(x => types.add(x));
87
- }
88
- else if (['||', '&&', '==', '!=', '===', '!==', '>=', '<=', '>', '<'].includes(operator) || keywords.find(x => x.name == operator)) {
89
- types.add(ELScalar.Bool);
90
- }
91
- else if (['**', '|', '^', '&', '<<', '>>', '+', '-', '*', '/', '%'].includes(operator)) {
92
- types.add(ELScalar.Number);
93
- }
94
- }
95
- else if (node.name === 'UnaryExpression' && node.firstChild) {
96
- const operator = state.sliceDoc(node.firstChild.from, node.firstChild.to);
97
- if (['not', '!'].includes(operator)) {
98
- types.add(ELScalar.Bool);
99
- }
100
- else if (['+', '-'].includes(operator)) {
101
- types.add(ELScalar.Number);
102
- }
103
- }
104
- if (types.size === 0) {
105
- types.add(ELScalar.Any);
106
- }
107
- return types;
108
- }
109
- function getExpressionLanguageConfig(state) {
110
- return state.languageDataAt('expressionLanguageConfig', 0)[0];
111
- }
112
- const keywords = [
113
- { name: 'starts with', info: 'Check if a string starts with a specific string' },
114
- { name: 'ends with', info: 'Check if a string ends with a specific string' },
115
- { name: 'contains', info: 'Check if a string is not included in another string' },
116
- { name: 'matches', info: 'Check if a string matches a regex pattern' },
117
- { name: 'not in', info: 'Check if a value is not included in an array' },
118
- { name: 'in', info: 'Check if a value is included in an array' },
119
- { name: 'not' },
120
- { name: 'or' },
121
- { name: 'and' },
122
- { name: 'xor' },
123
- ];
124
-
125
- const autocompleteFunction = (x) => {
126
- var _a, _b, _c;
127
- return ({
128
- 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(',')) || ''})`,
129
- apply: (view, completion, from, to) => {
130
- var _a;
131
- 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) } }));
132
- },
133
- detail: (_c = x.returnType) === null || _c === void 0 ? void 0 : _c.join('|'),
134
- info: x.info,
135
- type: "function",
136
- });
137
- };
138
- const autocompleteIdentifier = (x) => {
139
- var _a;
140
- return ({
141
- label: x.name,
142
- apply: x.name,
143
- info: x.info,
144
- detail: x.detail || ((_a = x.type) === null || _a === void 0 ? void 0 : _a.join('|')),
145
- type: 'variable',
146
- });
147
- };
148
- function completeOperatorKeyword(state, config, tree, from, to, explicit) {
149
- var _a;
150
- return {
151
- from,
152
- to,
153
- options: (_a = keywords.map(({ name, info, detail }) => ({
154
- label: name,
155
- apply: `${name} `,
156
- info: info,
157
- detail,
158
- type: "keyword"
159
- }))) !== null && _a !== void 0 ? _a : [],
160
- validFor: (text) => { var _a; return (_a = keywords.some(({ name }) => explicit || name.includes(text))) !== null && _a !== void 0 ? _a : false; },
161
- };
162
- }
163
- function completeIdentifier(state, config, tree, from, to) {
164
- var _a, _b;
165
- const identifiers = (_a = config.identifiers) !== null && _a !== void 0 ? _a : []; //?.filter(({ name }) => explicit || name.toLowerCase().startsWith(text)) ?? [];
166
- const functions = (_b = config.functions) !== null && _b !== void 0 ? _b : []; //?.filter(({ name }) => explicit || name.toLowerCase().startsWith(text)) ?? [];
167
- return {
168
- from,
169
- to,
170
- options: [...(identifiers.map(autocompleteIdentifier)), ...(functions.map(autocompleteFunction))],
171
- validFor: /^[a-zA-Z_]+[a-zA-Z_0-9]*$/,
172
- };
173
- }
174
- function completeMember(state, config, tree, from, to, explicit) {
175
- var _a, _b, _c, _d;
176
- if (((_a = tree.parent) === null || _a === void 0 ? void 0 : _a.name) != 'ObjectAccess' || !tree.parent.firstChild) {
177
- return null;
178
- }
179
- const types = resolveTypes(state, tree.parent.firstChild.node, config);
180
- if (!(types === null || types === void 0 ? void 0 : types.size)) {
181
- return null;
182
- }
183
- let options = [];
184
- for (const type of types) {
185
- const typeDeclaration = (_b = config.types) === null || _b === void 0 ? void 0 : _b[type];
186
- options.push(...(((_c = typeDeclaration === null || typeDeclaration === void 0 ? void 0 : typeDeclaration.identifiers) === null || _c === void 0 ? void 0 : _c.map(autocompleteIdentifier)) || []), ...(((_d = typeDeclaration === null || typeDeclaration === void 0 ? void 0 : typeDeclaration.functions) === null || _d === void 0 ? void 0 : _d.map(autocompleteFunction)) || []));
187
- }
188
- return {
189
- from,
190
- to,
191
- options,
192
- validFor: /^[a-zA-Z_]+[a-zA-Z_0-9]*$/,
193
- };
194
- }
195
- function expressionLanguageCompletion(context) {
196
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
197
- const { state, pos, explicit } = context;
198
- const tree = language.syntaxTree(state);
199
- const lastChar = state.sliceDoc(pos - 1, pos);
200
- const prevNode = tree.resolveInner(pos, lastChar === ')' ? 0 : -1);
201
- const config = getExpressionLanguageConfig(state);
202
- const isIdentifier = (node) => { var _a; return ['Variable', 'Function'].includes((_a = node === null || node === void 0 ? void 0 : node.name) !== null && _a !== void 0 ? _a : ''); };
203
- const isMember = (node) => { var _a; return ['Property', 'Method'].includes((_a = node === null || node === void 0 ? void 0 : node.name) !== null && _a !== void 0 ? _a : ''); };
204
- if (prevNode.name == 'String' || prevNode.name == 'BlockComment') {
205
- return null;
206
- }
207
- if (((_a = prevNode.parent) === null || _a === void 0 ? void 0 : _a.name) == 'ObjectAccess' && ['ObjectAccess', 'ArrayAccess', 'Variable', 'Call', 'Application'].includes(((_b = prevNode.parent.firstChild) === null || _b === void 0 ? void 0 : _b.name) || '')) {
208
- return completeMember(state, config, prevNode, isIdentifier(prevNode) || isMember(prevNode) ? prevNode.from : pos, pos);
209
- }
210
- if (['Expression', 'UnaryExpression', 'BinaryExpression', 'TernaryExpression'].includes(prevNode.name) && prevNode.lastChild && !((_c = prevNode.lastChild) === null || _c === void 0 ? void 0 : _c.type.isError)
211
- || ['Arguments', 'Array'].includes(prevNode.name) && prevNode.lastChild && !((_d = prevNode.lastChild) === null || _d === void 0 ? void 0 : _d.type.isError)
212
- || ['Expression', 'UnaryExpression', 'BinaryExpression', 'TernaryExpression'].includes((_f = (_e = prevNode.parent) === null || _e === void 0 ? void 0 : _e.name) !== null && _f !== void 0 ? _f : '') && prevNode.type.isError
213
- || ['Variable', 'Function'].includes((_h = (_g = prevNode.parent) === null || _g === void 0 ? void 0 : _g.name) !== null && _h !== void 0 ? _h : '') && prevNode.type.isError) {
214
- return completeOperatorKeyword(state, config, prevNode, !['Expression', 'UnaryExpression', 'BinaryExpression', 'TernaryExpression', 'Arguments'].includes(prevNode.name) ? prevNode.from : pos, pos, explicit);
215
- }
216
- if (!/[0-9]/.test(lastChar) && !['OperatorKeyword'].includes((_j = prevNode.name) !== null && _j !== void 0 ? _j : '') && (['Expression', 'UnaryExpression', 'BinaryExpression', 'TernaryExpression'].includes(prevNode.name) && ((_k = prevNode.lastChild) === null || _k === void 0 ? void 0 : _k.type.isError)
217
- || ['Expression', 'UnaryExpression', 'BinaryExpression', 'TernaryExpression', 'Arguments'].includes((_m = (_l = prevNode.parent) === null || _l === void 0 ? void 0 : _l.name) !== null && _m !== void 0 ? _m : '') && !prevNode.type.isError
218
- || ['Arguments', 'Array'].includes((_o = prevNode.name) !== null && _o !== void 0 ? _o : ''))) {
219
- return completeIdentifier(state, config, prevNode, isIdentifier(prevNode) ? prevNode.from : pos, pos);
220
- }
221
- return null;
222
- }
223
-
224
- exports.expressionLanguageCompletion = expressionLanguageCompletion;
@@ -1,3 +0,0 @@
1
- import { CompletionContext, CompletionResult } from "@codemirror/autocomplete";
2
- declare function expressionLanguageCompletion(context: CompletionContext): CompletionResult | null;
3
- export { expressionLanguageCompletion };
@@ -1,3 +0,0 @@
1
- import { CompletionContext, CompletionResult } from "@codemirror/autocomplete";
2
- declare function expressionLanguageCompletion(context: CompletionContext): CompletionResult | null;
3
- export { expressionLanguageCompletion };
package/dist/complete.js DELETED
@@ -1,220 +0,0 @@
1
- import { insertCompletionText } from '@codemirror/autocomplete';
2
- import { syntaxTree } from '@codemirror/language';
3
-
4
- var ELScalar;
5
- (function (ELScalar) {
6
- ELScalar["Bool"] = "bool";
7
- ELScalar["Number"] = "number";
8
- ELScalar["String"] = "string";
9
- ELScalar["Null"] = "null";
10
- ELScalar["Any"] = "any";
11
- })(ELScalar || (ELScalar = {}));
12
-
13
- // @ts-ignore
14
- const t = {
15
- deserialize: (str) => str,
16
- };
17
-
18
- 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); };
19
- const resolveIdentifier = (nodeName, identifier, config) => {
20
- var _a;
21
- switch (nodeName) {
22
- case 'Method':
23
- case 'Function':
24
- return resolveCallable(identifier, config);
25
- case 'Property':
26
- case 'Variable':
27
- return (_a = config === null || config === void 0 ? void 0 : config.identifiers) === null || _a === void 0 ? void 0 : _a.find(x => x.name === identifier);
28
- }
29
- };
30
- function resolveTypes(state, node, config, matchExact) {
31
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
32
- let types = new Set();
33
- if (!node) {
34
- return types;
35
- }
36
- let type;
37
- if (typeof (type = node.type.prop(t)) !== "undefined") {
38
- types.add(type);
39
- }
40
- else if (node.name === 'Call' && node.firstChild && node.lastChild) {
41
- resolveTypes(state, node.firstChild, config).forEach(x => types.add(x));
42
- }
43
- else if (node.name === 'Variable') {
44
- const varName = state.sliceDoc(node.from, node.to) || '';
45
- // @ts-ignore
46
- (_b = (_a = resolveIdentifier(node.name, varName, config)) === null || _a === void 0 ? void 0 : _a.type) === null || _b === void 0 ? void 0 : _b.forEach((x) => types.add(x));
47
- }
48
- else if (node.name === 'Function') {
49
- const varName = state.sliceDoc(node.from, node.to) || '';
50
- // @ts-ignore
51
- (_d = (_c = resolveIdentifier(node.name, varName, config)) === null || _c === void 0 ? void 0 : _c.returnType) === null || _d === void 0 ? void 0 : _d.forEach((x) => types.add(x));
52
- }
53
- else if (node.name === 'ObjectAccess' && node.firstChild && ((_e = node.lastChild) === null || _e === void 0 ? void 0 : _e.name) === 'Property') {
54
- const varName = state.sliceDoc(node.lastChild.from, node.lastChild.to) || '';
55
- (_f = resolveTypes(state, node.firstChild, config)) === null || _f === void 0 ? void 0 : _f.forEach(baseType => {
56
- var _a, _b, _c, _d;
57
- // @ts-ignore
58
- (_d = (_c = resolveIdentifier((_a = node.lastChild) === null || _a === void 0 ? void 0 : _a.name, 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));
59
- });
60
- }
61
- else if (node.name === 'ObjectAccess' && node.firstChild && ((_g = node.lastChild) === null || _g === void 0 ? void 0 : _g.name) === 'Method') {
62
- const varName = state.sliceDoc(node.lastChild.from, node.lastChild.to) || '';
63
- (_h = resolveTypes(state, node.firstChild, config)) === null || _h === void 0 ? void 0 : _h.forEach(baseType => {
64
- var _a, _b, _c, _d;
65
- // @ts-ignore
66
- (_d = (_c = resolveIdentifier((_a = node.lastChild) === null || _a === void 0 ? void 0 : _a.name, 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));
67
- });
68
- }
69
- else if (node.name === 'Application' && node.firstChild) {
70
- resolveTypes(state, node.firstChild, config).forEach(x => types.add(x));
71
- }
72
- else if (node.name === 'TernaryExpression' && node.firstChild && node.firstChild.nextSibling && node.firstChild.nextSibling.nextSibling) {
73
- resolveTypes(state, node.firstChild.nextSibling, config).forEach(x => types.add(x));
74
- resolveTypes(state, node.firstChild.nextSibling.nextSibling, config).forEach(x => types.add(x));
75
- }
76
- else if (node.name === '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)) {
77
- const operator = state.sliceDoc(node.firstChild.nextSibling.from, node.firstChild.nextSibling.to);
78
- if (operator == '?:' || operator == '??' || operator == '?') {
79
- if (operator == '?:' || operator == '??') {
80
- resolveTypes(state, node.firstChild, config).forEach(x => types.add(x));
81
- }
82
- resolveTypes(state, node.firstChild.nextSibling.nextSibling, config).forEach(x => types.add(x));
83
- }
84
- else if (['||', '&&', '==', '!=', '===', '!==', '>=', '<=', '>', '<'].includes(operator) || keywords.find(x => x.name == operator)) {
85
- types.add(ELScalar.Bool);
86
- }
87
- else if (['**', '|', '^', '&', '<<', '>>', '+', '-', '*', '/', '%'].includes(operator)) {
88
- types.add(ELScalar.Number);
89
- }
90
- }
91
- else if (node.name === 'UnaryExpression' && node.firstChild) {
92
- const operator = state.sliceDoc(node.firstChild.from, node.firstChild.to);
93
- if (['not', '!'].includes(operator)) {
94
- types.add(ELScalar.Bool);
95
- }
96
- else if (['+', '-'].includes(operator)) {
97
- types.add(ELScalar.Number);
98
- }
99
- }
100
- if (types.size === 0) {
101
- types.add(ELScalar.Any);
102
- }
103
- return types;
104
- }
105
- function getExpressionLanguageConfig(state) {
106
- return state.languageDataAt('expressionLanguageConfig', 0)[0];
107
- }
108
- const keywords = [
109
- { name: 'starts with', info: 'Check if a string starts with a specific string' },
110
- { name: 'ends with', info: 'Check if a string ends with a specific string' },
111
- { name: 'contains', info: 'Check if a string is not included in another string' },
112
- { name: 'matches', info: 'Check if a string matches a regex pattern' },
113
- { name: 'not in', info: 'Check if a value is not included in an array' },
114
- { name: 'in', info: 'Check if a value is included in an array' },
115
- { name: 'not' },
116
- { name: 'or' },
117
- { name: 'and' },
118
- { name: 'xor' },
119
- ];
120
-
121
- const autocompleteFunction = (x) => {
122
- var _a, _b, _c;
123
- return ({
124
- 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(',')) || ''})`,
125
- apply: (view, completion, from, to) => {
126
- var _a;
127
- 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) } }));
128
- },
129
- detail: (_c = x.returnType) === null || _c === void 0 ? void 0 : _c.join('|'),
130
- info: x.info,
131
- type: "function",
132
- });
133
- };
134
- const autocompleteIdentifier = (x) => {
135
- var _a;
136
- return ({
137
- label: x.name,
138
- apply: x.name,
139
- info: x.info,
140
- detail: x.detail || ((_a = x.type) === null || _a === void 0 ? void 0 : _a.join('|')),
141
- type: 'variable',
142
- });
143
- };
144
- function completeOperatorKeyword(state, config, tree, from, to, explicit) {
145
- var _a;
146
- return {
147
- from,
148
- to,
149
- options: (_a = keywords.map(({ name, info, detail }) => ({
150
- label: name,
151
- apply: `${name} `,
152
- info: info,
153
- detail,
154
- type: "keyword"
155
- }))) !== null && _a !== void 0 ? _a : [],
156
- validFor: (text) => { var _a; return (_a = keywords.some(({ name }) => explicit || name.includes(text))) !== null && _a !== void 0 ? _a : false; },
157
- };
158
- }
159
- function completeIdentifier(state, config, tree, from, to) {
160
- var _a, _b;
161
- const identifiers = (_a = config.identifiers) !== null && _a !== void 0 ? _a : []; //?.filter(({ name }) => explicit || name.toLowerCase().startsWith(text)) ?? [];
162
- const functions = (_b = config.functions) !== null && _b !== void 0 ? _b : []; //?.filter(({ name }) => explicit || name.toLowerCase().startsWith(text)) ?? [];
163
- return {
164
- from,
165
- to,
166
- options: [...(identifiers.map(autocompleteIdentifier)), ...(functions.map(autocompleteFunction))],
167
- validFor: /^[a-zA-Z_]+[a-zA-Z_0-9]*$/,
168
- };
169
- }
170
- function completeMember(state, config, tree, from, to, explicit) {
171
- var _a, _b, _c, _d;
172
- if (((_a = tree.parent) === null || _a === void 0 ? void 0 : _a.name) != 'ObjectAccess' || !tree.parent.firstChild) {
173
- return null;
174
- }
175
- const types = resolveTypes(state, tree.parent.firstChild.node, config);
176
- if (!(types === null || types === void 0 ? void 0 : types.size)) {
177
- return null;
178
- }
179
- let options = [];
180
- for (const type of types) {
181
- const typeDeclaration = (_b = config.types) === null || _b === void 0 ? void 0 : _b[type];
182
- options.push(...(((_c = typeDeclaration === null || typeDeclaration === void 0 ? void 0 : typeDeclaration.identifiers) === null || _c === void 0 ? void 0 : _c.map(autocompleteIdentifier)) || []), ...(((_d = typeDeclaration === null || typeDeclaration === void 0 ? void 0 : typeDeclaration.functions) === null || _d === void 0 ? void 0 : _d.map(autocompleteFunction)) || []));
183
- }
184
- return {
185
- from,
186
- to,
187
- options,
188
- validFor: /^[a-zA-Z_]+[a-zA-Z_0-9]*$/,
189
- };
190
- }
191
- function expressionLanguageCompletion(context) {
192
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
193
- const { state, pos, explicit } = context;
194
- const tree = syntaxTree(state);
195
- const lastChar = state.sliceDoc(pos - 1, pos);
196
- const prevNode = tree.resolveInner(pos, lastChar === ')' ? 0 : -1);
197
- const config = getExpressionLanguageConfig(state);
198
- const isIdentifier = (node) => { var _a; return ['Variable', 'Function'].includes((_a = node === null || node === void 0 ? void 0 : node.name) !== null && _a !== void 0 ? _a : ''); };
199
- const isMember = (node) => { var _a; return ['Property', 'Method'].includes((_a = node === null || node === void 0 ? void 0 : node.name) !== null && _a !== void 0 ? _a : ''); };
200
- if (prevNode.name == 'String' || prevNode.name == 'BlockComment') {
201
- return null;
202
- }
203
- if (((_a = prevNode.parent) === null || _a === void 0 ? void 0 : _a.name) == 'ObjectAccess' && ['ObjectAccess', 'ArrayAccess', 'Variable', 'Call', 'Application'].includes(((_b = prevNode.parent.firstChild) === null || _b === void 0 ? void 0 : _b.name) || '')) {
204
- return completeMember(state, config, prevNode, isIdentifier(prevNode) || isMember(prevNode) ? prevNode.from : pos, pos);
205
- }
206
- if (['Expression', 'UnaryExpression', 'BinaryExpression', 'TernaryExpression'].includes(prevNode.name) && prevNode.lastChild && !((_c = prevNode.lastChild) === null || _c === void 0 ? void 0 : _c.type.isError)
207
- || ['Arguments', 'Array'].includes(prevNode.name) && prevNode.lastChild && !((_d = prevNode.lastChild) === null || _d === void 0 ? void 0 : _d.type.isError)
208
- || ['Expression', 'UnaryExpression', 'BinaryExpression', 'TernaryExpression'].includes((_f = (_e = prevNode.parent) === null || _e === void 0 ? void 0 : _e.name) !== null && _f !== void 0 ? _f : '') && prevNode.type.isError
209
- || ['Variable', 'Function'].includes((_h = (_g = prevNode.parent) === null || _g === void 0 ? void 0 : _g.name) !== null && _h !== void 0 ? _h : '') && prevNode.type.isError) {
210
- return completeOperatorKeyword(state, config, prevNode, !['Expression', 'UnaryExpression', 'BinaryExpression', 'TernaryExpression', 'Arguments'].includes(prevNode.name) ? prevNode.from : pos, pos, explicit);
211
- }
212
- if (!/[0-9]/.test(lastChar) && !['OperatorKeyword'].includes((_j = prevNode.name) !== null && _j !== void 0 ? _j : '') && (['Expression', 'UnaryExpression', 'BinaryExpression', 'TernaryExpression'].includes(prevNode.name) && ((_k = prevNode.lastChild) === null || _k === void 0 ? void 0 : _k.type.isError)
213
- || ['Expression', 'UnaryExpression', 'BinaryExpression', 'TernaryExpression', 'Arguments'].includes((_m = (_l = prevNode.parent) === null || _l === void 0 ? void 0 : _l.name) !== null && _m !== void 0 ? _m : '') && !prevNode.type.isError
214
- || ['Arguments', 'Array'].includes((_o = prevNode.name) !== null && _o !== void 0 ? _o : ''))) {
215
- return completeIdentifier(state, config, prevNode, isIdentifier(prevNode) ? prevNode.from : pos, pos);
216
- }
217
- return null;
218
- }
219
-
220
- export { expressionLanguageCompletion };