@spyglassmc/core 0.1.1 → 0.3.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/README.md +7 -0
- package/lib/browser.d.ts +2 -0
- package/lib/browser.js +2 -0
- package/lib/common/Dev.d.ts +11 -0
- package/lib/common/Dev.js +90 -0
- package/lib/{service → common}/Logger.d.ts +0 -0
- package/lib/{service → common}/Logger.js +2 -5
- package/lib/common/Operations.d.ts +12 -0
- package/lib/common/Operations.js +33 -0
- package/lib/common/ReadonlyProxy.d.ts +9 -0
- package/lib/common/ReadonlyProxy.js +23 -0
- package/lib/common/StateProxy.d.ts +35 -0
- package/lib/common/StateProxy.js +69 -0
- package/lib/common/TwoWayMap.d.ts +21 -0
- package/lib/common/TwoWayMap.js +69 -0
- package/lib/common/externals/BrowserExternals.d.ts +3 -0
- package/lib/common/externals/BrowserExternals.js +191 -0
- package/lib/common/externals/NodeJsExternals.d.ts +3 -0
- package/lib/common/externals/NodeJsExternals.js +152 -0
- package/lib/common/externals/downloader.d.ts +31 -0
- package/lib/common/externals/downloader.js +32 -0
- package/lib/common/externals/index.d.ts +96 -0
- package/lib/common/externals/index.js +2 -0
- package/lib/common/index.d.ts +8 -1
- package/lib/common/index.js +8 -13
- package/lib/common/util.d.ts +50 -39
- package/lib/common/util.js +73 -122
- package/lib/index.d.ts +7 -7
- package/lib/index.js +7 -19
- package/lib/node/AstNode.d.ts +12 -11
- package/lib/node/AstNode.js +10 -16
- package/lib/node/BooleanNode.d.ts +2 -2
- package/lib/node/BooleanNode.js +4 -7
- package/lib/node/CommentNode.d.ts +6 -5
- package/lib/node/CommentNode.js +4 -9
- package/lib/node/ErrorNode.d.ts +1 -1
- package/lib/node/ErrorNode.js +2 -5
- package/lib/node/FileNode.d.ts +8 -4
- package/lib/node/FileNode.js +3 -6
- package/lib/node/FloatNode.d.ts +3 -3
- package/lib/node/FloatNode.js +4 -7
- package/lib/node/IntegerNode.d.ts +3 -3
- package/lib/node/IntegerNode.js +4 -7
- package/lib/node/ListNode.d.ts +2 -2
- package/lib/node/ListNode.js +2 -5
- package/lib/node/LiteralNode.d.ts +5 -5
- package/lib/node/LiteralNode.js +5 -8
- package/lib/node/LongNode.d.ts +3 -3
- package/lib/node/LongNode.js +4 -7
- package/lib/node/RecordNode.d.ts +2 -2
- package/lib/node/RecordNode.js +2 -5
- package/lib/node/ResourceLocationNode.d.ts +8 -10
- package/lib/node/ResourceLocationNode.js +9 -12
- package/lib/node/Sequence.d.ts +4 -3
- package/lib/node/Sequence.js +4 -6
- package/lib/node/StringNode.d.ts +5 -5
- package/lib/node/StringNode.js +9 -12
- package/lib/node/SymbolNode.d.ts +5 -5
- package/lib/node/SymbolNode.js +5 -8
- package/lib/node/index.d.ts +15 -15
- package/lib/node/index.js +15 -27
- package/lib/nodejs.d.ts +2 -0
- package/lib/nodejs.js +2 -0
- package/lib/parser/Parser.d.ts +3 -3
- package/lib/parser/Parser.js +1 -4
- package/lib/parser/boolean.d.ts +2 -2
- package/lib/parser/boolean.js +3 -6
- package/lib/parser/comment.d.ts +2 -2
- package/lib/parser/comment.js +5 -9
- package/lib/parser/empty.d.ts +1 -1
- package/lib/parser/empty.js +1 -5
- package/lib/parser/error.d.ts +2 -2
- package/lib/parser/error.js +5 -9
- package/lib/parser/file.d.ts +3 -3
- package/lib/parser/file.js +9 -13
- package/lib/parser/float.d.ts +4 -4
- package/lib/parser/float.js +12 -16
- package/lib/parser/index.d.ts +16 -16
- package/lib/parser/index.js +16 -34
- package/lib/parser/integer.d.ts +4 -4
- package/lib/parser/integer.js +10 -14
- package/lib/parser/list.d.ts +2 -2
- package/lib/parser/list.js +15 -19
- package/lib/parser/literal.d.ts +2 -2
- package/lib/parser/literal.js +5 -9
- package/lib/parser/long.d.ts +4 -4
- package/lib/parser/long.js +10 -14
- package/lib/parser/record.d.ts +3 -3
- package/lib/parser/record.js +20 -24
- package/lib/parser/resourceLocation.d.ts +2 -2
- package/lib/parser/resourceLocation.js +12 -24
- package/lib/parser/string.d.ts +7 -7
- package/lib/parser/string.js +40 -44
- package/lib/parser/symbol.d.ts +3 -3
- package/lib/parser/symbol.js +4 -14
- package/lib/parser/util.d.ts +30 -12
- package/lib/parser/util.js +78 -65
- package/lib/processor/ColorInfoProvider.d.ts +1 -1
- package/lib/processor/ColorInfoProvider.js +6 -9
- package/lib/processor/InlayHintProvider.d.ts +4 -3
- package/lib/processor/InlayHintProvider.js +1 -2
- package/lib/processor/SignatureHelpProvider.d.ts +4 -3
- package/lib/processor/SignatureHelpProvider.js +1 -2
- package/lib/processor/binder/Binder.d.ts +26 -0
- package/lib/processor/binder/Binder.js +18 -0
- package/lib/processor/binder/builtin.d.ts +27 -0
- package/lib/processor/binder/builtin.js +116 -0
- package/lib/processor/binder/index.d.ts +3 -0
- package/lib/processor/binder/index.js +3 -0
- package/lib/processor/checker/Checker.d.ts +2 -2
- package/lib/processor/checker/Checker.js +1 -5
- package/lib/processor/checker/builtin.d.ts +4 -4
- package/lib/processor/checker/builtin.js +22 -33
- package/lib/processor/checker/index.d.ts +2 -2
- package/lib/processor/checker/index.js +2 -27
- package/lib/processor/colorizer/Colorizer.d.ts +6 -5
- package/lib/processor/colorizer/Colorizer.js +8 -11
- package/lib/processor/colorizer/builtin.d.ts +3 -3
- package/lib/processor/colorizer/builtin.js +33 -46
- package/lib/processor/colorizer/index.d.ts +2 -2
- package/lib/processor/colorizer/index.js +2 -27
- package/lib/processor/completer/Completer.d.ts +6 -5
- package/lib/processor/completer/Completer.js +14 -33
- package/lib/processor/completer/builtin.d.ts +10 -9
- package/lib/processor/completer/builtin.js +59 -75
- package/lib/processor/completer/index.d.ts +2 -2
- package/lib/processor/completer/index.js +2 -27
- package/lib/processor/formatter/Formatter.d.ts +4 -3
- package/lib/processor/formatter/Formatter.js +2 -7
- package/lib/processor/formatter/builtin.d.ts +3 -3
- package/lib/processor/formatter/builtin.js +22 -36
- package/lib/processor/formatter/index.d.ts +2 -2
- package/lib/processor/formatter/index.js +2 -27
- package/lib/processor/index.d.ts +10 -9
- package/lib/processor/index.js +10 -21
- package/lib/processor/linter/Linter.d.ts +4 -3
- package/lib/processor/linter/Linter.js +1 -2
- package/lib/processor/linter/builtin/undeclaredSymbol.d.ts +2 -2
- package/lib/processor/linter/builtin/undeclaredSymbol.js +23 -27
- package/lib/processor/linter/builtin.d.ts +4 -3
- package/lib/processor/linter/builtin.js +19 -26
- package/lib/processor/linter/index.d.ts +2 -2
- package/lib/processor/linter/index.js +2 -27
- package/lib/processor/util.d.ts +4 -14
- package/lib/processor/util.js +1 -16
- package/lib/service/CacheService.d.ts +8 -6
- package/lib/service/CacheService.js +35 -56
- package/lib/service/Config.d.ts +17 -16
- package/lib/service/Config.js +56 -51
- package/lib/service/Context.d.ts +24 -21
- package/lib/service/Context.js +40 -36
- package/lib/service/Dependency.js +2 -5
- package/lib/service/Downloader.d.ts +9 -39
- package/lib/service/Downloader.js +37 -106
- package/lib/service/ErrorReporter.d.ts +2 -2
- package/lib/service/ErrorReporter.js +11 -15
- package/lib/service/FileService.d.ts +40 -14
- package/lib/service/FileService.js +107 -81
- package/lib/service/Hover.d.ts +2 -2
- package/lib/service/Hover.js +4 -7
- package/lib/service/MetaRegistry.d.ts +17 -12
- package/lib/service/MetaRegistry.js +81 -73
- package/lib/service/Profiler.d.ts +3 -2
- package/lib/service/Profiler.js +81 -45
- package/lib/service/Project.d.ts +101 -73
- package/lib/service/Project.js +438 -367
- package/lib/service/Service.d.ts +19 -29
- package/lib/service/Service.js +57 -53
- package/lib/service/SymbolLocations.d.ts +3 -3
- package/lib/service/SymbolLocations.js +4 -7
- package/lib/service/SymbolRegistrar.d.ts +1 -1
- package/lib/service/SymbolRegistrar.js +1 -2
- package/lib/service/UriProcessor.d.ts +5 -0
- package/lib/service/UriProcessor.js +2 -0
- package/lib/service/fileUtil.d.ts +21 -41
- package/lib/service/fileUtil.js +59 -129
- package/lib/service/index.d.ts +16 -17
- package/lib/service/index.js +16 -31
- package/lib/source/IndexMap.d.ts +1 -1
- package/lib/source/IndexMap.js +7 -10
- package/lib/source/LanguageError.d.ts +2 -2
- package/lib/source/LanguageError.js +3 -6
- package/lib/source/Location.d.ts +3 -3
- package/lib/source/Location.js +6 -9
- package/lib/source/Offset.d.ts +1 -1
- package/lib/source/Offset.js +4 -7
- package/lib/source/Position.js +2 -5
- package/lib/source/PositionRange.d.ts +2 -2
- package/lib/source/PositionRange.js +14 -17
- package/lib/source/Range.d.ts +1 -1
- package/lib/source/Range.js +7 -10
- package/lib/source/Source.d.ts +9 -4
- package/lib/source/Source.js +58 -31
- package/lib/source/index.d.ts +8 -8
- package/lib/source/index.js +8 -20
- package/lib/symbol/Symbol.d.ts +15 -14
- package/lib/symbol/Symbol.js +53 -68
- package/lib/symbol/SymbolUtil.d.ts +30 -39
- package/lib/symbol/SymbolUtil.js +189 -168
- package/lib/symbol/index.d.ts +2 -3
- package/lib/symbol/index.js +2 -15
- package/package.json +7 -4
- package/lib/service/Operations.d.ts +0 -8
- package/lib/service/Operations.js +0 -26
- package/lib/symbol/UriBinder.d.ts +0 -3
- package/lib/symbol/UriBinder.js +0 -3
package/lib/parser/util.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const source_1 = require("../source");
|
|
7
|
-
const Parser_1 = require("./Parser");
|
|
8
|
-
function attempt(parser, src, ctx) {
|
|
1
|
+
import { SequenceUtil, SequenceUtilDiscriminator } from '../node/index.js';
|
|
2
|
+
import { ErrorReporter } from '../service/index.js';
|
|
3
|
+
import { Range } from '../source/index.js';
|
|
4
|
+
import { Failure } from './Parser.js';
|
|
5
|
+
export function attempt(parser, src, ctx) {
|
|
9
6
|
const tmpSrc = src.clone();
|
|
10
7
|
const tmpCtx = {
|
|
11
8
|
...ctx,
|
|
12
|
-
err: new
|
|
13
|
-
symbols: ctx.symbols.clone(),
|
|
9
|
+
err: new ErrorReporter(),
|
|
14
10
|
};
|
|
15
11
|
const result = parser(tmpSrc, tmpCtx);
|
|
16
12
|
return {
|
|
@@ -20,17 +16,15 @@ function attempt(parser, src, ctx) {
|
|
|
20
16
|
updateSrcAndCtx: () => {
|
|
21
17
|
src.innerCursor = tmpSrc.innerCursor;
|
|
22
18
|
ctx.err.absorb(tmpCtx.err);
|
|
23
|
-
tmpCtx.symbols.applyDelayedEdits();
|
|
24
19
|
},
|
|
25
20
|
};
|
|
26
21
|
}
|
|
27
|
-
|
|
28
|
-
function sequence(parsers, parseGap) {
|
|
22
|
+
export function sequence(parsers, parseGap) {
|
|
29
23
|
return (src, ctx) => {
|
|
30
24
|
const ans = {
|
|
31
|
-
|
|
25
|
+
[SequenceUtilDiscriminator]: true,
|
|
32
26
|
children: [],
|
|
33
|
-
range:
|
|
27
|
+
range: Range.create(src),
|
|
34
28
|
};
|
|
35
29
|
for (const [i, p] of parsers.entries()) {
|
|
36
30
|
const parser = typeof p === 'function' ? p : p.get(ans);
|
|
@@ -41,13 +35,13 @@ function sequence(parsers, parseGap) {
|
|
|
41
35
|
ans.children.push(...parseGap(src, ctx));
|
|
42
36
|
}
|
|
43
37
|
const result = parser(src, ctx);
|
|
44
|
-
if (result ===
|
|
45
|
-
return
|
|
38
|
+
if (result === Failure) {
|
|
39
|
+
return Failure;
|
|
46
40
|
}
|
|
47
41
|
else if (result === undefined) {
|
|
48
42
|
continue;
|
|
49
43
|
}
|
|
50
|
-
else if (
|
|
44
|
+
else if (SequenceUtil.is(result)) {
|
|
51
45
|
ans.children.push(...result.children);
|
|
52
46
|
}
|
|
53
47
|
else {
|
|
@@ -58,24 +52,23 @@ function sequence(parsers, parseGap) {
|
|
|
58
52
|
return ans;
|
|
59
53
|
};
|
|
60
54
|
}
|
|
61
|
-
|
|
62
|
-
function repeat(parser, parseGap) {
|
|
55
|
+
export function repeat(parser, parseGap) {
|
|
63
56
|
return (src, ctx) => {
|
|
64
57
|
const ans = {
|
|
65
|
-
|
|
58
|
+
[SequenceUtilDiscriminator]: true,
|
|
66
59
|
children: [],
|
|
67
|
-
range:
|
|
60
|
+
range: Range.create(src),
|
|
68
61
|
};
|
|
69
62
|
while (src.canRead()) {
|
|
70
63
|
if (parseGap) {
|
|
71
64
|
ans.children.push(...parseGap(src, ctx));
|
|
72
65
|
}
|
|
73
66
|
const { result, updateSrcAndCtx } = attempt(parser, src, ctx);
|
|
74
|
-
if (result ===
|
|
67
|
+
if (result === Failure) {
|
|
75
68
|
break;
|
|
76
69
|
}
|
|
77
70
|
updateSrcAndCtx();
|
|
78
|
-
if (
|
|
71
|
+
if (SequenceUtil.is(result)) {
|
|
79
72
|
ans.children.push(...result.children);
|
|
80
73
|
}
|
|
81
74
|
else {
|
|
@@ -86,18 +79,17 @@ function repeat(parser, parseGap) {
|
|
|
86
79
|
return ans;
|
|
87
80
|
};
|
|
88
81
|
}
|
|
89
|
-
|
|
90
|
-
function any(parsers, out) {
|
|
82
|
+
export function any(parsers, out) {
|
|
91
83
|
return (src, ctx) => {
|
|
92
84
|
const results = parsers
|
|
93
85
|
.map((parser, i) => ({ attempt: attempt(parser, src, ctx), index: i }))
|
|
94
|
-
.filter(({ attempt }) => attempt.result !==
|
|
86
|
+
.filter(({ attempt }) => attempt.result !== Failure)
|
|
95
87
|
.sort((a, b) => (b.attempt.endCursor - a.attempt.endCursor) || (a.attempt.errorAmount - b.attempt.errorAmount));
|
|
96
88
|
if (results.length === 0) {
|
|
97
89
|
if (out) {
|
|
98
90
|
out.index = -1;
|
|
99
91
|
}
|
|
100
|
-
return
|
|
92
|
+
return Failure;
|
|
101
93
|
}
|
|
102
94
|
results[0].attempt.updateSrcAndCtx();
|
|
103
95
|
if (out) {
|
|
@@ -106,11 +98,10 @@ function any(parsers, out) {
|
|
|
106
98
|
return results[0].attempt.result;
|
|
107
99
|
};
|
|
108
100
|
}
|
|
109
|
-
exports.any = any;
|
|
110
101
|
/**
|
|
111
102
|
* @returns A parser that fails when the passed-in parser didn't move the cursor at all.
|
|
112
103
|
*/
|
|
113
|
-
function failOnEmpty(parser) {
|
|
104
|
+
export function failOnEmpty(parser) {
|
|
114
105
|
return (src, ctx) => {
|
|
115
106
|
const start = src.cursor;
|
|
116
107
|
const { endCursor, updateSrcAndCtx, result } = attempt(parser, src, ctx);
|
|
@@ -118,68 +109,78 @@ function failOnEmpty(parser) {
|
|
|
118
109
|
updateSrcAndCtx();
|
|
119
110
|
return result;
|
|
120
111
|
}
|
|
121
|
-
return
|
|
112
|
+
return Failure;
|
|
122
113
|
};
|
|
123
114
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
// empty,
|
|
129
|
-
// ])
|
|
115
|
+
/**
|
|
116
|
+
* @returns A parser that fails when the passed-in parser produced any errors.
|
|
117
|
+
*/
|
|
118
|
+
export function failOnError(parser) {
|
|
130
119
|
return (src, ctx) => {
|
|
120
|
+
const start = src.cursor;
|
|
121
|
+
const { errorAmount, updateSrcAndCtx, result } = attempt(parser, src, ctx);
|
|
122
|
+
if (!errorAmount) {
|
|
123
|
+
updateSrcAndCtx();
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
return Failure;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
export function optional(parser) {
|
|
130
|
+
return ((src, ctx) => {
|
|
131
131
|
const { result, updateSrcAndCtx } = attempt(parser, src, ctx);
|
|
132
|
-
if (result ===
|
|
132
|
+
if (result === Failure) {
|
|
133
133
|
return undefined;
|
|
134
134
|
}
|
|
135
135
|
else {
|
|
136
136
|
updateSrcAndCtx();
|
|
137
137
|
return result;
|
|
138
138
|
}
|
|
139
|
-
};
|
|
139
|
+
});
|
|
140
140
|
}
|
|
141
|
-
|
|
142
|
-
function recover(parser, defaultValue) {
|
|
141
|
+
export function recover(parser, defaultValue) {
|
|
143
142
|
return (src, ctx) => {
|
|
144
143
|
const result = parser(src, ctx);
|
|
145
|
-
if (result ===
|
|
144
|
+
if (result === Failure) {
|
|
146
145
|
const ans = defaultValue(src, ctx);
|
|
147
146
|
return ans;
|
|
148
147
|
}
|
|
149
148
|
return result;
|
|
150
149
|
};
|
|
151
150
|
}
|
|
152
|
-
|
|
153
|
-
function select(cases) {
|
|
151
|
+
export function select(cases) {
|
|
154
152
|
return (src, ctx) => {
|
|
155
|
-
for (const { predicate, parser } of cases) {
|
|
156
|
-
if (predicate?.(src) ?? true) {
|
|
157
|
-
|
|
153
|
+
for (const { predicate, prefix, parser } of cases) {
|
|
154
|
+
if (predicate?.(src) ?? (prefix !== undefined ? src.tryPeek(prefix) : undefined) ?? true) {
|
|
155
|
+
const callableParser = typeof parser === 'object' ? parser.get() : parser;
|
|
156
|
+
return callableParser(src, ctx);
|
|
158
157
|
}
|
|
159
158
|
}
|
|
160
|
-
|
|
159
|
+
throw new Error('The select parser util was called with non-exhaustive cases');
|
|
161
160
|
};
|
|
162
161
|
}
|
|
163
|
-
|
|
164
|
-
function map(parser, fn) {
|
|
162
|
+
export function map(parser, fn) {
|
|
165
163
|
return (src, ctx) => {
|
|
166
164
|
const result = parser(src, ctx);
|
|
167
|
-
if (result ===
|
|
168
|
-
return
|
|
165
|
+
if (result === Failure) {
|
|
166
|
+
return Failure;
|
|
169
167
|
}
|
|
170
168
|
const ans = fn(result, src, ctx);
|
|
171
169
|
return ans;
|
|
172
170
|
};
|
|
173
171
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
172
|
+
export function setType(type, parser) {
|
|
173
|
+
return map(parser, res => {
|
|
174
|
+
const { type: _type, ...restResult } = res;
|
|
175
|
+
const ans = {
|
|
176
|
+
type,
|
|
177
|
+
...restResult,
|
|
178
|
+
};
|
|
179
|
+
delete ans[SequenceUtilDiscriminator];
|
|
180
|
+
return ans;
|
|
181
|
+
});
|
|
180
182
|
}
|
|
181
|
-
|
|
182
|
-
function validate(parser, validator, message, severity) {
|
|
183
|
+
export function validate(parser, validator, message, severity) {
|
|
183
184
|
return map(parser, (res, src, ctx) => {
|
|
184
185
|
const isLegal = validator(res, src, ctx);
|
|
185
186
|
if (!isLegal) {
|
|
@@ -188,8 +189,7 @@ function validate(parser, validator, message, severity) {
|
|
|
188
189
|
return res;
|
|
189
190
|
});
|
|
190
191
|
}
|
|
191
|
-
|
|
192
|
-
function stopBefore(parser, ...teminators) {
|
|
192
|
+
export function stopBefore(parser, ...teminators) {
|
|
193
193
|
const flatTerminators = teminators.flat();
|
|
194
194
|
return (src, ctx) => {
|
|
195
195
|
const tmpSrc = src.clone();
|
|
@@ -203,8 +203,7 @@ function stopBefore(parser, ...teminators) {
|
|
|
203
203
|
return ans;
|
|
204
204
|
};
|
|
205
205
|
}
|
|
206
|
-
|
|
207
|
-
function acceptOnly(parser, ...characters) {
|
|
206
|
+
export function acceptOnly(parser, ...characters) {
|
|
208
207
|
const set = new Set(characters.flat());
|
|
209
208
|
return (src, ctx) => {
|
|
210
209
|
const tmpSrc = src.clone();
|
|
@@ -220,5 +219,19 @@ function acceptOnly(parser, ...characters) {
|
|
|
220
219
|
return ans;
|
|
221
220
|
};
|
|
222
221
|
}
|
|
223
|
-
|
|
222
|
+
export function acceptIf(parser, predicate) {
|
|
223
|
+
return ((src, ctx) => {
|
|
224
|
+
const tmpSrc = src.clone();
|
|
225
|
+
// Cut tmpSrc.string before the nearest unacceptable character.
|
|
226
|
+
for (let i = tmpSrc.innerCursor; i < tmpSrc.string.length; i++) {
|
|
227
|
+
if (!predicate(tmpSrc.string.charAt(i))) {
|
|
228
|
+
tmpSrc.string = tmpSrc.string.slice(0, i);
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
const ans = parser(tmpSrc, ctx);
|
|
233
|
+
src.innerCursor = tmpSrc.innerCursor;
|
|
234
|
+
return ans;
|
|
235
|
+
});
|
|
236
|
+
}
|
|
224
237
|
//# sourceMappingURL=util.js.map
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ColorPresentation = exports.ColorFormat = exports.Color = void 0;
|
|
4
|
-
var Color;
|
|
1
|
+
export var Color;
|
|
5
2
|
(function (Color) {
|
|
6
3
|
Color.NamedColors = new Map([
|
|
7
4
|
['aqua', 0x55ffff],
|
|
@@ -75,8 +72,8 @@ var Color;
|
|
|
75
72
|
return fromIntRGB(r, g, b);
|
|
76
73
|
}
|
|
77
74
|
Color.fromCompositeInt = fromCompositeInt;
|
|
78
|
-
})(Color
|
|
79
|
-
var ColorFormat;
|
|
75
|
+
})(Color || (Color = {}));
|
|
76
|
+
export var ColorFormat;
|
|
80
77
|
(function (ColorFormat) {
|
|
81
78
|
/**
|
|
82
79
|
* `1 0.6 0.2 1.0`
|
|
@@ -106,8 +103,8 @@ var ColorFormat;
|
|
|
106
103
|
* `16620441`
|
|
107
104
|
*/
|
|
108
105
|
ColorFormat[ColorFormat["CompositeInt"] = 6] = "CompositeInt";
|
|
109
|
-
})(ColorFormat
|
|
110
|
-
var ColorPresentation;
|
|
106
|
+
})(ColorFormat || (ColorFormat = {}));
|
|
107
|
+
export var ColorPresentation;
|
|
111
108
|
(function (ColorPresentation) {
|
|
112
109
|
function fromColorFormat(format, color, range) {
|
|
113
110
|
const presentation = colorPresentation(format, color);
|
|
@@ -137,5 +134,5 @@ var ColorPresentation;
|
|
|
137
134
|
return `${Math.round((color[0] * 255 << 16) + (color[1] * 255 << 8) + color[2] * 255)}`;
|
|
138
135
|
}
|
|
139
136
|
}
|
|
140
|
-
})(ColorPresentation
|
|
137
|
+
})(ColorPresentation || (ColorPresentation = {}));
|
|
141
138
|
//# sourceMappingURL=ColorInfoProvider.js.map
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { DeepReadonly } from '../common/index.js';
|
|
2
|
+
import type { AstNode } from '../node/index.js';
|
|
3
|
+
import type { ProcessorContext } from '../service/index.js';
|
|
3
4
|
export interface InlayHint {
|
|
4
5
|
offset: number;
|
|
5
6
|
text: string;
|
|
6
7
|
}
|
|
7
|
-
export declare type InlayHintProvider<N = AstNode> = (node: N
|
|
8
|
+
export declare type InlayHintProvider<N extends AstNode = AstNode> = (node: DeepReadonly<N>, ctx: ProcessorContext) => readonly InlayHint[];
|
|
8
9
|
//# sourceMappingURL=InlayHintProvider.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { DeepReadonly } from '../common/index.js';
|
|
2
|
+
import type { AstNode } from '../node/index.js';
|
|
3
|
+
import type { SignatureHelpProviderContext } from '../service/index.js';
|
|
3
4
|
export interface SignatureHelp {
|
|
4
5
|
signatures: SignatureInfo[];
|
|
5
6
|
activeSignature: number;
|
|
@@ -14,5 +15,5 @@ export interface ParameterInfo {
|
|
|
14
15
|
label: [number, number];
|
|
15
16
|
documentation?: string;
|
|
16
17
|
}
|
|
17
|
-
export declare type SignatureHelpProvider<N = AstNode> = (node: N
|
|
18
|
+
export declare type SignatureHelpProvider<N extends AstNode = AstNode> = (node: DeepReadonly<N>, ctx: SignatureHelpProviderContext) => SignatureHelp | undefined;
|
|
18
19
|
//# sourceMappingURL=SignatureHelpProvider.d.ts.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AstNode } from '../../node/index.js';
|
|
2
|
+
import type { BinderContext } from '../../service/index.js';
|
|
3
|
+
declare const IsAsync: unique symbol;
|
|
4
|
+
export declare type Binder<N extends AstNode> = SyncBinder<N> | AsyncBinder<N>;
|
|
5
|
+
export interface SyncBinderInitializer<N extends AstNode> {
|
|
6
|
+
(node: N, ctx: BinderContext): void;
|
|
7
|
+
}
|
|
8
|
+
export interface SyncBinder<N extends AstNode> extends SyncBinderInitializer<N> {
|
|
9
|
+
[IsAsync]?: never;
|
|
10
|
+
}
|
|
11
|
+
export declare const SyncBinder: Readonly<{
|
|
12
|
+
create<N extends AstNode>(binder: SyncBinderInitializer<N>): SyncBinder<N>;
|
|
13
|
+
is(binder: Binder<any>): binder is SyncBinder<any>;
|
|
14
|
+
}>;
|
|
15
|
+
interface AsyncBinderInitializer<N extends AstNode> {
|
|
16
|
+
(node: N, ctx: BinderContext): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export interface AsyncBinder<N extends AstNode> extends AsyncBinderInitializer<N> {
|
|
19
|
+
[IsAsync]: true;
|
|
20
|
+
}
|
|
21
|
+
export declare const AsyncBinder: Readonly<{
|
|
22
|
+
create<N extends AstNode>(binder: AsyncBinderInitializer<N>): AsyncBinder<N>;
|
|
23
|
+
is(binder: Binder<any>): binder is AsyncBinder<any>;
|
|
24
|
+
}>;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=Binder.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const IsAsync = Symbol('IsAsyncBinder');
|
|
2
|
+
export const SyncBinder = Object.freeze({
|
|
3
|
+
create(binder) {
|
|
4
|
+
return binder;
|
|
5
|
+
},
|
|
6
|
+
is(binder) {
|
|
7
|
+
return !binder[IsAsync];
|
|
8
|
+
},
|
|
9
|
+
});
|
|
10
|
+
export const AsyncBinder = Object.freeze({
|
|
11
|
+
create(binder) {
|
|
12
|
+
return Object.assign(binder, { [IsAsync]: true });
|
|
13
|
+
},
|
|
14
|
+
is(binder) {
|
|
15
|
+
return binder[IsAsync];
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
//# sourceMappingURL=Binder.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AstNode, SymbolBaseNode } from '../../node/index.js';
|
|
2
|
+
import { ResourceLocationNode } from '../../node/index.js';
|
|
3
|
+
import type { BinderContext, MetaRegistry } from '../../service/index.js';
|
|
4
|
+
import type { Binder } from './Binder.js';
|
|
5
|
+
import { AsyncBinder, SyncBinder } from './Binder.js';
|
|
6
|
+
export declare type AttemptResult = {
|
|
7
|
+
errorAmount: number;
|
|
8
|
+
totalErrorSpan: number;
|
|
9
|
+
updateNodeAndCtx: () => void;
|
|
10
|
+
};
|
|
11
|
+
export declare function attempt<B extends Binder<never>>(binder: B, node: B extends Binder<infer N extends AstNode> ? N : never, ctx: BinderContext): B extends SyncBinder<any> ? AttemptResult : Promise<AttemptResult>;
|
|
12
|
+
declare type ExtractBinder<B extends Binder<never>> = B extends Binder<infer N extends AstNode> ? N : never;
|
|
13
|
+
export declare function any<Binders extends Binder<never>[]>(binders: Binders): Binders extends SyncBinder<never>[] ? SyncBinder<ExtractBinder<Binders[number]>> : AsyncBinder<ExtractBinder<Binders[number]>>;
|
|
14
|
+
/**
|
|
15
|
+
* No operation.
|
|
16
|
+
*/
|
|
17
|
+
export declare const noop: SyncBinder<AstNode>;
|
|
18
|
+
/**
|
|
19
|
+
* Use the shallowest children that have their own binder to validate.
|
|
20
|
+
*/
|
|
21
|
+
export declare const fallback: AsyncBinder<AstNode>;
|
|
22
|
+
export declare const dispatchSync: SyncBinder<AstNode>;
|
|
23
|
+
export declare const resourceLocation: SyncBinder<ResourceLocationNode>;
|
|
24
|
+
export declare const symbol: SyncBinder<SymbolBaseNode>;
|
|
25
|
+
export declare function registerBinders(meta: MetaRegistry): void;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=builtin.d.ts.map
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { localize } from '@spyglassmc/locales';
|
|
2
|
+
import { ResourceLocation, StateProxy } from '../../common/index.js';
|
|
3
|
+
import { ResourceLocationNode } from '../../node/index.js';
|
|
4
|
+
import { ErrorReporter } from '../../service/index.js';
|
|
5
|
+
import { traversePreOrder } from '../util.js';
|
|
6
|
+
import { AsyncBinder, SyncBinder } from './Binder.js';
|
|
7
|
+
export function attempt(binder, node, ctx) {
|
|
8
|
+
const tempCtx = {
|
|
9
|
+
...ctx,
|
|
10
|
+
err: new ErrorReporter(),
|
|
11
|
+
symbols: ctx.symbols.clone(),
|
|
12
|
+
};
|
|
13
|
+
const processAfterBinder = () => {
|
|
14
|
+
StateProxy.undoChanges(node);
|
|
15
|
+
const totalErrorSpan = tempCtx.err.errors
|
|
16
|
+
.map(e => e.range.end - e.range.start)
|
|
17
|
+
.reduce((a, b) => a + b, 0);
|
|
18
|
+
return {
|
|
19
|
+
errorAmount: tempCtx.err.errors.length,
|
|
20
|
+
totalErrorSpan,
|
|
21
|
+
updateNodeAndCtx: () => {
|
|
22
|
+
ctx.err.absorb(tempCtx.err);
|
|
23
|
+
StateProxy.redoChanges(node);
|
|
24
|
+
tempCtx.symbols.applyDelayedEdits();
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
if (SyncBinder.is(binder)) {
|
|
29
|
+
binder(node, tempCtx);
|
|
30
|
+
return processAfterBinder();
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
return (async () => {
|
|
34
|
+
await binder(node, tempCtx);
|
|
35
|
+
return processAfterBinder();
|
|
36
|
+
})();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export function any(binders) {
|
|
40
|
+
if (binders.length === 0) {
|
|
41
|
+
throw new Error('Expected at least one binder');
|
|
42
|
+
}
|
|
43
|
+
const attemptSorter = (a, b) => a.errorAmount - b.errorAmount || a.totalErrorSpan - b.totalErrorSpan;
|
|
44
|
+
if (binders.every(SyncBinder.is)) {
|
|
45
|
+
return SyncBinder.create((node, ctx) => {
|
|
46
|
+
const attempts = binders
|
|
47
|
+
.map(binder => attempt(binder, node, ctx))
|
|
48
|
+
.sort(attemptSorter);
|
|
49
|
+
attempts[0].updateNodeAndCtx();
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
return AsyncBinder.create(async (node, ctx) => {
|
|
54
|
+
const attempts = (await Promise.all(binders.map(binder => attempt(binder, node, ctx))))
|
|
55
|
+
.sort(attemptSorter);
|
|
56
|
+
attempts[0].updateNodeAndCtx();
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* No operation.
|
|
62
|
+
*/
|
|
63
|
+
export const noop = SyncBinder.create(() => { });
|
|
64
|
+
/**
|
|
65
|
+
* Use the shallowest children that have their own binder to validate.
|
|
66
|
+
*/
|
|
67
|
+
export const fallback = AsyncBinder.create(async (node, ctx) => {
|
|
68
|
+
const promises = [];
|
|
69
|
+
traversePreOrder(node, node => !ctx.meta.hasBinder(node.type), node => ctx.meta.hasBinder(node.type), node => {
|
|
70
|
+
const binder = ctx.meta.getBinder(node.type);
|
|
71
|
+
const result = binder(node, ctx);
|
|
72
|
+
if (result instanceof Promise) {
|
|
73
|
+
promises.push(result);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
await Promise.all(promises);
|
|
77
|
+
});
|
|
78
|
+
export const dispatchSync = SyncBinder.create((node, ctx) => {
|
|
79
|
+
for (const child of node.children ?? []) {
|
|
80
|
+
if (ctx.meta.hasBinder(child.type)) {
|
|
81
|
+
const binder = ctx.meta.getBinder(child.type);
|
|
82
|
+
binder(child, ctx);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
export const resourceLocation = SyncBinder.create((node, ctx) => {
|
|
87
|
+
if (node.options.category) {
|
|
88
|
+
const raw = ResourceLocationNode.toString(node, 'full');
|
|
89
|
+
const sanitizedRaw = ResourceLocation.lengthen(node.options.namespacePathSep === '.'
|
|
90
|
+
? raw.replace('.', ResourceLocation.NamespacePathSep)
|
|
91
|
+
: raw);
|
|
92
|
+
ctx.symbols
|
|
93
|
+
.query(ctx.doc, node.isTag ? `tag/${node.options.category}` : node.options.category, sanitizedRaw)
|
|
94
|
+
.enter({ usage: { type: node.options.usageType, node, accessType: node.options.accessType } });
|
|
95
|
+
}
|
|
96
|
+
const full = ResourceLocationNode.toString(node, 'full');
|
|
97
|
+
if (node.options.pool) {
|
|
98
|
+
if (!node.options.pool.includes(full)) {
|
|
99
|
+
ctx.err.report(localize('expected', node.options.pool), node, 3 /* ErrorSeverity.Error */);
|
|
100
|
+
}
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
export const symbol = SyncBinder.create((node, ctx) => {
|
|
105
|
+
if (node.value) {
|
|
106
|
+
const path = node.options.parentPath ? [...node.options.parentPath, node.value] : [node.value];
|
|
107
|
+
ctx.symbols
|
|
108
|
+
.query(ctx.doc, node.options.category, ...path)
|
|
109
|
+
.enter({ usage: { type: node.options.usageType, node: node, accessType: node.options.accessType } });
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
export function registerBinders(meta) {
|
|
113
|
+
meta.registerBinder('resource_location', resourceLocation);
|
|
114
|
+
meta.registerBinder('symbol', symbol);
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=builtin.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AstNode } from '../../node';
|
|
2
|
-
import type { CheckerContext } from '../../service';
|
|
1
|
+
import type { AstNode } from '../../node/index.js';
|
|
2
|
+
import type { CheckerContext } from '../../service/index.js';
|
|
3
3
|
export declare type Checker<N extends AstNode> = (node: N, ctx: CheckerContext) => PromiseLike<void> | void;
|
|
4
4
|
export declare type SyncChecker<N extends AstNode> = (node: N, ctx: CheckerContext) => void;
|
|
5
5
|
export declare type AsyncChecker<N extends AstNode> = (node: N, ctx: CheckerContext) => PromiseLike<void>;
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FallbackChecker = void 0;
|
|
4
1
|
/* istanbul ignore next */
|
|
5
|
-
const FallbackChecker = () => Promise.resolve();
|
|
6
|
-
exports.FallbackChecker = FallbackChecker;
|
|
2
|
+
export const FallbackChecker = () => Promise.resolve();
|
|
7
3
|
//# sourceMappingURL=Checker.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { AstNode, SymbolBaseNode } from '../../node';
|
|
2
|
-
import { ResourceLocationNode } from '../../node';
|
|
3
|
-
import type { CheckerContext, MetaRegistry } from '../../service';
|
|
4
|
-
import type { Checker, SyncChecker } from './Checker';
|
|
1
|
+
import type { AstNode, SymbolBaseNode } from '../../node/index.js';
|
|
2
|
+
import { ResourceLocationNode } from '../../node/index.js';
|
|
3
|
+
import type { CheckerContext, MetaRegistry } from '../../service/index.js';
|
|
4
|
+
import type { Checker, SyncChecker } from './Checker.js';
|
|
5
5
|
export declare type AttemptResult = {
|
|
6
6
|
errorAmount: number;
|
|
7
7
|
totalErrorSpan: number;
|