@valtzu/codemirror-lang-el 0.2.1 → 0.2.2

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 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.1.13"
16
+ "@valtzu/codemirror-lang-el": "https://esm.sh/@valtzu/codemirror-lang-el@0.2.1"
17
17
  }
18
18
  }
19
19
  </script>
@@ -27,7 +27,16 @@ let editor = new EditorView({
27
27
  extensions: [
28
28
  basicSetup,
29
29
  keymap.of([{key: "Tab", run: acceptCompletion}]),
30
- expressionlanguage({ identifiers: ['foo', 'bar'], functions: {'smh': [], smash_my_head: ['object']} })
30
+ expressionlanguage({
31
+ identifiers: [
32
+ { name: 'foo' },
33
+ { name: 'bar' }
34
+ ],
35
+ functions: [
36
+ {name: 'smh'},
37
+ {name: 'smash_my_head', args: ['object']},
38
+ ],
39
+ })
31
40
  ],
32
41
  parent: document.getElementById('editor'),
33
42
  });
package/dist/index.cjs CHANGED
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var lr = require('@lezer/lr');
6
6
  var language = require('@codemirror/language');
7
7
  var highlight = require('@lezer/highlight');
8
+ var lint = require('@codemirror/lint');
8
9
 
9
10
  // This file was generated by lezer-generator. You probably shouldn't edit it.
10
11
  const parser = lr.LRParser.deserialize({
@@ -27,6 +28,26 @@ const parser = lr.LRParser.deserialize({
27
28
  });
28
29
 
29
30
  const identifier = /^[a-zA-Z_]+[a-zA-Z_0-9]*$/;
31
+ const expressionLanguageLinter = (config) => lint.linter(view => {
32
+ let diagnostics = [];
33
+ language.syntaxTree(view.state).cursor().iterate(node => {
34
+ var _a, _b;
35
+ if (node.name == "Identifier") {
36
+ const identifier = view.state.sliceDoc(node.from, node.to);
37
+ const isFunction = (_a = config.functions) === null || _a === void 0 ? void 0 : _a.find(fn => fn.name === identifier);
38
+ const isVariable = (_b = config.identifiers) === null || _b === void 0 ? void 0 : _b.filter(variable => variable.name === identifier);
39
+ if (!isFunction && !isVariable) {
40
+ diagnostics.push({
41
+ from: node.from,
42
+ to: node.to,
43
+ severity: 'warning',
44
+ message: `Identifier "${identifier}" not found`,
45
+ });
46
+ }
47
+ }
48
+ });
49
+ return diagnostics;
50
+ });
30
51
  const ELLanguage = language.LRLanguage.define({
31
52
  parser: parser.configure({
32
53
  props: [
@@ -86,7 +107,7 @@ function expressionLanguageCompletionFor(config, context) {
86
107
  if (tree.name == 'String') {
87
108
  return null;
88
109
  }
89
- if (tree.prevSibling && !['Operator', 'OperatorKeyword', 'Punctuation', 'NullSafe', 'NullCoalescing'].includes(tree.prevSibling.name)) {
110
+ if (tree.prevSibling && !['Operator', 'OperatorKeyword', 'Punctuation', 'NullSafe', 'NullCoalescing', 'OpeningBracket'].includes(tree.prevSibling.name)) {
90
111
  return completeOperatorKeyword(state, config, tree, tree.from, pos);
91
112
  }
92
113
  if (tree.name == "Identifier") {
@@ -100,7 +121,11 @@ function expressionLanguageCompletionSourceWith(config) {
100
121
  return (context) => expressionLanguageCompletionFor(config, context);
101
122
  }
102
123
  function expressionlanguage(config = {}, extensions = []) {
103
- return new language.LanguageSupport(ELLanguage, [ELLanguage.data.of({ autocomplete: expressionLanguageCompletionSourceWith(config) }), ...extensions]);
124
+ return new language.LanguageSupport(ELLanguage, [
125
+ ELLanguage.data.of({ autocomplete: expressionLanguageCompletionSourceWith(config) }),
126
+ expressionLanguageLinter(config),
127
+ ...extensions,
128
+ ]);
104
129
  }
105
130
 
106
131
  exports.ELLanguage = ELLanguage;
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  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
+ import { linter } from '@codemirror/lint';
4
5
 
5
6
  // This file was generated by lezer-generator. You probably shouldn't edit it.
6
7
  const parser = LRParser.deserialize({
@@ -23,6 +24,26 @@ const parser = LRParser.deserialize({
23
24
  });
24
25
 
25
26
  const identifier = /^[a-zA-Z_]+[a-zA-Z_0-9]*$/;
27
+ const expressionLanguageLinter = (config) => linter(view => {
28
+ let diagnostics = [];
29
+ syntaxTree(view.state).cursor().iterate(node => {
30
+ var _a, _b;
31
+ if (node.name == "Identifier") {
32
+ const identifier = view.state.sliceDoc(node.from, node.to);
33
+ const isFunction = (_a = config.functions) === null || _a === void 0 ? void 0 : _a.find(fn => fn.name === identifier);
34
+ const isVariable = (_b = config.identifiers) === null || _b === void 0 ? void 0 : _b.filter(variable => variable.name === identifier);
35
+ if (!isFunction && !isVariable) {
36
+ diagnostics.push({
37
+ from: node.from,
38
+ to: node.to,
39
+ severity: 'warning',
40
+ message: `Identifier "${identifier}" not found`,
41
+ });
42
+ }
43
+ }
44
+ });
45
+ return diagnostics;
46
+ });
26
47
  const ELLanguage = LRLanguage.define({
27
48
  parser: parser.configure({
28
49
  props: [
@@ -82,7 +103,7 @@ function expressionLanguageCompletionFor(config, context) {
82
103
  if (tree.name == 'String') {
83
104
  return null;
84
105
  }
85
- if (tree.prevSibling && !['Operator', 'OperatorKeyword', 'Punctuation', 'NullSafe', 'NullCoalescing'].includes(tree.prevSibling.name)) {
106
+ if (tree.prevSibling && !['Operator', 'OperatorKeyword', 'Punctuation', 'NullSafe', 'NullCoalescing', 'OpeningBracket'].includes(tree.prevSibling.name)) {
86
107
  return completeOperatorKeyword(state, config, tree, tree.from, pos);
87
108
  }
88
109
  if (tree.name == "Identifier") {
@@ -96,7 +117,11 @@ function expressionLanguageCompletionSourceWith(config) {
96
117
  return (context) => expressionLanguageCompletionFor(config, context);
97
118
  }
98
119
  function expressionlanguage(config = {}, extensions = []) {
99
- return new LanguageSupport(ELLanguage, [ELLanguage.data.of({ autocomplete: expressionLanguageCompletionSourceWith(config) }), ...extensions]);
120
+ return new LanguageSupport(ELLanguage, [
121
+ ELLanguage.data.of({ autocomplete: expressionLanguageCompletionSourceWith(config) }),
122
+ expressionLanguageLinter(config),
123
+ ...extensions,
124
+ ]);
100
125
  }
101
126
 
102
127
  export { ELLanguage, expressionlanguage };
package/package.json CHANGED
@@ -17,10 +17,12 @@
17
17
  "dependencies": {
18
18
  "@codemirror/autocomplete": "^6.9.0",
19
19
  "@codemirror/language": "^6.0.0",
20
+ "@codemirror/lint": "^6.4.2",
20
21
  "@lezer/highlight": "^1.0.0",
21
22
  "@lezer/lr": "^1.0.0"
22
23
  },
23
24
  "devDependencies": {
25
+ "@codemirror/state": "^6.2.1",
24
26
  "@lezer/generator": "^1.0.0",
25
27
  "@types/mocha": "^10.0.1",
26
28
  "ist": "^1.1.7",
@@ -39,5 +41,5 @@
39
41
  "access": "public",
40
42
  "registry": "https://registry.npmjs.org/"
41
43
  },
42
- "version": "0.2.1"
44
+ "version": "0.2.2"
43
45
  }