@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/common/util.js
CHANGED
|
@@ -1,56 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isIterable = exports.binarySearch = exports.getStates = exports.Lazy = exports.merge = exports.isObject = exports.parseGzippedJson = exports.zip = exports.unzip = exports.promisifyAsyncIterable = exports.TypePredicates = exports.Arrayable = exports.isEnoent = exports.isErrorCode = exports.getSha1 = exports.base64ToString = exports.stringToBase64 = exports.bufferToString = exports.ResourceLocation = exports.SpyglassUri = exports.Delay = exports.SingletonPromise = exports.CachePromise = exports.Uri = void 0;
|
|
7
|
-
const binary_search_1 = __importDefault(require("binary-search"));
|
|
8
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
9
|
-
const rfdc_1 = __importDefault(require("rfdc"));
|
|
10
|
-
const util_1 = require("util");
|
|
11
|
-
const zlib_1 = __importDefault(require("zlib"));
|
|
12
|
-
var url_1 = require("url");
|
|
13
|
-
Object.defineProperty(exports, "Uri", { enumerable: true, get: function () { return url_1.URL; } });
|
|
1
|
+
import externalBinarySearch from 'binary-search';
|
|
2
|
+
import rfdc from 'rfdc';
|
|
3
|
+
export const Uri = URL;
|
|
14
4
|
/**
|
|
15
|
-
* @param
|
|
16
|
-
* The result of this function will be used as the key to
|
|
5
|
+
* @param getKey A function that takes the actual arguments being passed into the decorated method, and returns anything.
|
|
6
|
+
* The result of this function will be used as the key to identify the `Promise`. By default the first element in the argument
|
|
17
7
|
* list will be used.
|
|
18
8
|
*
|
|
19
9
|
* This is a decorator for async methods. Decorated methods will return the same `Promise` for
|
|
20
|
-
* the same
|
|
10
|
+
* the same key, provided that the previously returned `Promise` is still pending.
|
|
21
11
|
*/
|
|
22
|
-
function
|
|
12
|
+
export function SingletonPromise(getKey = args => args[0]) {
|
|
23
13
|
return (_target, _key, descripter) => {
|
|
24
14
|
const promises = new Map();
|
|
25
15
|
const decoratedMethod = descripter.value;
|
|
26
16
|
// The `function` syntax is used to preserve `this` context from the decorated method.
|
|
27
17
|
descripter.value = function (...args) {
|
|
28
|
-
const
|
|
29
|
-
if (promises.has(
|
|
30
|
-
return promises.get(
|
|
18
|
+
const key = getKey(args);
|
|
19
|
+
if (promises.has(key)) {
|
|
20
|
+
return promises.get(key);
|
|
31
21
|
}
|
|
32
22
|
const ans = decoratedMethod.apply(this, args)
|
|
33
|
-
.then(ans => (promises.delete(
|
|
34
|
-
promises.set(
|
|
23
|
+
.then(ans => (promises.delete(key), ans), e => (promises.delete(key), Promise.reject(e)));
|
|
24
|
+
promises.set(key, ans);
|
|
35
25
|
return ans;
|
|
36
26
|
};
|
|
37
27
|
return descripter;
|
|
38
28
|
};
|
|
39
29
|
}
|
|
40
|
-
exports.CachePromise = CachePromise;
|
|
41
30
|
/**
|
|
42
|
-
* This is a decorator for
|
|
31
|
+
* This is a decorator for methods. Decorated methods will return the same non-`undefined` value no matter what.
|
|
43
32
|
*/
|
|
44
|
-
const
|
|
45
|
-
let
|
|
33
|
+
export const Singleton = (_target, _key, descripter) => {
|
|
34
|
+
let value;
|
|
46
35
|
const decoratedMethod = descripter.value;
|
|
47
36
|
// The `function` syntax is used to preserve `this` context from the decorated method.
|
|
48
37
|
descripter.value = function (...args) {
|
|
49
|
-
return
|
|
38
|
+
return value ??= decoratedMethod.apply(this, args);
|
|
50
39
|
};
|
|
51
40
|
return descripter;
|
|
52
41
|
};
|
|
53
|
-
exports.SingletonPromise = SingletonPromise;
|
|
54
42
|
/**
|
|
55
43
|
* @param getKey A function that takes the actual arguments being passed into the decorated method, and returns anything.
|
|
56
44
|
* The result of this function will be used as the key to cache the `Timeout`. By default the first element in the argument
|
|
@@ -58,7 +46,7 @@ exports.SingletonPromise = SingletonPromise;
|
|
|
58
46
|
*
|
|
59
47
|
* Decorated methods will be scheduled to run after `ms` milliseconds. The timer will reset when the method is called again.
|
|
60
48
|
*/
|
|
61
|
-
function Delay(ms, getKey = args => args[0]) {
|
|
49
|
+
export function Delay(ms, getKey = args => args[0]) {
|
|
62
50
|
return (_target, _key, descripter) => {
|
|
63
51
|
const timeouts = new Map();
|
|
64
52
|
const decoratedMethod = descripter.value;
|
|
@@ -76,42 +64,7 @@ function Delay(ms, getKey = args => args[0]) {
|
|
|
76
64
|
return descripter;
|
|
77
65
|
};
|
|
78
66
|
}
|
|
79
|
-
|
|
80
|
-
var SpyglassUri;
|
|
81
|
-
(function (SpyglassUri) {
|
|
82
|
-
SpyglassUri.Protocol = 'spyglassmc:';
|
|
83
|
-
let Archive;
|
|
84
|
-
(function (Archive) {
|
|
85
|
-
Archive.Hostname = 'archive';
|
|
86
|
-
function get(archiveUri, pathInArchive = '') {
|
|
87
|
-
return `${SpyglassUri.Protocol}//${Archive.Hostname}/${encodeURIComponent(archiveUri)}/${pathInArchive.replace(/\\/g, '/')}`;
|
|
88
|
-
}
|
|
89
|
-
Archive.get = get;
|
|
90
|
-
function is(uri) {
|
|
91
|
-
return uri.protocol === SpyglassUri.Protocol && uri.hostname === Archive.Hostname;
|
|
92
|
-
}
|
|
93
|
-
Archive.is = is;
|
|
94
|
-
/**
|
|
95
|
-
* @throws When `uri` has the wrong protocol or hostname.
|
|
96
|
-
*/
|
|
97
|
-
function decode(uri) {
|
|
98
|
-
if (uri.protocol !== SpyglassUri.Protocol) {
|
|
99
|
-
throw new Error(`Expected protocol “${SpyglassUri.Protocol}” in “${uri.toString()}”`);
|
|
100
|
-
}
|
|
101
|
-
if (uri.hostname !== Archive.Hostname) {
|
|
102
|
-
throw new Error(`Expected hostname “${Archive.Hostname}” in “${uri.toString()}”`);
|
|
103
|
-
}
|
|
104
|
-
// Ex. `pathname`: `/QzpcYS50YXIuZ3o=/foo/bar.json`
|
|
105
|
-
const paths = uri.pathname.split('/');
|
|
106
|
-
return {
|
|
107
|
-
archiveUri: decodeURIComponent(paths[1]),
|
|
108
|
-
pathInArchive: paths.slice(2).join('/'),
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
Archive.decode = decode;
|
|
112
|
-
})(Archive = SpyglassUri.Archive || (SpyglassUri.Archive = {}));
|
|
113
|
-
})(SpyglassUri = exports.SpyglassUri || (exports.SpyglassUri = {}));
|
|
114
|
-
var ResourceLocation;
|
|
67
|
+
export var ResourceLocation;
|
|
115
68
|
(function (ResourceLocation) {
|
|
116
69
|
/**
|
|
117
70
|
* The prefix for tags.
|
|
@@ -141,45 +94,19 @@ var ResourceLocation;
|
|
|
141
94
|
return value.replace(/^(?:minecraft)?:/, '');
|
|
142
95
|
}
|
|
143
96
|
ResourceLocation.shorten = shorten;
|
|
144
|
-
})(ResourceLocation
|
|
97
|
+
})(ResourceLocation || (ResourceLocation = {}));
|
|
145
98
|
/**
|
|
146
99
|
* @returns The string value decoded from the buffer according to UTF-8.
|
|
147
100
|
* Byte order mark is correctly removed.
|
|
148
101
|
*/
|
|
149
|
-
function bufferToString(buffer) {
|
|
150
|
-
const ans =
|
|
151
|
-
if (ans.charCodeAt(0) === 0xFEFF) {
|
|
152
|
-
|
|
153
|
-
}
|
|
102
|
+
export function bufferToString(buffer) {
|
|
103
|
+
const ans = new TextDecoder().decode(buffer);
|
|
104
|
+
// if (ans.charCodeAt(0) === 0xFEFF) {
|
|
105
|
+
// return ans.slice(1)
|
|
106
|
+
// }
|
|
154
107
|
return ans;
|
|
155
108
|
}
|
|
156
|
-
|
|
157
|
-
function stringToBase64(str) {
|
|
158
|
-
return Buffer.from(str).toString('base64');
|
|
159
|
-
}
|
|
160
|
-
exports.stringToBase64 = stringToBase64;
|
|
161
|
-
function base64ToString(base64) {
|
|
162
|
-
return Buffer.from(base64, 'base64').toString('utf-8');
|
|
163
|
-
}
|
|
164
|
-
exports.base64ToString = base64ToString;
|
|
165
|
-
/**
|
|
166
|
-
* @throws
|
|
167
|
-
*/
|
|
168
|
-
function getSha1(data) {
|
|
169
|
-
const hash = crypto_1.default.createHash('sha1');
|
|
170
|
-
hash.update(data);
|
|
171
|
-
return hash.digest('hex');
|
|
172
|
-
}
|
|
173
|
-
exports.getSha1 = getSha1;
|
|
174
|
-
function isErrorCode(e, code) {
|
|
175
|
-
return e instanceof Error && e.code === code;
|
|
176
|
-
}
|
|
177
|
-
exports.isErrorCode = isErrorCode;
|
|
178
|
-
function isEnoent(e) {
|
|
179
|
-
return isErrorCode(e, 'ENOENT');
|
|
180
|
-
}
|
|
181
|
-
exports.isEnoent = isEnoent;
|
|
182
|
-
var Arrayable;
|
|
109
|
+
export var Arrayable;
|
|
183
110
|
(function (Arrayable) {
|
|
184
111
|
function is(value, isT) {
|
|
185
112
|
return Array.isArray(value)
|
|
@@ -191,15 +118,15 @@ var Arrayable;
|
|
|
191
118
|
return Array.isArray(value) ? value : [value];
|
|
192
119
|
}
|
|
193
120
|
Arrayable.toArray = toArray;
|
|
194
|
-
})(Arrayable
|
|
195
|
-
var TypePredicates;
|
|
121
|
+
})(Arrayable || (Arrayable = {}));
|
|
122
|
+
export var TypePredicates;
|
|
196
123
|
(function (TypePredicates) {
|
|
197
124
|
function isString(value) {
|
|
198
125
|
return typeof value === 'string';
|
|
199
126
|
}
|
|
200
127
|
TypePredicates.isString = isString;
|
|
201
|
-
})(TypePredicates
|
|
202
|
-
function promisifyAsyncIterable(iterable, joiner) {
|
|
128
|
+
})(TypePredicates || (TypePredicates = {}));
|
|
129
|
+
export function promisifyAsyncIterable(iterable, joiner) {
|
|
203
130
|
return (async () => {
|
|
204
131
|
const chunks = [];
|
|
205
132
|
for await (const chunk of iterable) {
|
|
@@ -208,21 +135,19 @@ function promisifyAsyncIterable(iterable, joiner) {
|
|
|
208
135
|
return joiner(chunks);
|
|
209
136
|
})();
|
|
210
137
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
exports.zip = (0, util_1.promisify)(zlib_1.default.gzip);
|
|
214
|
-
async function parseGzippedJson(buffer) {
|
|
215
|
-
return JSON.parse(bufferToString(await (0, exports.unzip)(buffer)));
|
|
138
|
+
export async function parseGzippedJson(externals, buffer) {
|
|
139
|
+
return JSON.parse(bufferToString(await externals.archive.gunzip(buffer)));
|
|
216
140
|
}
|
|
217
|
-
|
|
218
|
-
|
|
141
|
+
/**
|
|
142
|
+
* @returns Is Plain Old JavaScript Object (POJO).
|
|
143
|
+
*/
|
|
144
|
+
export function isPojo(value) {
|
|
219
145
|
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
220
146
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const ans = (0, rfdc_1.default)()(a);
|
|
147
|
+
export function merge(a, b) {
|
|
148
|
+
const ans = rfdc()(a);
|
|
224
149
|
for (const [key, value] of Object.entries(b)) {
|
|
225
|
-
if (
|
|
150
|
+
if (isPojo(ans[key]) && isPojo(value)) {
|
|
226
151
|
ans[key] = merge(ans[key], value);
|
|
227
152
|
}
|
|
228
153
|
else if (value === undefined) {
|
|
@@ -234,8 +159,7 @@ function merge(a, b) {
|
|
|
234
159
|
}
|
|
235
160
|
return ans;
|
|
236
161
|
}
|
|
237
|
-
|
|
238
|
-
var Lazy;
|
|
162
|
+
export var Lazy;
|
|
239
163
|
(function (Lazy) {
|
|
240
164
|
const LazyDiscriminator = Symbol('LazyDiscriminator');
|
|
241
165
|
function create(getter) {
|
|
@@ -257,13 +181,13 @@ var Lazy;
|
|
|
257
181
|
return isUnresolved(lazy) ? lazy.value = lazy.getter() : lazy;
|
|
258
182
|
}
|
|
259
183
|
Lazy.resolve = resolve;
|
|
260
|
-
})(Lazy
|
|
184
|
+
})(Lazy || (Lazy = {}));
|
|
261
185
|
/**
|
|
262
186
|
* @param ids An array of block/fluid IDs, with or without the namespace.
|
|
263
187
|
* @returns A map from state names to the corresponding sets of values. The first element in the value array is the default
|
|
264
188
|
* value for that state.
|
|
265
189
|
*/
|
|
266
|
-
function getStates(category, ids, ctx) {
|
|
190
|
+
export function getStates(category, ids, ctx) {
|
|
267
191
|
const ans = {};
|
|
268
192
|
ids = ids.map(ResourceLocation.lengthen);
|
|
269
193
|
for (const id of ids) {
|
|
@@ -271,7 +195,7 @@ function getStates(category, ids, ctx) {
|
|
|
271
195
|
.query(ctx.doc, category, id)
|
|
272
196
|
.forEachMember((state, stateQuery) => {
|
|
273
197
|
const values = Object.keys(stateQuery.visibleMembers);
|
|
274
|
-
const set = ans[state]
|
|
198
|
+
const set = ans[state] ??= new Set();
|
|
275
199
|
const defaultValue = stateQuery.symbol?.relations?.default;
|
|
276
200
|
if (defaultValue) {
|
|
277
201
|
set.add(defaultValue.path[defaultValue.path.length - 1]);
|
|
@@ -283,10 +207,37 @@ function getStates(category, ids, ctx) {
|
|
|
283
207
|
}
|
|
284
208
|
return Object.fromEntries(Object.entries(ans).map(([k, v]) => [k, [...v]]));
|
|
285
209
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
function isIterable(value) {
|
|
210
|
+
export const binarySearch = externalBinarySearch;
|
|
211
|
+
export function isIterable(value) {
|
|
289
212
|
return !!value[Symbol.iterator];
|
|
290
213
|
}
|
|
291
|
-
|
|
214
|
+
//#region ESNext functions polyfill
|
|
215
|
+
export function atArray(array, index) {
|
|
216
|
+
return index >= 0 ? array?.[index] : array?.[array.length + index];
|
|
217
|
+
}
|
|
218
|
+
export function emplaceMap(map, key, handler) {
|
|
219
|
+
if (map.has(key)) {
|
|
220
|
+
let value = map.get(key);
|
|
221
|
+
if (handler.update) {
|
|
222
|
+
value = handler.update(value, key, map);
|
|
223
|
+
map.set(key, value);
|
|
224
|
+
}
|
|
225
|
+
return value;
|
|
226
|
+
}
|
|
227
|
+
else if (handler.insert) {
|
|
228
|
+
const value = handler.insert(key, map);
|
|
229
|
+
map.set(key, value);
|
|
230
|
+
return value;
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
throw new Error(`No key ${key} in map and no insert handler provided`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
//#endregion
|
|
237
|
+
/**
|
|
238
|
+
* @returns If `val` is an non-null object or a callable object (i.e. function).
|
|
239
|
+
*/
|
|
240
|
+
export function isObject(val) {
|
|
241
|
+
return typeof val === 'function' || (!!val && typeof val === 'object');
|
|
242
|
+
}
|
|
292
243
|
//# sourceMappingURL=util.js.map
|
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from './common';
|
|
2
|
-
export * from './node';
|
|
3
|
-
export * from './parser';
|
|
4
|
-
export * from './processor';
|
|
5
|
-
export * from './service';
|
|
6
|
-
export * from './source';
|
|
7
|
-
export * from './symbol';
|
|
1
|
+
export * from './common/index.js';
|
|
2
|
+
export * from './node/index.js';
|
|
3
|
+
export * from './parser/index.js';
|
|
4
|
+
export * from './processor/index.js';
|
|
5
|
+
export * from './service/index.js';
|
|
6
|
+
export * from './source/index.js';
|
|
7
|
+
export * from './symbol/index.js';
|
|
8
8
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.js
CHANGED
|
@@ -1,20 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
__exportStar(require("./common"), exports);
|
|
14
|
-
__exportStar(require("./node"), exports);
|
|
15
|
-
__exportStar(require("./parser"), exports);
|
|
16
|
-
__exportStar(require("./processor"), exports);
|
|
17
|
-
__exportStar(require("./service"), exports);
|
|
18
|
-
__exportStar(require("./source"), exports);
|
|
19
|
-
__exportStar(require("./symbol"), exports);
|
|
1
|
+
export * from './common/index.js';
|
|
2
|
+
export * from './node/index.js';
|
|
3
|
+
export * from './parser/index.js';
|
|
4
|
+
export * from './processor/index.js';
|
|
5
|
+
export * from './service/index.js';
|
|
6
|
+
export * from './source/index.js';
|
|
7
|
+
export * from './symbol/index.js';
|
|
20
8
|
//# sourceMappingURL=index.js.map
|
package/lib/node/AstNode.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import type { DeepReadonly } from '../common/index.js';
|
|
2
|
+
import type { Color, FormattableColor } from '../processor/index.js';
|
|
3
|
+
import { Range } from '../source/index.js';
|
|
4
|
+
import type { Symbol, SymbolTable } from '../symbol/index.js';
|
|
4
5
|
export interface AstNode {
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
type: string;
|
|
7
|
+
range: Range;
|
|
7
8
|
/**
|
|
8
9
|
* All child nodes of this AST node.
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
children?: AstNode[];
|
|
12
|
+
parent?: AstNode;
|
|
12
13
|
locals?: SymbolTable;
|
|
13
14
|
symbol?: Symbol;
|
|
14
15
|
hover?: string;
|
|
@@ -23,21 +24,21 @@ export declare namespace AstNode {
|
|
|
23
24
|
/**
|
|
24
25
|
* @param endInclusive Defaults to `false`.
|
|
25
26
|
*/
|
|
26
|
-
export function findChildIndex(node: AstNode
|
|
27
|
+
export function findChildIndex(node: DeepReadonly<AstNode>, needle: number | Range, endInclusive?: boolean): number;
|
|
27
28
|
/**
|
|
28
29
|
* @param endInclusive Defaults to `false`.
|
|
29
30
|
*/
|
|
30
|
-
export function findChild<N extends AstNode
|
|
31
|
+
export function findChild<N extends DeepReadonly<AstNode>>(node: N, needle: number | Range, endInclusive?: boolean): Exclude<N['children'], undefined>[number] | undefined;
|
|
31
32
|
/**
|
|
32
33
|
* Returns the index of the last child node that ends before the `needle`.
|
|
33
34
|
*
|
|
34
35
|
* @param endInclusive Defaults to `false`.
|
|
35
36
|
*/
|
|
36
|
-
export function findLastChildIndex(node: AstNode
|
|
37
|
+
export function findLastChildIndex(node: DeepReadonly<AstNode>, needle: number | Range, endInclusive?: boolean): number;
|
|
37
38
|
/**
|
|
38
39
|
* @param endInclusive Defaults to `false`.
|
|
39
40
|
*/
|
|
40
|
-
export function findLastChild<N extends AstNode
|
|
41
|
+
export function findLastChild<N extends DeepReadonly<AstNode>>(node: N, needle: number | Range, endInclusive?: boolean): (N['children'] extends readonly unknown[] ? N['children'][number] : undefined) | undefined;
|
|
41
42
|
interface FindRecursivelyOptions<P = (node: AstNode) => boolean> {
|
|
42
43
|
node: AstNode;
|
|
43
44
|
needle: number;
|
package/lib/node/AstNode.js
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.AstNode = void 0;
|
|
7
|
-
const binary_search_1 = __importDefault(require("binary-search"));
|
|
8
|
-
const source_1 = require("../source");
|
|
9
|
-
var AstNode;
|
|
1
|
+
import binarySearch from 'binary-search';
|
|
2
|
+
import { Range } from '../source/index.js';
|
|
3
|
+
export var AstNode;
|
|
10
4
|
(function (AstNode) {
|
|
11
5
|
/* istanbul ignore next */
|
|
12
6
|
function is(obj) {
|
|
13
7
|
return !!obj && typeof obj === 'object' && typeof obj.type === 'string' &&
|
|
14
|
-
|
|
8
|
+
Range.is(obj.range);
|
|
15
9
|
}
|
|
16
10
|
AstNode.is = is;
|
|
17
11
|
function setParents(node) {
|
|
@@ -28,8 +22,8 @@ var AstNode;
|
|
|
28
22
|
if (!node.children) {
|
|
29
23
|
return -1;
|
|
30
24
|
}
|
|
31
|
-
const comparator = typeof needle === 'number' ?
|
|
32
|
-
return (
|
|
25
|
+
const comparator = typeof needle === 'number' ? Range.compareOffset : Range.compare;
|
|
26
|
+
return binarySearch(node.children, needle, (a, b) => comparator(a.range, b, endInclusive));
|
|
33
27
|
}
|
|
34
28
|
AstNode.findChildIndex = findChildIndex;
|
|
35
29
|
/**
|
|
@@ -50,7 +44,7 @@ var AstNode;
|
|
|
50
44
|
}
|
|
51
45
|
let ans = -1;
|
|
52
46
|
for (const [i, childNode] of node.children.entries()) {
|
|
53
|
-
if (
|
|
47
|
+
if (Range.endsBefore(childNode.range, needle, endInclusive)) {
|
|
54
48
|
ans = i;
|
|
55
49
|
}
|
|
56
50
|
else {
|
|
@@ -69,7 +63,7 @@ var AstNode;
|
|
|
69
63
|
AstNode.findLastChild = findLastChild;
|
|
70
64
|
function findDeepestChild({ node, needle, endInclusive = false, predicate = () => true }) {
|
|
71
65
|
let last;
|
|
72
|
-
let head =
|
|
66
|
+
let head = Range.contains(node, needle, endInclusive) ? node : undefined;
|
|
73
67
|
while (head && predicate(head)) {
|
|
74
68
|
last = head;
|
|
75
69
|
head = findChild(head, needle, endInclusive);
|
|
@@ -78,7 +72,7 @@ var AstNode;
|
|
|
78
72
|
}
|
|
79
73
|
AstNode.findDeepestChild = findDeepestChild;
|
|
80
74
|
function findShallowestChild({ node, needle, endInclusive = false, predicate = () => true }) {
|
|
81
|
-
let head =
|
|
75
|
+
let head = Range.contains(node, needle, endInclusive) ? node : undefined;
|
|
82
76
|
while (head && !predicate(head)) {
|
|
83
77
|
head = findChild(head, needle, endInclusive);
|
|
84
78
|
}
|
|
@@ -104,5 +98,5 @@ var AstNode;
|
|
|
104
98
|
}
|
|
105
99
|
}
|
|
106
100
|
AstNode.getLocalsToLeaves = getLocalsToLeaves;
|
|
107
|
-
})(AstNode
|
|
101
|
+
})(AstNode || (AstNode = {}));
|
|
108
102
|
//# sourceMappingURL=AstNode.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { RangeLike } from '../source';
|
|
2
|
-
import type { AstNode } from './AstNode';
|
|
1
|
+
import type { RangeLike } from '../source/index.js';
|
|
2
|
+
import type { AstNode } from './AstNode.js';
|
|
3
3
|
export interface BooleanBaseNode extends AstNode {
|
|
4
4
|
readonly value?: boolean;
|
|
5
5
|
}
|
package/lib/node/BooleanNode.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.BooleanNode = void 0;
|
|
4
|
-
const source_1 = require("../source");
|
|
5
|
-
var BooleanNode;
|
|
1
|
+
import { Range } from '../source/index.js';
|
|
2
|
+
export var BooleanNode;
|
|
6
3
|
(function (BooleanNode) {
|
|
7
4
|
/* istanbul ignore next */
|
|
8
5
|
function is(obj) {
|
|
@@ -12,9 +9,9 @@ var BooleanNode;
|
|
|
12
9
|
function mock(range) {
|
|
13
10
|
return {
|
|
14
11
|
type: 'boolean',
|
|
15
|
-
range:
|
|
12
|
+
range: Range.get(range),
|
|
16
13
|
};
|
|
17
14
|
}
|
|
18
15
|
BooleanNode.mock = mock;
|
|
19
|
-
})(BooleanNode
|
|
16
|
+
})(BooleanNode || (BooleanNode = {}));
|
|
20
17
|
//# sourceMappingURL=BooleanNode.js.map
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DeepReadonly } from '../common/index.js';
|
|
2
|
+
import type { AstNode } from './AstNode.js';
|
|
2
3
|
export interface CommentNode extends AstNode {
|
|
3
4
|
readonly type: 'comment';
|
|
4
5
|
/**
|
|
5
6
|
* The actual comment with prefixes and suffixes removed.
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
export declare namespace CommentNode {
|
|
10
|
-
function is(obj: AstNode | undefined): obj is CommentNode;
|
|
8
|
+
comment: string;
|
|
11
9
|
}
|
|
10
|
+
export declare const CommentNode: Readonly<{
|
|
11
|
+
is<T extends DeepReadonly<AstNode> | undefined>(obj: T): obj is import("../common/util.js").IsHelper<AstNode, CommentNode, T>;
|
|
12
|
+
}>;
|
|
12
13
|
//# sourceMappingURL=CommentNode.d.ts.map
|
package/lib/node/CommentNode.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.CommentNode = void 0;
|
|
4
|
-
var CommentNode;
|
|
5
|
-
(function (CommentNode) {
|
|
6
|
-
function is(obj) {
|
|
1
|
+
export const CommentNode = Object.freeze({
|
|
2
|
+
is(obj) {
|
|
7
3
|
return obj?.type === 'comment';
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
})(CommentNode = exports.CommentNode || (exports.CommentNode = {}));
|
|
4
|
+
},
|
|
5
|
+
});
|
|
11
6
|
//# sourceMappingURL=CommentNode.js.map
|
package/lib/node/ErrorNode.d.ts
CHANGED
package/lib/node/ErrorNode.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ErrorNode = void 0;
|
|
4
|
-
var ErrorNode;
|
|
1
|
+
export var ErrorNode;
|
|
5
2
|
(function (ErrorNode) {
|
|
6
3
|
/* istanbul ignore next */
|
|
7
4
|
function is(obj) {
|
|
8
5
|
return obj.type === 'error';
|
|
9
6
|
}
|
|
10
7
|
ErrorNode.is = is;
|
|
11
|
-
})(ErrorNode
|
|
8
|
+
})(ErrorNode || (ErrorNode = {}));
|
|
12
9
|
//# sourceMappingURL=ErrorNode.js.map
|
package/lib/node/FileNode.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import type { AstNode } from '../node';
|
|
2
|
-
import type { LanguageError } from '../source';
|
|
3
|
-
import type { SymbolTable } from '../symbol';
|
|
1
|
+
import type { AstNode } from '../node/index.js';
|
|
2
|
+
import type { LanguageError } from '../source/index.js';
|
|
3
|
+
import type { SymbolTable } from '../symbol/index.js';
|
|
4
4
|
export interface FileNode<CN extends AstNode> extends AstNode {
|
|
5
5
|
readonly type: 'file';
|
|
6
6
|
readonly children: CN[];
|
|
7
7
|
locals: SymbolTable;
|
|
8
|
-
|
|
8
|
+
parserErrors: readonly LanguageError[];
|
|
9
|
+
/**
|
|
10
|
+
* Only exists when the file has been bound.
|
|
11
|
+
*/
|
|
12
|
+
binderErrors?: readonly LanguageError[];
|
|
9
13
|
/**
|
|
10
14
|
* Only exists when the file has been checked.
|
|
11
15
|
*/
|
package/lib/node/FileNode.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FileNode = void 0;
|
|
4
|
-
var FileNode;
|
|
1
|
+
export var FileNode;
|
|
5
2
|
(function (FileNode) {
|
|
6
3
|
function getErrors(node) {
|
|
7
|
-
return [...node.parserErrors, ...node.checkerErrors ?? [], ...node.linterErrors ?? []];
|
|
4
|
+
return [...node.parserErrors, ...node.binderErrors ?? [], ...node.checkerErrors ?? [], ...node.linterErrors ?? []];
|
|
8
5
|
}
|
|
9
6
|
FileNode.getErrors = getErrors;
|
|
10
|
-
})(FileNode
|
|
7
|
+
})(FileNode || (FileNode = {}));
|
|
11
8
|
//# sourceMappingURL=FileNode.js.map
|
package/lib/node/FloatNode.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { RangeLike } from '../source';
|
|
2
|
-
import type { AstNode } from './AstNode';
|
|
1
|
+
import type { RangeLike } from '../source/index.js';
|
|
2
|
+
import type { AstNode } from './AstNode.js';
|
|
3
3
|
export interface FloatBaseNode extends AstNode {
|
|
4
|
-
|
|
4
|
+
value: number;
|
|
5
5
|
}
|
|
6
6
|
export interface FloatNode extends FloatBaseNode {
|
|
7
7
|
readonly type: 'float';
|
package/lib/node/FloatNode.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.FloatNode = void 0;
|
|
4
|
-
const source_1 = require("../source");
|
|
5
|
-
var FloatNode;
|
|
1
|
+
import { Range } from '../source/index.js';
|
|
2
|
+
export var FloatNode;
|
|
6
3
|
(function (FloatNode) {
|
|
7
4
|
/* istanbul ignore next */
|
|
8
5
|
function is(obj) {
|
|
@@ -12,10 +9,10 @@ var FloatNode;
|
|
|
12
9
|
function mock(range) {
|
|
13
10
|
return {
|
|
14
11
|
type: 'float',
|
|
15
|
-
range:
|
|
12
|
+
range: Range.get(range),
|
|
16
13
|
value: 0,
|
|
17
14
|
};
|
|
18
15
|
}
|
|
19
16
|
FloatNode.mock = mock;
|
|
20
|
-
})(FloatNode
|
|
17
|
+
})(FloatNode || (FloatNode = {}));
|
|
21
18
|
//# sourceMappingURL=FloatNode.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { RangeLike } from '../source';
|
|
2
|
-
import type { AstNode } from './AstNode';
|
|
1
|
+
import type { RangeLike } from '../source/index.js';
|
|
2
|
+
import type { AstNode } from './AstNode.js';
|
|
3
3
|
export interface IntegerBaseNode extends AstNode {
|
|
4
|
-
|
|
4
|
+
value: number;
|
|
5
5
|
}
|
|
6
6
|
export interface IntegerNode extends IntegerBaseNode {
|
|
7
7
|
readonly type: 'integer';
|