@surrealdb/codemirror 1.0.0-beta.2 → 1.0.0-beta.20
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/index.cjs +59 -11
- package/dist/index.d.cts +11 -2
- package/dist/index.d.ts +11 -2
- package/dist/index.js +59 -12
- package/package.json +7 -5
- package/src/surrealql.ts +72 -16
package/dist/index.cjs
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var language = require('@codemirror/language');
|
|
4
|
-
var
|
|
4
|
+
var lint = require('@codemirror/lint');
|
|
5
5
|
var common = require('@lezer/common');
|
|
6
6
|
var javascript = require('@lezer/javascript');
|
|
7
|
+
var lezer = require('@surrealdb/lezer');
|
|
8
|
+
var compareVersions = require('compare-versions');
|
|
7
9
|
|
|
8
10
|
const surrealqlLanguage = language.LRLanguage.define({
|
|
9
11
|
name: "surrealql",
|
|
10
|
-
parser:
|
|
12
|
+
parser: lezer.parser.configure({
|
|
11
13
|
props: [
|
|
12
14
|
language.indentNodeProp.add({
|
|
13
15
|
Object: language.continuedIndent({ except: /^\s*}/ }),
|
|
@@ -24,24 +26,70 @@ const surrealqlLanguage = language.LRLanguage.define({
|
|
|
24
26
|
languageData: {
|
|
25
27
|
closeBrackets: { brackets: ["[", "{", '"', "'", "("] },
|
|
26
28
|
indentOnInput: /^\s*[\]}]$/,
|
|
27
|
-
commentTokens: { line: "--" },
|
|
29
|
+
commentTokens: { line: "--", block: { open: "/*", close: "*/" } },
|
|
28
30
|
},
|
|
29
31
|
});
|
|
30
|
-
const
|
|
31
|
-
["
|
|
32
|
-
["
|
|
33
|
-
["combined-results",
|
|
32
|
+
const scopeMap = new Map([
|
|
33
|
+
["permission", "PermissionInput"],
|
|
34
|
+
["index", "IndexInput"],
|
|
35
|
+
["combined-results", "CombinedResults"],
|
|
36
|
+
["syntax", "Syntax"],
|
|
34
37
|
]);
|
|
38
|
+
/**
|
|
39
|
+
* A linter that checks if the syntax tree uses features that are not available in the given SurrealDB version
|
|
40
|
+
*
|
|
41
|
+
* @param version The SurrealDB version to check against (e.g. "2.0.0")
|
|
42
|
+
*/
|
|
43
|
+
function surrealqlVersionLinter(version) {
|
|
44
|
+
if (!compareVersions.validate(version)) {
|
|
45
|
+
throw new Error(`Invalid SurrealDB version: ${version}`);
|
|
46
|
+
}
|
|
47
|
+
return lint.linter((view) => {
|
|
48
|
+
const diagnostics = [];
|
|
49
|
+
language.syntaxTree(view.state)
|
|
50
|
+
.cursor()
|
|
51
|
+
.iterate((node) => {
|
|
52
|
+
if (node.from === node.to) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const sinceVersionProp = node.type.prop(lezer.sinceProp);
|
|
56
|
+
const untilVersionProp = node.type.prop(lezer.untilProp);
|
|
57
|
+
if (sinceVersionProp && compareVersions.compareVersions(version, sinceVersionProp) < 0) {
|
|
58
|
+
diagnostics.push({
|
|
59
|
+
from: node.from,
|
|
60
|
+
to: node.to,
|
|
61
|
+
severity: "error",
|
|
62
|
+
message: `This syntax is only available on SurrealDB ${sinceVersionProp} and up`,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
if (untilVersionProp && compareVersions.compareVersions(version, untilVersionProp) >= 0) {
|
|
66
|
+
diagnostics.push({
|
|
67
|
+
from: node.from,
|
|
68
|
+
to: node.to,
|
|
69
|
+
severity: "error",
|
|
70
|
+
message: `This syntax is only available until SurrealDB ${untilVersionProp}`,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return diagnostics;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
35
77
|
/**
|
|
36
78
|
* The CodeMirror extension used to add support for the SurrealQL language
|
|
79
|
+
*
|
|
80
|
+
* @param scope Limit the scope of the highlighting
|
|
37
81
|
*/
|
|
38
|
-
function surrealql(scope
|
|
39
|
-
|
|
40
|
-
|
|
82
|
+
function surrealql(scope) {
|
|
83
|
+
if (!scope) {
|
|
84
|
+
return new language.LanguageSupport(surrealqlLanguage);
|
|
85
|
+
}
|
|
86
|
+
const scopeId = scopeMap.get(scope);
|
|
87
|
+
if (!scopeId) {
|
|
41
88
|
throw new Error(`Unknown language scope: ${scope}`);
|
|
42
89
|
}
|
|
43
|
-
return new language.LanguageSupport(
|
|
90
|
+
return new language.LanguageSupport(surrealqlLanguage.configure({ top: scopeId }));
|
|
44
91
|
}
|
|
45
92
|
|
|
46
93
|
exports.surrealql = surrealql;
|
|
47
94
|
exports.surrealqlLanguage = surrealqlLanguage;
|
|
95
|
+
exports.surrealqlVersionLinter = surrealqlVersionLinter;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { LRLanguage, LanguageSupport } from '@codemirror/language';
|
|
2
|
+
import { Extension } from '@codemirror/state';
|
|
2
3
|
|
|
3
4
|
declare const surrealqlLanguage: LRLanguage;
|
|
4
|
-
type Scope = "
|
|
5
|
+
type Scope = "permission" | "index" | "combined-results" | "syntax";
|
|
6
|
+
/**
|
|
7
|
+
* A linter that checks if the syntax tree uses features that are not available in the given SurrealDB version
|
|
8
|
+
*
|
|
9
|
+
* @param version The SurrealDB version to check against (e.g. "2.0.0")
|
|
10
|
+
*/
|
|
11
|
+
declare function surrealqlVersionLinter(version: string): Extension;
|
|
5
12
|
/**
|
|
6
13
|
* The CodeMirror extension used to add support for the SurrealQL language
|
|
14
|
+
*
|
|
15
|
+
* @param scope Limit the scope of the highlighting
|
|
7
16
|
*/
|
|
8
17
|
declare function surrealql(scope?: Scope): LanguageSupport;
|
|
9
18
|
|
|
10
|
-
export { surrealql, surrealqlLanguage };
|
|
19
|
+
export { surrealql, surrealqlLanguage, surrealqlVersionLinter };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
import { LRLanguage, LanguageSupport } from '@codemirror/language';
|
|
2
|
+
import { Extension } from '@codemirror/state';
|
|
2
3
|
|
|
3
4
|
declare const surrealqlLanguage: LRLanguage;
|
|
4
|
-
type Scope = "
|
|
5
|
+
type Scope = "permission" | "index" | "combined-results" | "syntax";
|
|
6
|
+
/**
|
|
7
|
+
* A linter that checks if the syntax tree uses features that are not available in the given SurrealDB version
|
|
8
|
+
*
|
|
9
|
+
* @param version The SurrealDB version to check against (e.g. "2.0.0")
|
|
10
|
+
*/
|
|
11
|
+
declare function surrealqlVersionLinter(version: string): Extension;
|
|
5
12
|
/**
|
|
6
13
|
* The CodeMirror extension used to add support for the SurrealQL language
|
|
14
|
+
*
|
|
15
|
+
* @param scope Limit the scope of the highlighting
|
|
7
16
|
*/
|
|
8
17
|
declare function surrealql(scope?: Scope): LanguageSupport;
|
|
9
18
|
|
|
10
|
-
export { surrealql, surrealqlLanguage };
|
|
19
|
+
export { surrealql, surrealqlLanguage, surrealqlVersionLinter };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { LRLanguage, indentNodeProp, continuedIndent, foldNodeProp, foldInside, LanguageSupport } from '@codemirror/language';
|
|
2
|
-
import {
|
|
1
|
+
import { LRLanguage, indentNodeProp, continuedIndent, foldNodeProp, foldInside, syntaxTree, LanguageSupport } from '@codemirror/language';
|
|
2
|
+
import { linter } from '@codemirror/lint';
|
|
3
3
|
import { parseMixed } from '@lezer/common';
|
|
4
4
|
import { parser as parser$1 } from '@lezer/javascript';
|
|
5
|
+
import { parser, sinceProp, untilProp } from '@surrealdb/lezer';
|
|
6
|
+
import { validate, compareVersions } from 'compare-versions';
|
|
5
7
|
|
|
6
8
|
const surrealqlLanguage = /*@__PURE__*/LRLanguage.define({
|
|
7
9
|
name: "surrealql",
|
|
@@ -22,23 +24,68 @@ const surrealqlLanguage = /*@__PURE__*/LRLanguage.define({
|
|
|
22
24
|
languageData: {
|
|
23
25
|
closeBrackets: { brackets: ["[", "{", '"', "'", "("] },
|
|
24
26
|
indentOnInput: /^\s*[\]}]$/,
|
|
25
|
-
commentTokens: { line: "--" },
|
|
27
|
+
commentTokens: { line: "--", block: { open: "/*", close: "*/" } },
|
|
26
28
|
},
|
|
27
29
|
});
|
|
28
|
-
const
|
|
29
|
-
["
|
|
30
|
-
["
|
|
31
|
-
["combined-results",
|
|
30
|
+
const scopeMap = /*@__PURE__*/new Map([
|
|
31
|
+
["permission", "PermissionInput"],
|
|
32
|
+
["index", "IndexInput"],
|
|
33
|
+
["combined-results", "CombinedResults"],
|
|
34
|
+
["syntax", "Syntax"],
|
|
32
35
|
]);
|
|
36
|
+
/**
|
|
37
|
+
* A linter that checks if the syntax tree uses features that are not available in the given SurrealDB version
|
|
38
|
+
*
|
|
39
|
+
* @param version The SurrealDB version to check against (e.g. "2.0.0")
|
|
40
|
+
*/
|
|
41
|
+
function surrealqlVersionLinter(version) {
|
|
42
|
+
if (!validate(version)) {
|
|
43
|
+
throw new Error(`Invalid SurrealDB version: ${version}`);
|
|
44
|
+
}
|
|
45
|
+
return linter((view) => {
|
|
46
|
+
const diagnostics = [];
|
|
47
|
+
syntaxTree(view.state)
|
|
48
|
+
.cursor()
|
|
49
|
+
.iterate((node) => {
|
|
50
|
+
if (node.from === node.to) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const sinceVersionProp = node.type.prop(sinceProp);
|
|
54
|
+
const untilVersionProp = node.type.prop(untilProp);
|
|
55
|
+
if (sinceVersionProp && compareVersions(version, sinceVersionProp) < 0) {
|
|
56
|
+
diagnostics.push({
|
|
57
|
+
from: node.from,
|
|
58
|
+
to: node.to,
|
|
59
|
+
severity: "error",
|
|
60
|
+
message: `This syntax is only available on SurrealDB ${sinceVersionProp} and up`,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (untilVersionProp && compareVersions(version, untilVersionProp) >= 0) {
|
|
64
|
+
diagnostics.push({
|
|
65
|
+
from: node.from,
|
|
66
|
+
to: node.to,
|
|
67
|
+
severity: "error",
|
|
68
|
+
message: `This syntax is only available until SurrealDB ${untilVersionProp}`,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
return diagnostics;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
33
75
|
/**
|
|
34
76
|
* The CodeMirror extension used to add support for the SurrealQL language
|
|
77
|
+
*
|
|
78
|
+
* @param scope Limit the scope of the highlighting
|
|
35
79
|
*/
|
|
36
|
-
function surrealql(scope
|
|
37
|
-
|
|
38
|
-
|
|
80
|
+
function surrealql(scope) {
|
|
81
|
+
if (!scope) {
|
|
82
|
+
return new LanguageSupport(surrealqlLanguage);
|
|
83
|
+
}
|
|
84
|
+
const scopeId = scopeMap.get(scope);
|
|
85
|
+
if (!scopeId) {
|
|
39
86
|
throw new Error(`Unknown language scope: ${scope}`);
|
|
40
87
|
}
|
|
41
|
-
return new LanguageSupport(
|
|
88
|
+
return new LanguageSupport(surrealqlLanguage.configure({ top: scopeId }));
|
|
42
89
|
}
|
|
43
90
|
|
|
44
|
-
export { surrealql, surrealqlLanguage };
|
|
91
|
+
export { surrealql, surrealqlLanguage, surrealqlVersionLinter };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@surrealdb/codemirror",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.20",
|
|
4
4
|
"author": "SurrealDB",
|
|
5
5
|
"description": "SurrealQL language support for CodeMirror",
|
|
6
6
|
"type": "module",
|
|
@@ -12,10 +12,12 @@
|
|
|
12
12
|
"types": "dist/index.d.ts",
|
|
13
13
|
"module": "dist/index.js",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@codemirror/language": "^6.
|
|
16
|
-
"@
|
|
17
|
-
"@lezer/
|
|
18
|
-
"@
|
|
15
|
+
"@codemirror/language": "^6.10.3",
|
|
16
|
+
"@codemirror/lint": "^6.8.2",
|
|
17
|
+
"@lezer/common": "^1.2.3",
|
|
18
|
+
"@lezer/javascript": "^1.4.19",
|
|
19
|
+
"@surrealdb/lezer": "",
|
|
20
|
+
"compare-versions": "^6.1.1"
|
|
19
21
|
},
|
|
20
22
|
"devDependencies": {
|
|
21
23
|
"@codemirror/buildhelper": "^1.0.0"
|
package/src/surrealql.ts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
|
-
continuedIndent,
|
|
3
|
-
indentNodeProp,
|
|
4
|
-
foldNodeProp,
|
|
5
|
-
foldInside,
|
|
6
2
|
LRLanguage,
|
|
7
3
|
LanguageSupport,
|
|
4
|
+
continuedIndent,
|
|
5
|
+
foldInside,
|
|
6
|
+
foldNodeProp,
|
|
7
|
+
indentNodeProp,
|
|
8
|
+
syntaxTree,
|
|
8
9
|
} from "@codemirror/language";
|
|
9
|
-
|
|
10
|
-
import {
|
|
10
|
+
import { type Diagnostic, linter } from "@codemirror/lint";
|
|
11
|
+
import type { Extension } from "@codemirror/state";
|
|
11
12
|
import { parseMixed } from "@lezer/common";
|
|
12
13
|
import { parser as jsParser } from "@lezer/javascript";
|
|
14
|
+
import { parser, sinceProp, untilProp } from "@surrealdb/lezer";
|
|
15
|
+
import { compareVersions, validate } from "compare-versions";
|
|
13
16
|
|
|
14
17
|
export const surrealqlLanguage = LRLanguage.define({
|
|
15
18
|
name: "surrealql",
|
|
@@ -30,27 +33,80 @@ export const surrealqlLanguage = LRLanguage.define({
|
|
|
30
33
|
languageData: {
|
|
31
34
|
closeBrackets: { brackets: ["[", "{", '"', "'", "("] },
|
|
32
35
|
indentOnInput: /^\s*[\]}]$/,
|
|
33
|
-
commentTokens: { line: "--" },
|
|
36
|
+
commentTokens: { line: "--", block: { open: "/*", close: "*/" } },
|
|
34
37
|
},
|
|
35
38
|
});
|
|
36
39
|
|
|
37
|
-
type Scope = "
|
|
40
|
+
type Scope = "permission" | "index" | "combined-results" | "syntax";
|
|
38
41
|
|
|
39
|
-
const
|
|
40
|
-
["
|
|
41
|
-
["
|
|
42
|
-
["combined-results",
|
|
42
|
+
const scopeMap = new Map<Scope, string>([
|
|
43
|
+
["permission", "PermissionInput"],
|
|
44
|
+
["index", "IndexInput"],
|
|
45
|
+
["combined-results", "CombinedResults"],
|
|
46
|
+
["syntax", "Syntax"],
|
|
43
47
|
]);
|
|
44
48
|
|
|
49
|
+
/**
|
|
50
|
+
* A linter that checks if the syntax tree uses features that are not available in the given SurrealDB version
|
|
51
|
+
*
|
|
52
|
+
* @param version The SurrealDB version to check against (e.g. "2.0.0")
|
|
53
|
+
*/
|
|
54
|
+
export function surrealqlVersionLinter(version: string): Extension {
|
|
55
|
+
if (!validate(version)) {
|
|
56
|
+
throw new Error(`Invalid SurrealDB version: ${version}`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return linter((view) => {
|
|
60
|
+
const diagnostics: Diagnostic[] = [];
|
|
61
|
+
|
|
62
|
+
syntaxTree(view.state)
|
|
63
|
+
.cursor()
|
|
64
|
+
.iterate((node) => {
|
|
65
|
+
if (node.from === node.to) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const sinceVersionProp = node.type.prop(sinceProp);
|
|
70
|
+
const untilVersionProp = node.type.prop(untilProp);
|
|
71
|
+
|
|
72
|
+
if (sinceVersionProp && compareVersions(version, sinceVersionProp) < 0) {
|
|
73
|
+
diagnostics.push({
|
|
74
|
+
from: node.from,
|
|
75
|
+
to: node.to,
|
|
76
|
+
severity: "error",
|
|
77
|
+
message: `This syntax is only available on SurrealDB ${sinceVersionProp} and up`,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (untilVersionProp && compareVersions(version, untilVersionProp) >= 0) {
|
|
82
|
+
diagnostics.push({
|
|
83
|
+
from: node.from,
|
|
84
|
+
to: node.to,
|
|
85
|
+
severity: "error",
|
|
86
|
+
message: `This syntax is only available until SurrealDB ${untilVersionProp}`,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
return diagnostics;
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
45
95
|
/**
|
|
46
96
|
* The CodeMirror extension used to add support for the SurrealQL language
|
|
97
|
+
*
|
|
98
|
+
* @param scope Limit the scope of the highlighting
|
|
47
99
|
*/
|
|
48
|
-
export function surrealql(scope
|
|
49
|
-
|
|
100
|
+
export function surrealql(scope?: Scope): LanguageSupport {
|
|
101
|
+
if (!scope) {
|
|
102
|
+
return new LanguageSupport(surrealqlLanguage);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const scopeId = scopeMap.get(scope);
|
|
50
106
|
|
|
51
|
-
if (!
|
|
107
|
+
if (!scopeId) {
|
|
52
108
|
throw new Error(`Unknown language scope: ${scope}`);
|
|
53
109
|
}
|
|
54
110
|
|
|
55
|
-
return new LanguageSupport(
|
|
111
|
+
return new LanguageSupport(surrealqlLanguage.configure({ top: scopeId }));
|
|
56
112
|
}
|