@spyglassmc/core 0.4.0 → 0.4.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/lib/common/Dev.js +5 -2
- package/lib/common/Operations.js +7 -3
- package/lib/common/ReadonlyProxy.d.ts +2 -2
- package/lib/common/ReadonlyProxy.js +3 -1
- package/lib/common/StateProxy.d.ts +2 -2
- package/lib/common/StateProxy.js +18 -7
- package/lib/common/externals/BrowserExternals.js +2 -9
- package/lib/common/externals/NodeJsExternals.js +11 -18
- package/lib/common/externals/downloader.d.ts +2 -2
- package/lib/common/externals/index.d.ts +2 -5
- package/lib/common/util.d.ts +8 -7
- package/lib/common/util.js +16 -12
- package/lib/node/AstNode.d.ts +1 -1
- package/lib/node/AstNode.js +9 -5
- package/lib/node/CommentNode.d.ts +2 -2
- package/lib/node/FileNode.js +6 -1
- package/lib/node/ResourceLocationNode.d.ts +3 -3
- package/lib/node/ResourceLocationNode.js +9 -5
- package/lib/node/StringNode.d.ts +3 -3
- package/lib/node/StringNode.js +4 -1
- package/lib/parser/Parser.d.ts +5 -5
- package/lib/parser/boolean.js +1 -1
- package/lib/parser/comment.d.ts +1 -1
- package/lib/parser/comment.js +1 -1
- package/lib/parser/float.d.ts +1 -1
- package/lib/parser/float.js +2 -1
- package/lib/parser/integer.d.ts +1 -1
- package/lib/parser/integer.js +2 -1
- package/lib/parser/list.d.ts +1 -1
- package/lib/parser/list.js +3 -3
- package/lib/parser/long.d.ts +1 -1
- package/lib/parser/long.js +2 -1
- package/lib/parser/record.d.ts +1 -1
- package/lib/parser/record.js +18 -8
- package/lib/parser/resourceLocation.js +61 -8
- package/lib/parser/string.js +79 -8
- package/lib/parser/util.d.ts +7 -7
- package/lib/parser/util.js +14 -5
- package/lib/processor/ColorInfoProvider.d.ts +3 -3
- package/lib/processor/ColorInfoProvider.js +22 -7
- package/lib/processor/InlayHintProvider.d.ts +1 -1
- package/lib/processor/SignatureHelpProvider.d.ts +1 -1
- package/lib/processor/binder/Binder.d.ts +1 -1
- package/lib/processor/binder/builtin.d.ts +2 -2
- package/lib/processor/binder/builtin.js +30 -18
- package/lib/processor/binder/index.d.ts +1 -1
- package/lib/processor/binder/index.js +1 -1
- package/lib/processor/checker/Checker.d.ts +3 -3
- package/lib/processor/checker/builtin.d.ts +2 -3
- package/lib/processor/checker/builtin.js +12 -13
- package/lib/processor/colorizer/Colorizer.d.ts +3 -3
- package/lib/processor/colorizer/builtin.js +8 -7
- package/lib/processor/completer/Completer.d.ts +1 -1
- package/lib/processor/completer/Completer.js +4 -2
- package/lib/processor/completer/builtin.js +33 -26
- package/lib/processor/formatter/Formatter.d.ts +1 -1
- package/lib/processor/formatter/Formatter.js +3 -1
- package/lib/processor/formatter/builtin.js +14 -12
- package/lib/processor/linter/Linter.d.ts +1 -1
- package/lib/processor/linter/builtin/undeclaredSymbol.js +47 -24
- package/lib/processor/linter/builtin.js +7 -8
- package/lib/processor/util.d.ts +1 -1
- package/lib/service/CacheService.d.ts +1 -1
- package/lib/service/CacheService.js +9 -6
- package/lib/service/Config.d.ts +11 -11
- package/lib/service/Config.js +28 -21
- package/lib/service/Dependency.d.ts +3 -3
- package/lib/service/Downloader.js +12 -7
- package/lib/service/FileService.d.ts +1 -1
- package/lib/service/FileService.js +28 -10
- package/lib/service/MetaRegistry.js +7 -6
- package/lib/service/Profiler.js +10 -5
- package/lib/service/Project.d.ts +5 -5
- package/lib/service/Project.js +45 -34
- package/lib/service/Service.js +31 -12
- package/lib/service/SymbolRegistrar.d.ts +1 -1
- package/lib/service/UriProcessor.d.ts +3 -3
- package/lib/service/fileUtil.d.ts +2 -2
- package/lib/service/fileUtil.js +2 -1
- package/lib/source/IndexMap.d.ts +1 -1
- package/lib/source/IndexMap.js +1 -1
- package/lib/source/LanguageError.js +1 -1
- package/lib/source/Location.d.ts +1 -1
- package/lib/source/Location.js +4 -1
- package/lib/source/Offset.d.ts +1 -1
- package/lib/source/Range.d.ts +1 -1
- package/lib/source/Range.js +6 -3
- package/lib/source/Source.d.ts +4 -4
- package/lib/source/Source.js +3 -1
- package/lib/symbol/Symbol.d.ts +19 -19
- package/lib/symbol/Symbol.js +27 -12
- package/lib/symbol/SymbolUtil.d.ts +6 -6
- package/lib/symbol/SymbolUtil.js +76 -44
- package/package.json +2 -2
package/lib/symbol/Symbol.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import rfdc from 'rfdc';
|
|
2
2
|
import { isIterable } from '../common/index.js';
|
|
3
3
|
import { Location, PositionRange, Range } from '../source/index.js';
|
|
4
|
-
|
|
4
|
+
// #region Mcdoc Categories
|
|
5
5
|
export const McdocCategories = Object.freeze([
|
|
6
6
|
'mcdoc',
|
|
7
7
|
'mcdoc/dispatcher',
|
|
8
8
|
]);
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
// #endregion
|
|
10
|
+
// #region Registry Categories
|
|
11
11
|
// Data in `java-edition/src/binder/index.ts` may need to be updated when this section is changed.
|
|
12
12
|
export const RegistryCategories = Object.freeze([
|
|
13
13
|
'activity',
|
|
@@ -69,14 +69,15 @@ export const RegistryCategories = Object.freeze([
|
|
|
69
69
|
'worldgen/tree_decorator_type',
|
|
70
70
|
'worldgen/trunk_placer_type',
|
|
71
71
|
]);
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
// #endregion
|
|
73
|
+
// #region Data Pack Categories
|
|
74
74
|
export const WorldgenFileCategories = Object.freeze([
|
|
75
75
|
'worldgen/biome',
|
|
76
76
|
'worldgen/configured_carver',
|
|
77
77
|
'worldgen/configured_feature',
|
|
78
78
|
'worldgen/configured_structure_feature',
|
|
79
79
|
'worldgen/configured_surface_builder',
|
|
80
|
+
'worldgen/density_function',
|
|
80
81
|
'worldgen/noise',
|
|
81
82
|
'worldgen/noise_settings',
|
|
82
83
|
'worldgen/placed_feature',
|
|
@@ -88,7 +89,7 @@ export const TaggableResourceLocationCategories = Object.freeze([
|
|
|
88
89
|
...RegistryCategories,
|
|
89
90
|
...WorldgenFileCategories,
|
|
90
91
|
]);
|
|
91
|
-
export const TagFileCategories = Object.freeze(TaggableResourceLocationCategories.map(key => `tag/${key}`));
|
|
92
|
+
export const TagFileCategories = Object.freeze(TaggableResourceLocationCategories.map((key) => `tag/${key}`));
|
|
92
93
|
export const FileCategories = Object.freeze([
|
|
93
94
|
'advancement',
|
|
94
95
|
'dimension',
|
|
@@ -115,7 +116,7 @@ export const DatapackCategories = Object.freeze([
|
|
|
115
116
|
...FileCategories,
|
|
116
117
|
...MiscCategories,
|
|
117
118
|
]);
|
|
118
|
-
|
|
119
|
+
// #endregion
|
|
119
120
|
export const AllCategories = Object.freeze([
|
|
120
121
|
...DatapackCategories,
|
|
121
122
|
...McdocCategories,
|
|
@@ -170,7 +171,13 @@ export class SymbolPathCollector {
|
|
|
170
171
|
return [...this.#set].map(SymbolPath.fromString);
|
|
171
172
|
}
|
|
172
173
|
}
|
|
173
|
-
export const SymbolUsageTypes = Object.freeze([
|
|
174
|
+
export const SymbolUsageTypes = Object.freeze([
|
|
175
|
+
'definition',
|
|
176
|
+
'declaration',
|
|
177
|
+
'implementation',
|
|
178
|
+
'reference',
|
|
179
|
+
'typeDefinition',
|
|
180
|
+
]);
|
|
174
181
|
export var SymbolUsageType;
|
|
175
182
|
(function (SymbolUsageType) {
|
|
176
183
|
function is(value) {
|
|
@@ -203,9 +210,14 @@ export var SymbolLocation;
|
|
|
203
210
|
function create(doc, range, fullRange, contributor, additional) {
|
|
204
211
|
return {
|
|
205
212
|
...Location.create(doc, range),
|
|
206
|
-
...
|
|
207
|
-
|
|
208
|
-
|
|
213
|
+
...(fullRange
|
|
214
|
+
? {
|
|
215
|
+
fullRange: Range.get(fullRange),
|
|
216
|
+
fullPosRange: PositionRange.from(fullRange, doc),
|
|
217
|
+
}
|
|
218
|
+
: {}),
|
|
219
|
+
...(contributor ? { contributor } : {}),
|
|
220
|
+
...(additional ? additional : {}),
|
|
209
221
|
};
|
|
210
222
|
}
|
|
211
223
|
SymbolLocation.create = create;
|
|
@@ -233,7 +245,10 @@ export var SymbolTable;
|
|
|
233
245
|
};
|
|
234
246
|
const linkSymbolMap = (map, parentSymbol, category, path) => {
|
|
235
247
|
for (const [identifier, childSymbol] of Object.entries(map)) {
|
|
236
|
-
linkSymbol(childSymbol, map, parentSymbol, category, [
|
|
248
|
+
linkSymbol(childSymbol, map, parentSymbol, category, [
|
|
249
|
+
...path,
|
|
250
|
+
identifier,
|
|
251
|
+
]);
|
|
237
252
|
}
|
|
238
253
|
};
|
|
239
254
|
const ans = rfdc()(table);
|
|
@@ -99,7 +99,7 @@ export declare class SymbolUtil implements ExternalEventEmitter {
|
|
|
99
99
|
* - `uri` - clear symbol locations associated with this URI.
|
|
100
100
|
* - `predicate` - clear symbol locations matching this predicate
|
|
101
101
|
*/
|
|
102
|
-
clear({ uri, contributor, predicate }: {
|
|
102
|
+
clear({ uri, contributor, predicate, }: {
|
|
103
103
|
contributor?: string;
|
|
104
104
|
uri?: string;
|
|
105
105
|
predicate?: (this: void, data: SymbolLocationEvent) => boolean;
|
|
@@ -213,7 +213,7 @@ interface SymbolAddition {
|
|
|
213
213
|
data?: SymbolMetadata;
|
|
214
214
|
usage?: SymbolAdditionUsage;
|
|
215
215
|
}
|
|
216
|
-
|
|
216
|
+
type SymbolAdditionUsage = SymbolAdditionUsageWithRange | SymbolAdditionUsageWithNode;
|
|
217
217
|
interface SymbolAdditionUsageBase extends SymbolLocationMetadata {
|
|
218
218
|
/**
|
|
219
219
|
* The type of this usage. Use `definition` when the usage consists both a `declaration` and an `implementation`.
|
|
@@ -269,9 +269,9 @@ declare namespace SymbolAdditionUsageWithNode {
|
|
|
269
269
|
* which is accessible by any later elements but not saved to the global `SymbolTable`.
|
|
270
270
|
* Later elements represent different levels of `Block` visibility scopes.
|
|
271
271
|
*/
|
|
272
|
-
export
|
|
273
|
-
|
|
274
|
-
|
|
272
|
+
export type SymbolStack = [SymbolTable, ...SymbolTable[]];
|
|
273
|
+
type QueryCallback<S extends Symbol | undefined = Symbol | undefined> = (this: SymbolQuery, symbol: S, query: SymbolQuery) => unknown;
|
|
274
|
+
type QueryMemberCallback = (this: void, query: SymbolQuery) => unknown;
|
|
275
275
|
export declare class SymbolQuery {
|
|
276
276
|
#private;
|
|
277
277
|
readonly category: string;
|
|
@@ -282,7 +282,7 @@ export declare class SymbolQuery {
|
|
|
282
282
|
util: SymbolUtil;
|
|
283
283
|
get symbol(): Symbol | undefined;
|
|
284
284
|
get visibleMembers(): SymbolMap;
|
|
285
|
-
constructor({ category, contributor, doc, map, parentSymbol, path, symbol, util }: {
|
|
285
|
+
constructor({ category, contributor, doc, map, parentSymbol, path, symbol, util, }: {
|
|
286
286
|
category: string;
|
|
287
287
|
contributor: string | undefined;
|
|
288
288
|
doc: DocAndNode | TextDocument | string;
|
package/lib/symbol/SymbolUtil.js
CHANGED
|
@@ -6,7 +6,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
};
|
|
7
7
|
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
8
8
|
import { Range } from '../source/index.js';
|
|
9
|
-
import { SymbolLocation, SymbolPath, SymbolUsageTypes } from './Symbol.js';
|
|
9
|
+
import { SymbolLocation, SymbolPath, SymbolUsageTypes, } from './Symbol.js';
|
|
10
10
|
export class SymbolUtil {
|
|
11
11
|
#global;
|
|
12
12
|
#eventEmitter;
|
|
@@ -35,16 +35,16 @@ export class SymbolUtil {
|
|
|
35
35
|
this.#global = global;
|
|
36
36
|
this.#currentContributor = _currentContributor;
|
|
37
37
|
this._inDelayMode = _inDelayMode;
|
|
38
|
-
this
|
|
39
|
-
.on('symbolCreated', ({ symbol }) => {
|
|
38
|
+
this.on('symbolCreated', ({ symbol }) => {
|
|
40
39
|
this.#trimmableSymbols.add(SymbolPath.toString(symbol));
|
|
41
40
|
})
|
|
42
41
|
.on('symbolRemoved', ({ symbol }) => {
|
|
43
42
|
this.#trimmableSymbols.delete(SymbolPath.toString(symbol));
|
|
44
43
|
})
|
|
45
44
|
.on('symbolLocationCreated', ({ symbol, location }) => {
|
|
46
|
-
const cache = this.#cache[location.contributor ?? 'undefined'] ??= Object
|
|
47
|
-
|
|
45
|
+
const cache = (this.#cache[location.contributor ?? 'undefined'] ??= Object
|
|
46
|
+
.create(null));
|
|
47
|
+
const fileSymbols = (cache[location.uri] ??= new Set());
|
|
48
48
|
const path = SymbolPath.toString(symbol);
|
|
49
49
|
fileSymbols.add(path);
|
|
50
50
|
this.#trimmableSymbols.delete(path);
|
|
@@ -69,7 +69,7 @@ export class SymbolUtil {
|
|
|
69
69
|
* Build the internal cache of the SymbolUtil according to the current global symbol table.
|
|
70
70
|
*/
|
|
71
71
|
buildCache() {
|
|
72
|
-
SymbolUtil.forEachSymbol(this.global, symbol => {
|
|
72
|
+
SymbolUtil.forEachSymbol(this.global, (symbol) => {
|
|
73
73
|
this.emit('symbolCreated', { symbol });
|
|
74
74
|
SymbolUtil.forEachLocationOfSymbol(symbol, ({ type, location }) => {
|
|
75
75
|
this.emit('symbolLocationCreated', { symbol, type, location });
|
|
@@ -90,7 +90,7 @@ export class SymbolUtil {
|
|
|
90
90
|
* Apply edits done during the delay mode.
|
|
91
91
|
*/
|
|
92
92
|
applyDelayedEdits() {
|
|
93
|
-
this._delayedOps.forEach(f => f());
|
|
93
|
+
this._delayedOps.forEach((f) => f());
|
|
94
94
|
this._delayedOps = [];
|
|
95
95
|
this._inDelayMode = false;
|
|
96
96
|
}
|
|
@@ -123,7 +123,7 @@ export class SymbolUtil {
|
|
|
123
123
|
* - `uri` - clear symbol locations associated with this URI.
|
|
124
124
|
* - `predicate` - clear symbol locations matching this predicate
|
|
125
125
|
*/
|
|
126
|
-
clear({ uri, contributor, predicate = () => true }) {
|
|
126
|
+
clear({ uri, contributor, predicate = () => true, }) {
|
|
127
127
|
const getCaches = () => {
|
|
128
128
|
if (contributor) {
|
|
129
129
|
return this.#cache[contributor] ? [this.#cache[contributor]] : [];
|
|
@@ -135,14 +135,15 @@ export class SymbolUtil {
|
|
|
135
135
|
const getPaths = () => {
|
|
136
136
|
const caches = getCaches();
|
|
137
137
|
const sets = uri
|
|
138
|
-
? caches.map(cache => cache[uri] ?? new Set())
|
|
139
|
-
: caches.map(cache => Object.values(cache)).flat();
|
|
140
|
-
return sets
|
|
138
|
+
? caches.map((cache) => cache[uri] ?? new Set())
|
|
139
|
+
: caches.map((cache) => Object.values(cache)).flat();
|
|
140
|
+
return sets
|
|
141
|
+
.map((s) => [...s])
|
|
142
|
+
.flat()
|
|
143
|
+
.map(SymbolPath.fromString);
|
|
141
144
|
};
|
|
142
145
|
const getTables = () => {
|
|
143
|
-
return uri
|
|
144
|
-
? [this.#global]
|
|
145
|
-
: [this.#global];
|
|
146
|
+
return uri ? [this.#global] : [this.#global];
|
|
146
147
|
};
|
|
147
148
|
const paths = getPaths();
|
|
148
149
|
const tables = getTables();
|
|
@@ -153,7 +154,7 @@ export class SymbolUtil {
|
|
|
153
154
|
continue;
|
|
154
155
|
}
|
|
155
156
|
this.removeLocationsFromSymbol(symbol, uri
|
|
156
|
-
? data => data.location.uri === uri && predicate(data)
|
|
157
|
+
? (data) => data.location.uri === uri && predicate(data)
|
|
157
158
|
: predicate);
|
|
158
159
|
}
|
|
159
160
|
this.trim(table);
|
|
@@ -277,7 +278,9 @@ export class SymbolUtil {
|
|
|
277
278
|
if (result.symbol) {
|
|
278
279
|
return result;
|
|
279
280
|
}
|
|
280
|
-
if (!parentSymbol &&
|
|
281
|
+
if (!parentSymbol &&
|
|
282
|
+
!parentMap &&
|
|
283
|
+
(result.parentSymbol || result.parentMap)) {
|
|
281
284
|
parentSymbol = result.parentSymbol;
|
|
282
285
|
parentMap = result.parentMap;
|
|
283
286
|
}
|
|
@@ -285,14 +288,14 @@ export class SymbolUtil {
|
|
|
285
288
|
return { parentSymbol, parentMap, symbol: undefined };
|
|
286
289
|
}
|
|
287
290
|
createSymbol(category, parentSymbol, parentMap, path, identifier, addition, doc, contributor) {
|
|
288
|
-
const ans = parentMap[identifier] = {
|
|
291
|
+
const ans = (parentMap[identifier] = {
|
|
289
292
|
category,
|
|
290
293
|
identifier,
|
|
291
|
-
...parentSymbol ? { parentSymbol } : {},
|
|
294
|
+
...(parentSymbol ? { parentSymbol } : {}),
|
|
292
295
|
parentMap,
|
|
293
296
|
path,
|
|
294
297
|
...addition.data,
|
|
295
|
-
};
|
|
298
|
+
});
|
|
296
299
|
this.emit('symbolCreated', { symbol: ans });
|
|
297
300
|
this.amendSymbolUsage(ans, addition.usage, doc, contributor);
|
|
298
301
|
return ans;
|
|
@@ -321,8 +324,12 @@ export class SymbolUtil {
|
|
|
321
324
|
if ('visibility' in addition) {
|
|
322
325
|
// Visibility changes are only accepted if the change wouldn't result in the
|
|
323
326
|
// symbol being stored in a different symbol table.
|
|
324
|
-
const inGlobalTable = (v) => v === undefined ||
|
|
325
|
-
|
|
327
|
+
const inGlobalTable = (v) => v === undefined ||
|
|
328
|
+
v === 2 /* SymbolVisibility.Public */ ||
|
|
329
|
+
v === 3 /* SymbolVisibility.Restricted */;
|
|
330
|
+
if (symbol.visibility === addition.visibility ||
|
|
331
|
+
(inGlobalTable(symbol.visibility) &&
|
|
332
|
+
inGlobalTable(addition.visibility))) {
|
|
326
333
|
symbol.visibility = addition.visibility;
|
|
327
334
|
}
|
|
328
335
|
else {
|
|
@@ -337,8 +344,10 @@ export class SymbolUtil {
|
|
|
337
344
|
amendSymbolUsage(symbol, addition, doc, contributor) {
|
|
338
345
|
if (addition) {
|
|
339
346
|
const type = addition.type ?? 'reference';
|
|
340
|
-
const arr = symbol[type] ??= [];
|
|
341
|
-
const range = Range.get((SymbolAdditionUsageWithNode.is(addition)
|
|
347
|
+
const arr = (symbol[type] ??= []);
|
|
348
|
+
const range = Range.get((SymbolAdditionUsageWithNode.is(addition)
|
|
349
|
+
? addition.node
|
|
350
|
+
: addition.range) ?? 0);
|
|
342
351
|
const location = SymbolLocation.create(doc, range, addition.fullRange, contributor, {
|
|
343
352
|
accessType: addition.accessType,
|
|
344
353
|
skipRenaming: addition.skipRenaming,
|
|
@@ -371,7 +380,12 @@ export class SymbolUtil {
|
|
|
371
380
|
return ans;
|
|
372
381
|
}
|
|
373
382
|
static isTrimmable(symbol) {
|
|
374
|
-
return !Object.keys(symbol.members ?? {}).length &&
|
|
383
|
+
return (!Object.keys(symbol.members ?? {}).length &&
|
|
384
|
+
!symbol.declaration?.length &&
|
|
385
|
+
!symbol.definition?.length &&
|
|
386
|
+
!symbol.implementation?.length &&
|
|
387
|
+
!symbol.reference?.length &&
|
|
388
|
+
!symbol.typeDefinition?.length);
|
|
375
389
|
}
|
|
376
390
|
static isVisible(symbol, _uri) {
|
|
377
391
|
switch (symbol.visibility) {
|
|
@@ -394,7 +408,8 @@ export class SymbolUtil {
|
|
|
394
408
|
* @returns If the symbol has definitions, or declarations and implementations.
|
|
395
409
|
*/
|
|
396
410
|
static isDefined(symbol) {
|
|
397
|
-
return !!(symbol?.definition?.length ||
|
|
411
|
+
return !!(symbol?.definition?.length ||
|
|
412
|
+
(symbol?.definition?.length && symbol?.implementation?.length));
|
|
398
413
|
}
|
|
399
414
|
/**
|
|
400
415
|
* @returns If the symbol has implementations or definitions.
|
|
@@ -418,7 +433,11 @@ export class SymbolUtil {
|
|
|
418
433
|
* @throws If the symbol does not have any declarations or definitions.
|
|
419
434
|
*/
|
|
420
435
|
static getDeclaredLocation(symbol) {
|
|
421
|
-
return symbol.declaration?.[0] ??
|
|
436
|
+
return (symbol.declaration?.[0] ??
|
|
437
|
+
symbol.definition?.[0] ??
|
|
438
|
+
(() => {
|
|
439
|
+
throw new Error(`Cannot get declared location of ${JSON.stringify(SymbolPath.fromSymbol(symbol))}`);
|
|
440
|
+
})());
|
|
422
441
|
}
|
|
423
442
|
static forEachSymbolInMap(map, fn) {
|
|
424
443
|
for (const symbol of Object.values(map)) {
|
|
@@ -435,11 +454,13 @@ export class SymbolUtil {
|
|
|
435
454
|
}
|
|
436
455
|
static forEachLocationOfSymbol(symbol, fn) {
|
|
437
456
|
for (const type of SymbolUsageTypes) {
|
|
438
|
-
symbol[type]?.forEach(location => fn({ type, location }));
|
|
457
|
+
symbol[type]?.forEach((location) => fn({ type, location }));
|
|
439
458
|
}
|
|
440
459
|
}
|
|
441
460
|
static isVisibilityInGlobal(v) {
|
|
442
|
-
return v === undefined ||
|
|
461
|
+
return (v === undefined ||
|
|
462
|
+
v === 2 /* SymbolVisibility.Public */ ||
|
|
463
|
+
v === 3 /* SymbolVisibility.Restricted */);
|
|
443
464
|
}
|
|
444
465
|
static areVisibilitiesCompatible(v1, v2) {
|
|
445
466
|
return ((this.isVisibilityInGlobal(v1) && this.isVisibilityInGlobal(v2)) ||
|
|
@@ -505,7 +526,7 @@ export class SymbolQuery {
|
|
|
505
526
|
get visibleMembers() {
|
|
506
527
|
return SymbolUtil.filterVisibleSymbols(this.#doc.uri, this.path.length === 0 ? this.#map : this.#symbol?.members);
|
|
507
528
|
}
|
|
508
|
-
constructor({ category, contributor, doc, map, parentSymbol, path, symbol, util }) {
|
|
529
|
+
constructor({ category, contributor, doc, map, parentSymbol, path, symbol, util, }) {
|
|
509
530
|
this.category = category;
|
|
510
531
|
this.path = path;
|
|
511
532
|
if (typeof doc === 'string') {
|
|
@@ -545,13 +566,13 @@ export class SymbolQuery {
|
|
|
545
566
|
* Calls `fn` if the queried symbol does not exist.
|
|
546
567
|
*/
|
|
547
568
|
ifUnknown(fn) {
|
|
548
|
-
return this.if(s => s === undefined, fn);
|
|
569
|
+
return this.if((s) => s === undefined, fn);
|
|
549
570
|
}
|
|
550
571
|
/**
|
|
551
572
|
* Calls `fn` if the queried symbol exists (i.e. has any of declarations/definitions/implementations/references/typeDefinitions).
|
|
552
573
|
*/
|
|
553
574
|
ifKnown(fn) {
|
|
554
|
-
return this.if(s => s !== undefined, fn);
|
|
575
|
+
return this.if((s) => s !== undefined, fn);
|
|
555
576
|
}
|
|
556
577
|
/**
|
|
557
578
|
* Calls `fn` if the queried symbol has declarations or definitions.
|
|
@@ -613,11 +634,14 @@ export class SymbolQuery {
|
|
|
613
634
|
* * If the visibility is `undefined`, use the visibility of the symbol, or `Public` if unapplicable.
|
|
614
635
|
*/
|
|
615
636
|
const getAdditionVisibility = (addition) => {
|
|
616
|
-
return addition.data?.visibility ??
|
|
637
|
+
return (addition.data?.visibility ??
|
|
638
|
+
this.symbol?.visibility ??
|
|
639
|
+
2 /* SymbolVisibility.Public */);
|
|
617
640
|
};
|
|
618
641
|
const getMap = (addition) => {
|
|
619
642
|
const additionVisibility = getAdditionVisibility(addition);
|
|
620
|
-
if (this.#map &&
|
|
643
|
+
if (this.#map &&
|
|
644
|
+
SymbolUtil.areVisibilitiesCompatible(additionVisibility, this.#symbol?.visibility)) {
|
|
621
645
|
return this.#map;
|
|
622
646
|
}
|
|
623
647
|
if (this.path.length > 1) {
|
|
@@ -625,7 +649,7 @@ export class SymbolQuery {
|
|
|
625
649
|
if (!SymbolUtil.areVisibilitiesCompatible(additionVisibility, this.#parentSymbol.visibility)) {
|
|
626
650
|
throw new Error(`Cannot enter member “${this.getPath()}” of ${SymbolFormatter.stringifyVisibility(additionVisibility)} visibility to parent of ${SymbolFormatter.stringifyVisibility(this.#parentSymbol.visibility)} visibility`);
|
|
627
651
|
}
|
|
628
|
-
return this.#parentSymbol.members ??= {};
|
|
652
|
+
return (this.#parentSymbol.members ??= {});
|
|
629
653
|
}
|
|
630
654
|
}
|
|
631
655
|
else {
|
|
@@ -666,12 +690,13 @@ export class SymbolQuery {
|
|
|
666
690
|
}
|
|
667
691
|
}
|
|
668
692
|
// TODO: Move part of symbol from global to table.
|
|
669
|
-
return table[this.category] ??= {};
|
|
693
|
+
return (table[this.category] ??= {});
|
|
670
694
|
}
|
|
671
695
|
throw new Error(`Cannot create the symbol map for “${this.getPath()}”`);
|
|
672
696
|
};
|
|
673
697
|
// Treat `usage.range` as `[0, 0)` if this class was constructed with a string URI (instead of a `TextDocument`).
|
|
674
|
-
if (this.#createdWithUri &&
|
|
698
|
+
if (this.#createdWithUri &&
|
|
699
|
+
SymbolAdditionUsageWithRange.is(addition.usage)) {
|
|
675
700
|
addition.usage.range = Range.create(0, 0);
|
|
676
701
|
}
|
|
677
702
|
this.#map = getMap(addition);
|
|
@@ -738,7 +763,8 @@ export class SymbolQuery {
|
|
|
738
763
|
if (this.#symbol === undefined) {
|
|
739
764
|
throw new Error(`Tried to query member symbol “${identifier}” from an undefined symbol (path “${this.path.join('.')}”)`);
|
|
740
765
|
}
|
|
741
|
-
const memberDoc = typeof doc === 'string' && doc === this.#doc.uri &&
|
|
766
|
+
const memberDoc = typeof doc === 'string' && doc === this.#doc.uri &&
|
|
767
|
+
!this.#createdWithUri
|
|
742
768
|
? this.#doc
|
|
743
769
|
: doc;
|
|
744
770
|
const memberMap = this.#symbol.members;
|
|
@@ -767,7 +793,7 @@ export class SymbolQuery {
|
|
|
767
793
|
return this;
|
|
768
794
|
}
|
|
769
795
|
forEachMember(fn) {
|
|
770
|
-
return this.onEach(Object.keys(this.visibleMembers), identifier => this.member(identifier, query => fn(identifier, query)));
|
|
796
|
+
return this.onEach(Object.keys(this.visibleMembers), (identifier) => this.member(identifier, (query) => fn(identifier, query)));
|
|
771
797
|
}
|
|
772
798
|
getPath() {
|
|
773
799
|
return `${this.category}.${this.path.join('/')}`;
|
|
@@ -789,7 +815,9 @@ export var SymbolFormatter;
|
|
|
789
815
|
}
|
|
790
816
|
}
|
|
791
817
|
function stringifySymbolStack(stack) {
|
|
792
|
-
return stack
|
|
818
|
+
return stack
|
|
819
|
+
.map((table) => stringifySymbolTable(table))
|
|
820
|
+
.join('\n------------\n');
|
|
793
821
|
}
|
|
794
822
|
SymbolFormatter.stringifySymbolStack = stringifySymbolStack;
|
|
795
823
|
function stringifySymbolTable(table, indent = '') {
|
|
@@ -798,7 +826,9 @@ export var SymbolFormatter;
|
|
|
798
826
|
const map = table[category];
|
|
799
827
|
ans.push([category, stringifySymbolMap(map, `${indent}${IndentChar}`)]);
|
|
800
828
|
}
|
|
801
|
-
return ans
|
|
829
|
+
return (ans
|
|
830
|
+
.map((v) => `CATEGORY ${v[0]}\n${v[1]}`)
|
|
831
|
+
.join(`\n${indent}------------\n`) || 'EMPTY TABLE');
|
|
802
832
|
}
|
|
803
833
|
SymbolFormatter.stringifySymbolTable = stringifySymbolTable;
|
|
804
834
|
function stringifySymbolMap(map, indent = '') {
|
|
@@ -831,7 +861,7 @@ export var SymbolFormatter;
|
|
|
831
861
|
}
|
|
832
862
|
for (const type of SymbolUsageTypes) {
|
|
833
863
|
if (symbol[type]) {
|
|
834
|
-
ans.push(`${IndentChar}${type}:\n${symbol[type].map(v => `${indent}${IndentChar.repeat(2)}${JSON.stringify(v)}`).join(`\n${indent}${IndentChar.repeat(2)}------------\n`)}`);
|
|
864
|
+
ans.push(`${IndentChar}${type}:\n${symbol[type].map((v) => `${indent}${IndentChar.repeat(2)}${JSON.stringify(v)}`).join(`\n${indent}${IndentChar.repeat(2)}------------\n`)}`);
|
|
835
865
|
}
|
|
836
866
|
}
|
|
837
867
|
if (symbol.relations) {
|
|
@@ -840,7 +870,7 @@ export var SymbolFormatter;
|
|
|
840
870
|
if (symbol.members) {
|
|
841
871
|
ans.push(`${IndentChar}members:\n${stringifySymbolMap(symbol.members, `${indent}${IndentChar.repeat(2)}`)}`);
|
|
842
872
|
}
|
|
843
|
-
return ans.map(v => `${indent}${v}`).join('\n');
|
|
873
|
+
return ans.map((v) => `${indent}${v}`).join('\n');
|
|
844
874
|
}
|
|
845
875
|
SymbolFormatter.stringifySymbol = stringifySymbol;
|
|
846
876
|
function stringifyVisibility(visibility, visibilityRestriction) {
|
|
@@ -860,7 +890,9 @@ export var SymbolFormatter;
|
|
|
860
890
|
stringVisibility = 'Public';
|
|
861
891
|
break;
|
|
862
892
|
}
|
|
863
|
-
return `${stringVisibility}${visibilityRestriction
|
|
893
|
+
return `${stringVisibility}${visibilityRestriction
|
|
894
|
+
? ` ${visibilityRestriction.map((v) => `“${v}”`).join(', ')}`
|
|
895
|
+
: ''}`;
|
|
864
896
|
}
|
|
865
897
|
SymbolFormatter.stringifyVisibility = stringifyVisibility;
|
|
866
898
|
function stringifyLookupResult(result) {
|
|
@@ -879,7 +911,7 @@ ${stringifySymbol(result.symbol, IndentChar)}`;
|
|
|
879
911
|
*
|
|
880
912
|
* The decorated method MUST have return type `void`.
|
|
881
913
|
*/
|
|
882
|
-
function DelayModeSupport(getUtil = self => self) {
|
|
914
|
+
function DelayModeSupport(getUtil = (self) => self) {
|
|
883
915
|
return (_target, _key, descripter) => {
|
|
884
916
|
const decoratedMethod = descripter.value;
|
|
885
917
|
// The `function` syntax is used to preserve `this` context from the decorated method.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spyglassmc/core",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"pako": "^2.0.4",
|
|
24
24
|
"rfdc": "^1.3.0",
|
|
25
25
|
"vscode-languageserver-textdocument": "^1.0.4",
|
|
26
|
-
"@spyglassmc/locales": "0.3.
|
|
26
|
+
"@spyglassmc/locales": "0.3.2"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/decompress": "^4.2.3",
|