@valtzu/codemirror-lang-el 0.2.2 → 0.2.3
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/README.md +4 -4
- package/dist/index.cjs +35 -5
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +35 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"codemirror": "https://esm.sh/codemirror@6.0.1",
|
|
14
14
|
"@codemirror/autocomplete": "https://esm.sh/@codemirror/autocomplete@6.9.0",
|
|
15
15
|
"@codemirror/view": "https://esm.sh/@codemirror/view@6.17.1",
|
|
16
|
-
"@valtzu/codemirror-lang-el": "https://esm.sh/@valtzu/codemirror-lang-el@0.2.
|
|
16
|
+
"@valtzu/codemirror-lang-el": "https://esm.sh/@valtzu/codemirror-lang-el@0.2.3"
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
</script>
|
|
@@ -29,12 +29,12 @@ let editor = new EditorView({
|
|
|
29
29
|
keymap.of([{key: "Tab", run: acceptCompletion}]),
|
|
30
30
|
expressionlanguage({
|
|
31
31
|
identifiers: [
|
|
32
|
-
{ name: 'foo' },
|
|
32
|
+
{ name: 'foo', info: 'Foo is a variable' },
|
|
33
33
|
{ name: 'bar' }
|
|
34
34
|
],
|
|
35
35
|
functions: [
|
|
36
|
-
{name: 'smh'},
|
|
37
|
-
{name: 'smash_my_head', args: ['object']},
|
|
36
|
+
{ name: 'smh' },
|
|
37
|
+
{ name: 'smash_my_head', args: ['object'] },
|
|
38
38
|
],
|
|
39
39
|
})
|
|
40
40
|
],
|
package/dist/index.cjs
CHANGED
|
@@ -6,6 +6,7 @@ var lr = require('@lezer/lr');
|
|
|
6
6
|
var language = require('@codemirror/language');
|
|
7
7
|
var highlight = require('@lezer/highlight');
|
|
8
8
|
var lint = require('@codemirror/lint');
|
|
9
|
+
var view = require('@codemirror/view');
|
|
9
10
|
|
|
10
11
|
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
11
12
|
const parser = lr.LRParser.deserialize({
|
|
@@ -28,19 +29,18 @@ const parser = lr.LRParser.deserialize({
|
|
|
28
29
|
});
|
|
29
30
|
|
|
30
31
|
const identifier = /^[a-zA-Z_]+[a-zA-Z_0-9]*$/;
|
|
32
|
+
const isFunction = (identifier, config) => { var _a; return (_a = config.functions) === null || _a === void 0 ? void 0 : _a.find(fn => fn.name === identifier); };
|
|
33
|
+
const isVariable = (identifier, config) => { var _a; return (_a = config.identifiers) === null || _a === void 0 ? void 0 : _a.find(variable => variable.name === identifier); };
|
|
31
34
|
const expressionLanguageLinter = (config) => lint.linter(view => {
|
|
32
35
|
let diagnostics = [];
|
|
33
36
|
language.syntaxTree(view.state).cursor().iterate(node => {
|
|
34
|
-
var _a, _b;
|
|
35
37
|
if (node.name == "Identifier") {
|
|
36
38
|
const identifier = view.state.sliceDoc(node.from, node.to);
|
|
37
|
-
|
|
38
|
-
const isVariable = (_b = config.identifiers) === null || _b === void 0 ? void 0 : _b.filter(variable => variable.name === identifier);
|
|
39
|
-
if (!isFunction && !isVariable) {
|
|
39
|
+
if (!isFunction(identifier, config) && !isVariable(identifier, config)) {
|
|
40
40
|
diagnostics.push({
|
|
41
41
|
from: node.from,
|
|
42
42
|
to: node.to,
|
|
43
|
-
severity: '
|
|
43
|
+
severity: 'error',
|
|
44
44
|
message: `Identifier "${identifier}" not found`,
|
|
45
45
|
});
|
|
46
46
|
}
|
|
@@ -48,6 +48,34 @@ const expressionLanguageLinter = (config) => lint.linter(view => {
|
|
|
48
48
|
});
|
|
49
49
|
return diagnostics;
|
|
50
50
|
});
|
|
51
|
+
const keywordTooltip = (config) => view.hoverTooltip((view, pos, side) => {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
let { from, to, text } = view.state.doc.lineAt(pos);
|
|
54
|
+
let start = pos, end = pos;
|
|
55
|
+
while (start > from && /\w/.test(text[start - from - 1]))
|
|
56
|
+
start--;
|
|
57
|
+
while (end < to && /\w/.test(text[end - from]))
|
|
58
|
+
end++;
|
|
59
|
+
if (start == pos && side < 0 || end == pos && side > 0) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const keyword = text.slice(start - from, end - from);
|
|
63
|
+
const info = (_b = ((_a = isFunction(keyword, config)) !== null && _a !== void 0 ? _a : isVariable(keyword, config))) === null || _b === void 0 ? void 0 : _b.info;
|
|
64
|
+
if (!info) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
pos: start,
|
|
69
|
+
end,
|
|
70
|
+
above: true,
|
|
71
|
+
create(view) {
|
|
72
|
+
let dom = document.createElement("div");
|
|
73
|
+
dom.textContent = info;
|
|
74
|
+
dom.className = 'cm-diagnostic';
|
|
75
|
+
return { dom };
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
});
|
|
51
79
|
const ELLanguage = language.LRLanguage.define({
|
|
52
80
|
parser: parser.configure({
|
|
53
81
|
props: [
|
|
@@ -124,9 +152,11 @@ function expressionlanguage(config = {}, extensions = []) {
|
|
|
124
152
|
return new language.LanguageSupport(ELLanguage, [
|
|
125
153
|
ELLanguage.data.of({ autocomplete: expressionLanguageCompletionSourceWith(config) }),
|
|
126
154
|
expressionLanguageLinter(config),
|
|
155
|
+
keywordTooltip(config),
|
|
127
156
|
...extensions,
|
|
128
157
|
]);
|
|
129
158
|
}
|
|
130
159
|
|
|
131
160
|
exports.ELLanguage = ELLanguage;
|
|
132
161
|
exports.expressionlanguage = expressionlanguage;
|
|
162
|
+
exports.keywordTooltip = keywordTooltip;
|
package/dist/index.d.cts
CHANGED
|
@@ -12,6 +12,7 @@ interface ExpressionLanguageConfig {
|
|
|
12
12
|
}[];
|
|
13
13
|
operatorKeywords?: readonly string[];
|
|
14
14
|
}
|
|
15
|
+
declare const keywordTooltip: (config: ExpressionLanguageConfig) => import("@codemirror/state").Extension;
|
|
15
16
|
declare const ELLanguage: LRLanguage;
|
|
16
17
|
declare function expressionlanguage(config?: ExpressionLanguageConfig, extensions?: Array<any>): LanguageSupport;
|
|
17
|
-
export { ExpressionLanguageConfig, ELLanguage, expressionlanguage };
|
|
18
|
+
export { ExpressionLanguageConfig, keywordTooltip, ELLanguage, expressionlanguage };
|
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ interface ExpressionLanguageConfig {
|
|
|
12
12
|
}[];
|
|
13
13
|
operatorKeywords?: readonly string[];
|
|
14
14
|
}
|
|
15
|
+
declare const keywordTooltip: (config: ExpressionLanguageConfig) => import("@codemirror/state").Extension;
|
|
15
16
|
declare const ELLanguage: LRLanguage;
|
|
16
17
|
declare function expressionlanguage(config?: ExpressionLanguageConfig, extensions?: Array<any>): LanguageSupport;
|
|
17
|
-
export { ExpressionLanguageConfig, ELLanguage, expressionlanguage };
|
|
18
|
+
export { ExpressionLanguageConfig, keywordTooltip, ELLanguage, expressionlanguage };
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import { LRParser } from '@lezer/lr';
|
|
|
2
2
|
import { LRLanguage, indentNodeProp, delimitedIndent, foldNodeProp, foldInside, LanguageSupport, syntaxTree } from '@codemirror/language';
|
|
3
3
|
import { styleTags, tags } from '@lezer/highlight';
|
|
4
4
|
import { linter } from '@codemirror/lint';
|
|
5
|
+
import { hoverTooltip } from '@codemirror/view';
|
|
5
6
|
|
|
6
7
|
// This file was generated by lezer-generator. You probably shouldn't edit it.
|
|
7
8
|
const parser = LRParser.deserialize({
|
|
@@ -24,19 +25,18 @@ const parser = LRParser.deserialize({
|
|
|
24
25
|
});
|
|
25
26
|
|
|
26
27
|
const identifier = /^[a-zA-Z_]+[a-zA-Z_0-9]*$/;
|
|
28
|
+
const isFunction = (identifier, config) => { var _a; return (_a = config.functions) === null || _a === void 0 ? void 0 : _a.find(fn => fn.name === identifier); };
|
|
29
|
+
const isVariable = (identifier, config) => { var _a; return (_a = config.identifiers) === null || _a === void 0 ? void 0 : _a.find(variable => variable.name === identifier); };
|
|
27
30
|
const expressionLanguageLinter = (config) => linter(view => {
|
|
28
31
|
let diagnostics = [];
|
|
29
32
|
syntaxTree(view.state).cursor().iterate(node => {
|
|
30
|
-
var _a, _b;
|
|
31
33
|
if (node.name == "Identifier") {
|
|
32
34
|
const identifier = view.state.sliceDoc(node.from, node.to);
|
|
33
|
-
|
|
34
|
-
const isVariable = (_b = config.identifiers) === null || _b === void 0 ? void 0 : _b.filter(variable => variable.name === identifier);
|
|
35
|
-
if (!isFunction && !isVariable) {
|
|
35
|
+
if (!isFunction(identifier, config) && !isVariable(identifier, config)) {
|
|
36
36
|
diagnostics.push({
|
|
37
37
|
from: node.from,
|
|
38
38
|
to: node.to,
|
|
39
|
-
severity: '
|
|
39
|
+
severity: 'error',
|
|
40
40
|
message: `Identifier "${identifier}" not found`,
|
|
41
41
|
});
|
|
42
42
|
}
|
|
@@ -44,6 +44,34 @@ const expressionLanguageLinter = (config) => linter(view => {
|
|
|
44
44
|
});
|
|
45
45
|
return diagnostics;
|
|
46
46
|
});
|
|
47
|
+
const keywordTooltip = (config) => hoverTooltip((view, pos, side) => {
|
|
48
|
+
var _a, _b;
|
|
49
|
+
let { from, to, text } = view.state.doc.lineAt(pos);
|
|
50
|
+
let start = pos, end = pos;
|
|
51
|
+
while (start > from && /\w/.test(text[start - from - 1]))
|
|
52
|
+
start--;
|
|
53
|
+
while (end < to && /\w/.test(text[end - from]))
|
|
54
|
+
end++;
|
|
55
|
+
if (start == pos && side < 0 || end == pos && side > 0) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
const keyword = text.slice(start - from, end - from);
|
|
59
|
+
const info = (_b = ((_a = isFunction(keyword, config)) !== null && _a !== void 0 ? _a : isVariable(keyword, config))) === null || _b === void 0 ? void 0 : _b.info;
|
|
60
|
+
if (!info) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
pos: start,
|
|
65
|
+
end,
|
|
66
|
+
above: true,
|
|
67
|
+
create(view) {
|
|
68
|
+
let dom = document.createElement("div");
|
|
69
|
+
dom.textContent = info;
|
|
70
|
+
dom.className = 'cm-diagnostic';
|
|
71
|
+
return { dom };
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
});
|
|
47
75
|
const ELLanguage = LRLanguage.define({
|
|
48
76
|
parser: parser.configure({
|
|
49
77
|
props: [
|
|
@@ -120,8 +148,9 @@ function expressionlanguage(config = {}, extensions = []) {
|
|
|
120
148
|
return new LanguageSupport(ELLanguage, [
|
|
121
149
|
ELLanguage.data.of({ autocomplete: expressionLanguageCompletionSourceWith(config) }),
|
|
122
150
|
expressionLanguageLinter(config),
|
|
151
|
+
keywordTooltip(config),
|
|
123
152
|
...extensions,
|
|
124
153
|
]);
|
|
125
154
|
}
|
|
126
155
|
|
|
127
|
-
export { ELLanguage, expressionlanguage };
|
|
156
|
+
export { ELLanguage, expressionlanguage, keywordTooltip };
|
package/package.json
CHANGED