@valtzu/codemirror-lang-el 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/tooltip.cjs DELETED
@@ -1,258 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var state = require('@codemirror/state');
6
- var view = require('@codemirror/view');
7
- var language = require('@codemirror/language');
8
-
9
- var ELScalar;
10
- (function (ELScalar) {
11
- ELScalar["Bool"] = "bool";
12
- ELScalar["Number"] = "number";
13
- ELScalar["String"] = "string";
14
- ELScalar["Null"] = "null";
15
- ELScalar["Any"] = "any";
16
- })(ELScalar || (ELScalar = {}));
17
-
18
- // @ts-ignore
19
- const t = {
20
- deserialize: (str) => str,
21
- };
22
-
23
- const createInfoElement = (html) => {
24
- const dom = document.createElement("div");
25
- dom.innerHTML = html;
26
- dom.className = 'cm-diagnostic';
27
- return dom;
28
- };
29
- function resolveFunctionDefinition(node, state, config) {
30
- var _a;
31
- if (!node) {
32
- return undefined;
33
- }
34
- let identifier;
35
- if (node.name === 'ObjectAccess' && node.lastChild) {
36
- const leftArgument = (_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.node;
37
- const types = Array.from(resolveTypes(state, leftArgument, config));
38
- identifier = state.sliceDoc(node.lastChild.from, node.lastChild.to);
39
- return types.map(type => { var _a; return resolveCallable(identifier, (_a = config.types) === null || _a === void 0 ? void 0 : _a[type]); }).find(x => x);
40
- }
41
- else if (node.name === 'Function') {
42
- identifier = state.sliceDoc(node.from, node.node.firstChild ? node.node.firstChild.from - 1 : node.to);
43
- return resolveCallable(identifier, config);
44
- }
45
- }
46
- 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); };
47
- const resolveIdentifier = (nodeName, identifier, config) => {
48
- var _a;
49
- switch (nodeName) {
50
- case 'Method':
51
- case 'Function':
52
- return resolveCallable(identifier, config);
53
- case 'Property':
54
- case 'Variable':
55
- return (_a = config === null || config === void 0 ? void 0 : config.identifiers) === null || _a === void 0 ? void 0 : _a.find(x => x.name === identifier);
56
- }
57
- };
58
- function resolveTypes(state, node, config, matchExact) {
59
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
60
- let types = new Set();
61
- if (!node) {
62
- return types;
63
- }
64
- let type;
65
- if (typeof (type = node.type.prop(t)) !== "undefined") {
66
- types.add(type);
67
- }
68
- else if (node.name === 'Call' && node.firstChild && node.lastChild) {
69
- resolveTypes(state, node.firstChild, config).forEach(x => types.add(x));
70
- }
71
- else if (node.name === 'Variable') {
72
- const varName = state.sliceDoc(node.from, node.to) || '';
73
- // @ts-ignore
74
- (_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));
75
- }
76
- else if (node.name === 'Function') {
77
- const varName = state.sliceDoc(node.from, node.to) || '';
78
- // @ts-ignore
79
- (_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));
80
- }
81
- else if (node.name === 'ObjectAccess' && node.firstChild && ((_e = node.lastChild) === null || _e === void 0 ? void 0 : _e.name) === 'Property') {
82
- const varName = state.sliceDoc(node.lastChild.from, node.lastChild.to) || '';
83
- (_f = resolveTypes(state, node.firstChild, config)) === null || _f === void 0 ? void 0 : _f.forEach(baseType => {
84
- var _a, _b, _c, _d;
85
- // @ts-ignore
86
- (_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));
87
- });
88
- }
89
- else if (node.name === 'ObjectAccess' && node.firstChild && ((_g = node.lastChild) === null || _g === void 0 ? void 0 : _g.name) === 'Method') {
90
- const varName = state.sliceDoc(node.lastChild.from, node.lastChild.to) || '';
91
- (_h = resolveTypes(state, node.firstChild, config)) === null || _h === void 0 ? void 0 : _h.forEach(baseType => {
92
- var _a, _b, _c, _d;
93
- // @ts-ignore
94
- (_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));
95
- });
96
- }
97
- else if (node.name === 'Application' && node.firstChild) {
98
- resolveTypes(state, node.firstChild, config).forEach(x => types.add(x));
99
- }
100
- else if (node.name === 'TernaryExpression' && node.firstChild && node.firstChild.nextSibling && node.firstChild.nextSibling.nextSibling) {
101
- resolveTypes(state, node.firstChild.nextSibling, config).forEach(x => types.add(x));
102
- resolveTypes(state, node.firstChild.nextSibling.nextSibling, config).forEach(x => types.add(x));
103
- }
104
- 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)) {
105
- const operator = state.sliceDoc(node.firstChild.nextSibling.from, node.firstChild.nextSibling.to);
106
- if (operator == '?:' || operator == '??' || operator == '?') {
107
- if (operator == '?:' || operator == '??') {
108
- resolveTypes(state, node.firstChild, config).forEach(x => types.add(x));
109
- }
110
- resolveTypes(state, node.firstChild.nextSibling.nextSibling, config).forEach(x => types.add(x));
111
- }
112
- else if (['||', '&&', '==', '!=', '===', '!==', '>=', '<=', '>', '<'].includes(operator) || keywords.find(x => x.name == operator)) {
113
- types.add(ELScalar.Bool);
114
- }
115
- else if (['**', '|', '^', '&', '<<', '>>', '+', '-', '*', '/', '%'].includes(operator)) {
116
- types.add(ELScalar.Number);
117
- }
118
- }
119
- else if (node.name === 'UnaryExpression' && node.firstChild) {
120
- const operator = state.sliceDoc(node.firstChild.from, node.firstChild.to);
121
- if (['not', '!'].includes(operator)) {
122
- types.add(ELScalar.Bool);
123
- }
124
- else if (['+', '-'].includes(operator)) {
125
- types.add(ELScalar.Number);
126
- }
127
- }
128
- if (types.size === 0) {
129
- types.add(ELScalar.Any);
130
- }
131
- return types;
132
- }
133
- function getExpressionLanguageConfig(state) {
134
- return state.languageDataAt('expressionLanguageConfig', 0)[0];
135
- }
136
- const keywords = [
137
- { name: 'starts with', info: 'Check if a string starts with a specific string' },
138
- { name: 'ends with', info: 'Check if a string ends with a specific string' },
139
- { name: 'contains', info: 'Check if a string is not included in another string' },
140
- { name: 'matches', info: 'Check if a string matches a regex pattern' },
141
- { name: 'not in', info: 'Check if a value is not included in an array' },
142
- { name: 'in', info: 'Check if a value is included in an array' },
143
- { name: 'not' },
144
- { name: 'or' },
145
- { name: 'and' },
146
- { name: 'xor' },
147
- ];
148
-
149
- function getNodeOrdinal(node) {
150
- let ordinal = -1;
151
- // noinspection StatementWithEmptyBodyJS
152
- for (let c = node; c; c = c.prevSibling, ordinal++)
153
- ;
154
- return ordinal;
155
- }
156
- function resolveArguments(node) {
157
- let c = node;
158
- while (c && c.name !== 'Arguments') {
159
- c = c.parent;
160
- }
161
- return c;
162
- }
163
- function getCursorTooltips(state) {
164
- const config = getExpressionLanguageConfig(state);
165
- // @ts-ignore
166
- return state.selection.ranges
167
- .filter(range => range.empty)
168
- .map(range => {
169
- var _a, _b;
170
- const tree = language.syntaxTree(state);
171
- const node = tree.resolveInner(range.from, 0);
172
- const args = resolveArguments(node);
173
- if (!args || !args.prevSibling) {
174
- return null;
175
- }
176
- const fn = resolveFunctionDefinition(args.prevSibling, state, config);
177
- if (!fn) {
178
- return null;
179
- }
180
- const n = args.childAfter(range.from - 1);
181
- 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;
182
- if (n && n.from !== range.from || !argName) {
183
- return null;
184
- }
185
- return {
186
- pos: range.head,
187
- above: true,
188
- strictSide: false,
189
- arrow: true,
190
- create: () => {
191
- let dom = document.createElement("div");
192
- dom.className = "cm-tooltip-cursor";
193
- dom.textContent = `${argName}`;
194
- return { dom };
195
- },
196
- };
197
- }).filter(x => x);
198
- }
199
- const cursorTooltipField = state.StateField.define({
200
- create: (state) => getCursorTooltips(state),
201
- update(tooltips, tr) {
202
- if (!tr.docChanged && !tr.selection) {
203
- return tooltips;
204
- }
205
- return getCursorTooltips(tr.state);
206
- },
207
- provide: f => view.showTooltip.computeN([f], state => state.field(f))
208
- });
209
- const keywordTooltip = view.hoverTooltip((view, pos, side) => {
210
- var _a, _b, _c, _d, _e, _f, _g;
211
- const config = getExpressionLanguageConfig(view.state);
212
- const tree = language.syntaxTree(view.state).resolveInner(pos, side);
213
- if (tree.name === 'OperatorKeyword') {
214
- const name = view.state.sliceDoc(tree.from, tree.to);
215
- const info = (_a = keywords.find(x => x.name === name)) === null || _a === void 0 ? void 0 : _a.info;
216
- if (info) {
217
- return {
218
- pos: tree.from,
219
- end: tree.to,
220
- above: true,
221
- create: () => ({ dom: createInfoElement(info) }),
222
- };
223
- }
224
- }
225
- if (!['Function', 'Variable', 'Method', 'Property'].includes(tree.name)) {
226
- return null;
227
- }
228
- const skipEmpty = (x) => x;
229
- let info;
230
- if (((_b = tree.parent) === null || _b === void 0 ? void 0 : _b.firstChild) && ((_c = tree.parent) === null || _c === void 0 ? void 0 : _c.name) === 'ObjectAccess' && tree.prevSibling) {
231
- const node = tree.parent.firstChild;
232
- const types = Array.from(resolveTypes(view.state, node, config));
233
- const name = view.state.sliceDoc(tree.from, tree.to);
234
- info = [
235
- ...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),
236
- ...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),
237
- ].join('\n');
238
- }
239
- else {
240
- const name = view.state.sliceDoc(tree.from, tree.to);
241
- info = [
242
- ...[(_e = (_d = config.identifiers) === null || _d === void 0 ? void 0 : _d.find(x => x.name === name)) === null || _e === void 0 ? void 0 : _e.info].filter(skipEmpty),
243
- ...[(_g = (_f = config.functions) === null || _f === void 0 ? void 0 : _f.find(x => x.name === name)) === null || _g === void 0 ? void 0 : _g.info].filter(skipEmpty),
244
- ].join('\n');
245
- }
246
- if (!info) {
247
- return null;
248
- }
249
- return {
250
- pos: tree.from,
251
- end: tree.to,
252
- above: true,
253
- create: () => ({ dom: createInfoElement(info) }),
254
- };
255
- });
256
-
257
- exports.cursorTooltipField = cursorTooltipField;
258
- exports.keywordTooltip = keywordTooltip;
@@ -1,7 +0,0 @@
1
- import { StateField } from "@codemirror/state";
2
- import { Tooltip } from "@codemirror/view";
3
- declare const cursorTooltipField: StateField<readonly Tooltip[]>;
4
- declare const keywordTooltip: import("@codemirror/state").Extension & {
5
- active: StateField<readonly Tooltip[]>;
6
- };
7
- export { cursorTooltipField, keywordTooltip };
package/dist/tooltip.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import { StateField } from "@codemirror/state";
2
- import { Tooltip } from "@codemirror/view";
3
- declare const cursorTooltipField: StateField<readonly Tooltip[]>;
4
- declare const keywordTooltip: import("@codemirror/state").Extension & {
5
- active: StateField<readonly Tooltip[]>;
6
- };
7
- export { cursorTooltipField, keywordTooltip };
package/dist/tooltip.js DELETED
@@ -1,253 +0,0 @@
1
- import { StateField } from '@codemirror/state';
2
- import { showTooltip, hoverTooltip } from '@codemirror/view';
3
- import { syntaxTree } from '@codemirror/language';
4
-
5
- var ELScalar;
6
- (function (ELScalar) {
7
- ELScalar["Bool"] = "bool";
8
- ELScalar["Number"] = "number";
9
- ELScalar["String"] = "string";
10
- ELScalar["Null"] = "null";
11
- ELScalar["Any"] = "any";
12
- })(ELScalar || (ELScalar = {}));
13
-
14
- // @ts-ignore
15
- const t = {
16
- deserialize: (str) => str,
17
- };
18
-
19
- const createInfoElement = (html) => {
20
- const dom = document.createElement("div");
21
- dom.innerHTML = html;
22
- dom.className = 'cm-diagnostic';
23
- return dom;
24
- };
25
- function resolveFunctionDefinition(node, state, config) {
26
- var _a;
27
- if (!node) {
28
- return undefined;
29
- }
30
- let identifier;
31
- if (node.name === 'ObjectAccess' && node.lastChild) {
32
- const leftArgument = (_a = node.firstChild) === null || _a === void 0 ? void 0 : _a.node;
33
- const types = Array.from(resolveTypes(state, leftArgument, config));
34
- identifier = state.sliceDoc(node.lastChild.from, node.lastChild.to);
35
- return types.map(type => { var _a; return resolveCallable(identifier, (_a = config.types) === null || _a === void 0 ? void 0 : _a[type]); }).find(x => x);
36
- }
37
- else if (node.name === 'Function') {
38
- identifier = state.sliceDoc(node.from, node.node.firstChild ? node.node.firstChild.from - 1 : node.to);
39
- return resolveCallable(identifier, config);
40
- }
41
- }
42
- 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); };
43
- const resolveIdentifier = (nodeName, identifier, config) => {
44
- var _a;
45
- switch (nodeName) {
46
- case 'Method':
47
- case 'Function':
48
- return resolveCallable(identifier, config);
49
- case 'Property':
50
- case 'Variable':
51
- return (_a = config === null || config === void 0 ? void 0 : config.identifiers) === null || _a === void 0 ? void 0 : _a.find(x => x.name === identifier);
52
- }
53
- };
54
- function resolveTypes(state, node, config, matchExact) {
55
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
56
- let types = new Set();
57
- if (!node) {
58
- return types;
59
- }
60
- let type;
61
- if (typeof (type = node.type.prop(t)) !== "undefined") {
62
- types.add(type);
63
- }
64
- else if (node.name === 'Call' && node.firstChild && node.lastChild) {
65
- resolveTypes(state, node.firstChild, config).forEach(x => types.add(x));
66
- }
67
- else if (node.name === 'Variable') {
68
- const varName = state.sliceDoc(node.from, node.to) || '';
69
- // @ts-ignore
70
- (_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));
71
- }
72
- else if (node.name === 'Function') {
73
- const varName = state.sliceDoc(node.from, node.to) || '';
74
- // @ts-ignore
75
- (_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));
76
- }
77
- else if (node.name === 'ObjectAccess' && node.firstChild && ((_e = node.lastChild) === null || _e === void 0 ? void 0 : _e.name) === 'Property') {
78
- const varName = state.sliceDoc(node.lastChild.from, node.lastChild.to) || '';
79
- (_f = resolveTypes(state, node.firstChild, config)) === null || _f === void 0 ? void 0 : _f.forEach(baseType => {
80
- var _a, _b, _c, _d;
81
- // @ts-ignore
82
- (_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));
83
- });
84
- }
85
- else if (node.name === 'ObjectAccess' && node.firstChild && ((_g = node.lastChild) === null || _g === void 0 ? void 0 : _g.name) === 'Method') {
86
- const varName = state.sliceDoc(node.lastChild.from, node.lastChild.to) || '';
87
- (_h = resolveTypes(state, node.firstChild, config)) === null || _h === void 0 ? void 0 : _h.forEach(baseType => {
88
- var _a, _b, _c, _d;
89
- // @ts-ignore
90
- (_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));
91
- });
92
- }
93
- else if (node.name === 'Application' && node.firstChild) {
94
- resolveTypes(state, node.firstChild, config).forEach(x => types.add(x));
95
- }
96
- else if (node.name === 'TernaryExpression' && node.firstChild && node.firstChild.nextSibling && node.firstChild.nextSibling.nextSibling) {
97
- resolveTypes(state, node.firstChild.nextSibling, config).forEach(x => types.add(x));
98
- resolveTypes(state, node.firstChild.nextSibling.nextSibling, config).forEach(x => types.add(x));
99
- }
100
- 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)) {
101
- const operator = state.sliceDoc(node.firstChild.nextSibling.from, node.firstChild.nextSibling.to);
102
- if (operator == '?:' || operator == '??' || operator == '?') {
103
- if (operator == '?:' || operator == '??') {
104
- resolveTypes(state, node.firstChild, config).forEach(x => types.add(x));
105
- }
106
- resolveTypes(state, node.firstChild.nextSibling.nextSibling, config).forEach(x => types.add(x));
107
- }
108
- else if (['||', '&&', '==', '!=', '===', '!==', '>=', '<=', '>', '<'].includes(operator) || keywords.find(x => x.name == operator)) {
109
- types.add(ELScalar.Bool);
110
- }
111
- else if (['**', '|', '^', '&', '<<', '>>', '+', '-', '*', '/', '%'].includes(operator)) {
112
- types.add(ELScalar.Number);
113
- }
114
- }
115
- else if (node.name === 'UnaryExpression' && node.firstChild) {
116
- const operator = state.sliceDoc(node.firstChild.from, node.firstChild.to);
117
- if (['not', '!'].includes(operator)) {
118
- types.add(ELScalar.Bool);
119
- }
120
- else if (['+', '-'].includes(operator)) {
121
- types.add(ELScalar.Number);
122
- }
123
- }
124
- if (types.size === 0) {
125
- types.add(ELScalar.Any);
126
- }
127
- return types;
128
- }
129
- function getExpressionLanguageConfig(state) {
130
- return state.languageDataAt('expressionLanguageConfig', 0)[0];
131
- }
132
- const keywords = [
133
- { name: 'starts with', info: 'Check if a string starts with a specific string' },
134
- { name: 'ends with', info: 'Check if a string ends with a specific string' },
135
- { name: 'contains', info: 'Check if a string is not included in another string' },
136
- { name: 'matches', info: 'Check if a string matches a regex pattern' },
137
- { name: 'not in', info: 'Check if a value is not included in an array' },
138
- { name: 'in', info: 'Check if a value is included in an array' },
139
- { name: 'not' },
140
- { name: 'or' },
141
- { name: 'and' },
142
- { name: 'xor' },
143
- ];
144
-
145
- function getNodeOrdinal(node) {
146
- let ordinal = -1;
147
- // noinspection StatementWithEmptyBodyJS
148
- for (let c = node; c; c = c.prevSibling, ordinal++)
149
- ;
150
- return ordinal;
151
- }
152
- function resolveArguments(node) {
153
- let c = node;
154
- while (c && c.name !== 'Arguments') {
155
- c = c.parent;
156
- }
157
- return c;
158
- }
159
- function getCursorTooltips(state) {
160
- const config = getExpressionLanguageConfig(state);
161
- // @ts-ignore
162
- return state.selection.ranges
163
- .filter(range => range.empty)
164
- .map(range => {
165
- var _a, _b;
166
- const tree = syntaxTree(state);
167
- const node = tree.resolveInner(range.from, 0);
168
- const args = resolveArguments(node);
169
- if (!args || !args.prevSibling) {
170
- return null;
171
- }
172
- const fn = resolveFunctionDefinition(args.prevSibling, state, config);
173
- if (!fn) {
174
- return null;
175
- }
176
- const n = args.childAfter(range.from - 1);
177
- 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;
178
- if (n && n.from !== range.from || !argName) {
179
- return null;
180
- }
181
- return {
182
- pos: range.head,
183
- above: true,
184
- strictSide: false,
185
- arrow: true,
186
- create: () => {
187
- let dom = document.createElement("div");
188
- dom.className = "cm-tooltip-cursor";
189
- dom.textContent = `${argName}`;
190
- return { dom };
191
- },
192
- };
193
- }).filter(x => x);
194
- }
195
- const cursorTooltipField = StateField.define({
196
- create: (state) => getCursorTooltips(state),
197
- update(tooltips, tr) {
198
- if (!tr.docChanged && !tr.selection) {
199
- return tooltips;
200
- }
201
- return getCursorTooltips(tr.state);
202
- },
203
- provide: f => showTooltip.computeN([f], state => state.field(f))
204
- });
205
- const keywordTooltip = hoverTooltip((view, pos, side) => {
206
- var _a, _b, _c, _d, _e, _f, _g;
207
- const config = getExpressionLanguageConfig(view.state);
208
- const tree = syntaxTree(view.state).resolveInner(pos, side);
209
- if (tree.name === 'OperatorKeyword') {
210
- const name = view.state.sliceDoc(tree.from, tree.to);
211
- const info = (_a = keywords.find(x => x.name === name)) === null || _a === void 0 ? void 0 : _a.info;
212
- if (info) {
213
- return {
214
- pos: tree.from,
215
- end: tree.to,
216
- above: true,
217
- create: () => ({ dom: createInfoElement(info) }),
218
- };
219
- }
220
- }
221
- if (!['Function', 'Variable', 'Method', 'Property'].includes(tree.name)) {
222
- return null;
223
- }
224
- const skipEmpty = (x) => x;
225
- let info;
226
- if (((_b = tree.parent) === null || _b === void 0 ? void 0 : _b.firstChild) && ((_c = tree.parent) === null || _c === void 0 ? void 0 : _c.name) === 'ObjectAccess' && tree.prevSibling) {
227
- const node = tree.parent.firstChild;
228
- const types = Array.from(resolveTypes(view.state, node, config));
229
- const name = view.state.sliceDoc(tree.from, tree.to);
230
- info = [
231
- ...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),
232
- ...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),
233
- ].join('\n');
234
- }
235
- else {
236
- const name = view.state.sliceDoc(tree.from, tree.to);
237
- info = [
238
- ...[(_e = (_d = config.identifiers) === null || _d === void 0 ? void 0 : _d.find(x => x.name === name)) === null || _e === void 0 ? void 0 : _e.info].filter(skipEmpty),
239
- ...[(_g = (_f = config.functions) === null || _f === void 0 ? void 0 : _f.find(x => x.name === name)) === null || _g === void 0 ? void 0 : _g.info].filter(skipEmpty),
240
- ].join('\n');
241
- }
242
- if (!info) {
243
- return null;
244
- }
245
- return {
246
- pos: tree.from,
247
- end: tree.to,
248
- above: true,
249
- create: () => ({ dom: createInfoElement(info) }),
250
- };
251
- });
252
-
253
- export { cursorTooltipField, keywordTooltip };