@spyglassmc/core 0.1.2 → 0.2.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/TwoWayMap.js +4 -10
- 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 +151 -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 +2 -1
- package/lib/common/index.js +2 -17
- package/lib/common/util.d.ts +15 -15
- package/lib/common/util.js +30 -77
- package/lib/index.d.ts +7 -7
- package/lib/index.js +7 -23
- package/lib/node/AstNode.d.ts +3 -3
- 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 +1 -1
- package/lib/node/CommentNode.js +2 -5
- package/lib/node/ErrorNode.d.ts +1 -1
- package/lib/node/ErrorNode.js +2 -5
- package/lib/node/FileNode.d.ts +3 -3
- package/lib/node/FileNode.js +2 -5
- package/lib/node/FloatNode.d.ts +2 -2
- package/lib/node/FloatNode.js +4 -7
- package/lib/node/IntegerNode.d.ts +2 -2
- 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 +3 -3
- package/lib/node/LiteralNode.js +4 -7
- package/lib/node/LongNode.d.ts +2 -2
- 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 +5 -5
- package/lib/node/ResourceLocationNode.js +9 -12
- package/lib/node/Sequence.d.ts +2 -2
- package/lib/node/Sequence.js +4 -7
- package/lib/node/StringNode.d.ts +4 -4
- package/lib/node/StringNode.js +9 -12
- package/lib/node/SymbolNode.d.ts +3 -3
- package/lib/node/SymbolNode.js +4 -7
- package/lib/node/index.d.ts +15 -15
- package/lib/node/index.js +15 -31
- 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 -38
- 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 +14 -18
- package/lib/parser/string.d.ts +5 -5
- package/lib/parser/string.js +36 -42
- package/lib/parser/symbol.d.ts +3 -3
- package/lib/parser/symbol.js +3 -7
- package/lib/parser/util.d.ts +5 -5
- package/lib/parser/util.js +38 -56
- package/lib/processor/ColorInfoProvider.d.ts +1 -1
- package/lib/processor/ColorInfoProvider.js +6 -9
- package/lib/processor/InlayHintProvider.d.ts +2 -2
- package/lib/processor/InlayHintProvider.js +1 -2
- package/lib/processor/SignatureHelpProvider.d.ts +2 -2
- package/lib/processor/SignatureHelpProvider.js +1 -2
- 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 +19 -30
- package/lib/processor/checker/index.d.ts +2 -2
- package/lib/processor/checker/index.js +2 -31
- package/lib/processor/colorizer/Colorizer.d.ts +4 -4
- 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 -31
- package/lib/processor/completer/Completer.d.ts +4 -4
- package/lib/processor/completer/Completer.js +14 -33
- package/lib/processor/completer/builtin.d.ts +7 -7
- package/lib/processor/completer/builtin.js +46 -62
- package/lib/processor/completer/index.d.ts +2 -2
- package/lib/processor/completer/index.js +2 -31
- package/lib/processor/formatter/Formatter.d.ts +2 -2
- 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 -31
- package/lib/processor/index.d.ts +9 -9
- package/lib/processor/index.js +9 -25
- package/lib/processor/linter/Linter.d.ts +2 -2
- 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 +20 -24
- package/lib/processor/linter/builtin.d.ts +3 -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 -31
- package/lib/processor/util.d.ts +2 -2
- package/lib/processor/util.js +4 -9
- package/lib/service/CacheService.d.ts +6 -6
- package/lib/service/CacheService.js +32 -56
- package/lib/service/Config.d.ts +11 -12
- package/lib/service/Config.js +50 -45
- package/lib/service/Context.d.ts +13 -13
- package/lib/service/Context.js +29 -32
- package/lib/service/Dependency.js +2 -5
- package/lib/service/Downloader.d.ts +10 -40
- package/lib/service/Downloader.js +37 -110
- package/lib/service/ErrorReporter.d.ts +2 -2
- package/lib/service/ErrorReporter.js +10 -14
- package/lib/service/FileService.d.ts +16 -14
- package/lib/service/FileService.js +55 -92
- package/lib/service/Hover.d.ts +2 -2
- package/lib/service/Hover.js +4 -7
- package/lib/service/Logger.js +2 -5
- package/lib/service/MetaRegistry.d.ts +12 -12
- package/lib/service/MetaRegistry.js +62 -73
- package/lib/service/Operations.js +3 -9
- package/lib/service/Profiler.d.ts +1 -1
- package/lib/service/Profiler.js +25 -41
- package/lib/service/Project.d.ts +47 -51
- package/lib/service/Project.js +199 -239
- package/lib/service/Service.d.ts +17 -27
- package/lib/service/Service.js +37 -43
- 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/fileUtil.d.ts +15 -45
- package/lib/service/fileUtil.js +38 -143
- package/lib/service/index.d.ts +17 -17
- package/lib/service/index.js +17 -35
- 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 +2 -5
- 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 +3 -3
- package/lib/source/Source.js +28 -29
- package/lib/source/index.d.ts +8 -8
- package/lib/source/index.js +8 -24
- package/lib/symbol/Symbol.d.ts +2 -2
- package/lib/symbol/Symbol.js +49 -65
- package/lib/symbol/SymbolUtil.d.ts +22 -25
- package/lib/symbol/SymbolUtil.js +150 -151
- package/lib/symbol/UriBinder.d.ts +1 -1
- package/lib/symbol/UriBinder.js +1 -2
- package/lib/symbol/index.d.ts +3 -3
- package/lib/symbol/index.js +3 -19
- package/package.json +7 -4
package/lib/symbol/SymbolUtil.js
CHANGED
|
@@ -1,72 +1,69 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
6
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class SymbolUtil extends events_1.default {
|
|
31
|
-
constructor(global,
|
|
7
|
+
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
8
|
+
import { Range } from '../source/index.js';
|
|
9
|
+
import { SymbolLocation, SymbolPath, SymbolUsageTypes } from './Symbol.js';
|
|
10
|
+
export class SymbolUtil {
|
|
11
|
+
#global;
|
|
12
|
+
#eventEmitter;
|
|
13
|
+
#eventEmitterConstructor;
|
|
14
|
+
#trimmableSymbols = new Set();
|
|
15
|
+
#cache = Object.create(null);
|
|
16
|
+
#currentContributor;
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
_delayedOps = [];
|
|
21
|
+
/**
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
_inDelayMode;
|
|
25
|
+
get global() {
|
|
26
|
+
return this.#global;
|
|
27
|
+
}
|
|
28
|
+
constructor(global, eventEmitterConstructor,
|
|
32
29
|
/** @internal */
|
|
33
30
|
_currentContributor,
|
|
34
31
|
/** @internal */
|
|
35
32
|
_inDelayMode = false) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
_SymbolUtil_currentContributor.set(this, void 0);
|
|
41
|
-
/**
|
|
42
|
-
* @internal
|
|
43
|
-
*/
|
|
44
|
-
this._delayedOps = [];
|
|
45
|
-
__classPrivateFieldSet(this, _SymbolUtil_global, global, "f");
|
|
46
|
-
__classPrivateFieldSet(this, _SymbolUtil_currentContributor, _currentContributor, "f");
|
|
33
|
+
this.#eventEmitter = new eventEmitterConstructor();
|
|
34
|
+
this.#eventEmitterConstructor = eventEmitterConstructor;
|
|
35
|
+
this.#global = global;
|
|
36
|
+
this.#currentContributor = _currentContributor;
|
|
47
37
|
this._inDelayMode = _inDelayMode;
|
|
48
38
|
this
|
|
49
39
|
.on('symbolCreated', ({ symbol }) => {
|
|
50
|
-
|
|
40
|
+
this.#trimmableSymbols.add(SymbolPath.toString(symbol));
|
|
51
41
|
})
|
|
52
42
|
.on('symbolRemoved', ({ symbol }) => {
|
|
53
|
-
|
|
43
|
+
this.#trimmableSymbols.delete(SymbolPath.toString(symbol));
|
|
54
44
|
})
|
|
55
45
|
.on('symbolLocationCreated', ({ symbol, location }) => {
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
const path = Symbol_1.SymbolPath.toString(symbol);
|
|
46
|
+
const cache = this.#cache[location.contributor ?? 'undefined'] ??= Object.create(null);
|
|
47
|
+
const fileSymbols = cache[location.uri] ??= new Set();
|
|
48
|
+
const path = SymbolPath.toString(symbol);
|
|
60
49
|
fileSymbols.add(path);
|
|
61
|
-
|
|
50
|
+
this.#trimmableSymbols.delete(path);
|
|
62
51
|
})
|
|
63
52
|
.on('symbolLocationRemoved', ({ symbol }) => {
|
|
64
|
-
const path =
|
|
65
|
-
|
|
53
|
+
const path = SymbolPath.toString(symbol);
|
|
54
|
+
this.#trimmableSymbols.add(path);
|
|
66
55
|
});
|
|
67
56
|
}
|
|
68
|
-
|
|
69
|
-
|
|
57
|
+
on(event, callbackFn) {
|
|
58
|
+
this.#eventEmitter.on(event, callbackFn);
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
once(event, callbackFn) {
|
|
62
|
+
this.#eventEmitter.once(event, callbackFn);
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
emit(event, ...args) {
|
|
66
|
+
return this.#eventEmitter.emit(event, ...args);
|
|
70
67
|
}
|
|
71
68
|
/**
|
|
72
69
|
* Build the internal cache of the SymbolUtil according to the current global symbol table.
|
|
@@ -87,7 +84,7 @@ class SymbolUtil extends events_1.default {
|
|
|
87
84
|
* `applyDelayedEdits` is called, the original SymbolUtil will also be modified.
|
|
88
85
|
*/
|
|
89
86
|
clone() {
|
|
90
|
-
return new SymbolUtil(
|
|
87
|
+
return new SymbolUtil(this.#global, this.#eventEmitterConstructor, this.#currentContributor, true);
|
|
91
88
|
}
|
|
92
89
|
/**
|
|
93
90
|
* Apply edits done during the delay mode.
|
|
@@ -98,24 +95,24 @@ class SymbolUtil extends events_1.default {
|
|
|
98
95
|
this._inDelayMode = false;
|
|
99
96
|
}
|
|
100
97
|
contributeAs(contributor, fn) {
|
|
101
|
-
const originalValue =
|
|
102
|
-
|
|
98
|
+
const originalValue = this.#currentContributor;
|
|
99
|
+
this.#currentContributor = contributor;
|
|
103
100
|
try {
|
|
104
101
|
fn();
|
|
105
102
|
}
|
|
106
103
|
finally {
|
|
107
|
-
|
|
104
|
+
this.#currentContributor = originalValue;
|
|
108
105
|
}
|
|
109
106
|
return this;
|
|
110
107
|
}
|
|
111
108
|
async contributeAsAsync(contributor, fn) {
|
|
112
|
-
const originalValue =
|
|
113
|
-
|
|
109
|
+
const originalValue = this.#currentContributor;
|
|
110
|
+
this.#currentContributor = contributor;
|
|
114
111
|
try {
|
|
115
112
|
await fn();
|
|
116
113
|
}
|
|
117
114
|
finally {
|
|
118
|
-
|
|
115
|
+
this.#currentContributor = originalValue;
|
|
119
116
|
}
|
|
120
117
|
return this;
|
|
121
118
|
}
|
|
@@ -129,10 +126,10 @@ class SymbolUtil extends events_1.default {
|
|
|
129
126
|
clear({ uri, contributor, predicate = () => true }) {
|
|
130
127
|
const getCaches = () => {
|
|
131
128
|
if (contributor) {
|
|
132
|
-
return
|
|
129
|
+
return this.#cache[contributor] ? [this.#cache[contributor]] : [];
|
|
133
130
|
}
|
|
134
131
|
else {
|
|
135
|
-
return Object.values(
|
|
132
|
+
return Object.values(this.#cache);
|
|
136
133
|
}
|
|
137
134
|
};
|
|
138
135
|
const getPaths = () => {
|
|
@@ -140,12 +137,12 @@ class SymbolUtil extends events_1.default {
|
|
|
140
137
|
const sets = uri
|
|
141
138
|
? caches.map(cache => cache[uri] ?? new Set())
|
|
142
139
|
: caches.map(cache => Object.values(cache)).flat();
|
|
143
|
-
return sets.map(s => [...s]).flat().map(
|
|
140
|
+
return sets.map(s => [...s]).flat().map(SymbolPath.fromString);
|
|
144
141
|
};
|
|
145
142
|
const getTables = () => {
|
|
146
143
|
return uri
|
|
147
|
-
? [
|
|
148
|
-
: [
|
|
144
|
+
? [this.#global]
|
|
145
|
+
: [this.#global];
|
|
149
146
|
};
|
|
150
147
|
const paths = getPaths();
|
|
151
148
|
const tables = getTables();
|
|
@@ -172,7 +169,7 @@ class SymbolUtil extends events_1.default {
|
|
|
172
169
|
return new SymbolQuery({
|
|
173
170
|
category,
|
|
174
171
|
doc,
|
|
175
|
-
contributor:
|
|
172
|
+
contributor: this.#currentContributor,
|
|
176
173
|
map: visible ? parentMap : undefined,
|
|
177
174
|
parentSymbol: parentSymbol,
|
|
178
175
|
path,
|
|
@@ -207,14 +204,14 @@ class SymbolUtil extends events_1.default {
|
|
|
207
204
|
trimSymbol(symbol.parentSymbol);
|
|
208
205
|
}
|
|
209
206
|
};
|
|
210
|
-
for (const pathString of
|
|
211
|
-
const path =
|
|
207
|
+
for (const pathString of this.#trimmableSymbols) {
|
|
208
|
+
const path = SymbolPath.fromString(pathString);
|
|
212
209
|
const { symbol } = SymbolUtil.lookupTable(table, path.category, path.path);
|
|
213
210
|
trimSymbol(symbol);
|
|
214
211
|
}
|
|
215
212
|
}
|
|
216
213
|
removeLocationsFromSymbol(symbol, predicate) {
|
|
217
|
-
for (const type of
|
|
214
|
+
for (const type of SymbolUsageTypes) {
|
|
218
215
|
if (!symbol[type]) {
|
|
219
216
|
continue;
|
|
220
217
|
}
|
|
@@ -304,7 +301,7 @@ class SymbolUtil extends events_1.default {
|
|
|
304
301
|
symbol.desc = addition.desc;
|
|
305
302
|
}
|
|
306
303
|
if (addition.relations && Object.keys(addition.relations).length) {
|
|
307
|
-
symbol.relations
|
|
304
|
+
symbol.relations ??= {};
|
|
308
305
|
for (const relationship of Object.keys(addition.relations)) {
|
|
309
306
|
symbol.relations[relationship] = addition.relations[relationship];
|
|
310
307
|
}
|
|
@@ -320,7 +317,7 @@ class SymbolUtil extends events_1.default {
|
|
|
320
317
|
symbol.visibility = addition.visibility;
|
|
321
318
|
}
|
|
322
319
|
else {
|
|
323
|
-
throw new Error(`Cannot change visibility from ${symbol.visibility} to ${addition.visibility}: ${JSON.stringify(
|
|
320
|
+
throw new Error(`Cannot change visibility from ${symbol.visibility} to ${addition.visibility}: ${JSON.stringify(SymbolPath.fromSymbol(symbol))}`);
|
|
324
321
|
}
|
|
325
322
|
}
|
|
326
323
|
if (addition.visibilityRestriction?.length) {
|
|
@@ -331,9 +328,9 @@ class SymbolUtil extends events_1.default {
|
|
|
331
328
|
amendSymbolUsage(symbol, addition, doc, contributor) {
|
|
332
329
|
if (addition) {
|
|
333
330
|
const type = addition.type ?? 'reference';
|
|
334
|
-
const arr = symbol[type]
|
|
335
|
-
const range =
|
|
336
|
-
const location =
|
|
331
|
+
const arr = symbol[type] ??= [];
|
|
332
|
+
const range = Range.get((SymbolAdditionUsageWithNode.is(addition) ? addition.node : addition.range) ?? 0);
|
|
333
|
+
const location = SymbolLocation.create(doc, range, addition.fullRange, contributor, {
|
|
337
334
|
accessType: addition.accessType,
|
|
338
335
|
skipRenaming: addition.skipRenaming,
|
|
339
336
|
});
|
|
@@ -412,7 +409,7 @@ class SymbolUtil extends events_1.default {
|
|
|
412
409
|
* @throws If the symbol does not have any declarations or definitions.
|
|
413
410
|
*/
|
|
414
411
|
static getDeclaredLocation(symbol) {
|
|
415
|
-
return symbol.declaration?.[0] ?? symbol.definition?.[0] ?? (() => { throw new Error(`Cannot get declared location of ${JSON.stringify(
|
|
412
|
+
return symbol.declaration?.[0] ?? symbol.definition?.[0] ?? (() => { throw new Error(`Cannot get declared location of ${JSON.stringify(SymbolPath.fromSymbol(symbol))}`); })();
|
|
416
413
|
}
|
|
417
414
|
static forEachSymbolInMap(map, fn) {
|
|
418
415
|
for (const symbol of Object.values(map)) {
|
|
@@ -428,7 +425,7 @@ class SymbolUtil extends events_1.default {
|
|
|
428
425
|
}
|
|
429
426
|
}
|
|
430
427
|
static forEachLocationOfSymbol(symbol, fn) {
|
|
431
|
-
for (const type of
|
|
428
|
+
for (const type of SymbolUsageTypes) {
|
|
432
429
|
symbol[type]?.forEach(location => fn({ type, location }));
|
|
433
430
|
}
|
|
434
431
|
}
|
|
@@ -441,7 +438,6 @@ class SymbolUtil extends events_1.default {
|
|
|
441
438
|
(v1 === 1 /* SymbolVisibility.File */ && v2 === 1 /* SymbolVisibility.File */));
|
|
442
439
|
}
|
|
443
440
|
}
|
|
444
|
-
_SymbolUtil_global = new WeakMap(), _SymbolUtil_trimmableSymbols = new WeakMap(), _SymbolUtil_cache = new WeakMap(), _SymbolUtil_currentContributor = new WeakMap();
|
|
445
441
|
__decorate([
|
|
446
442
|
DelayModeSupport()
|
|
447
443
|
], SymbolUtil.prototype, "clear", null);
|
|
@@ -451,7 +447,6 @@ __decorate([
|
|
|
451
447
|
__decorate([
|
|
452
448
|
DelayModeSupport()
|
|
453
449
|
], SymbolUtil.prototype, "removeLocationsFromSymbol", null);
|
|
454
|
-
exports.SymbolUtil = SymbolUtil;
|
|
455
450
|
var SymbolAdditionUsageWithRange;
|
|
456
451
|
(function (SymbolAdditionUsageWithRange) {
|
|
457
452
|
/* istanbul ignore next */
|
|
@@ -469,65 +464,67 @@ var SymbolAdditionUsageWithNode;
|
|
|
469
464
|
SymbolAdditionUsageWithNode.is = is;
|
|
470
465
|
})(SymbolAdditionUsageWithNode || (SymbolAdditionUsageWithNode = {}));
|
|
471
466
|
/* istanbul ignore next */
|
|
472
|
-
class SymbolQuery {
|
|
467
|
+
export class SymbolQuery {
|
|
468
|
+
category;
|
|
469
|
+
path;
|
|
470
|
+
#doc;
|
|
471
|
+
#node;
|
|
472
|
+
/**
|
|
473
|
+
* If only a string URI (instead of a {@link TextDocument}) is provided when constructing this class.
|
|
474
|
+
*
|
|
475
|
+
* If this is `true`, {@link SymbolAdditionUsageWithRange.range} is ignored and treated as `[0, 0)` when entering symbols through this class.
|
|
476
|
+
*/
|
|
477
|
+
#createdWithUri;
|
|
478
|
+
#currentContributor;
|
|
479
|
+
#hasTriggeredIf = false;
|
|
480
|
+
/**
|
|
481
|
+
* The map where the queried symbol is stored. `undefined` if the map hasn't been created yet.
|
|
482
|
+
*/
|
|
483
|
+
#map;
|
|
484
|
+
#parentSymbol;
|
|
485
|
+
/**
|
|
486
|
+
* The queried symbol. `undefined` if the symbol hasn't been created yet.
|
|
487
|
+
*/
|
|
488
|
+
#symbol;
|
|
489
|
+
/**
|
|
490
|
+
* The {@link SymbolUtil} where this query was created.
|
|
491
|
+
*/
|
|
492
|
+
util;
|
|
493
|
+
get symbol() {
|
|
494
|
+
return this.#symbol;
|
|
495
|
+
}
|
|
496
|
+
get visibleMembers() {
|
|
497
|
+
return SymbolUtil.filterVisibleSymbols(this.#doc.uri, this.path.length === 0 ? this.#map : this.#symbol?.members);
|
|
498
|
+
}
|
|
473
499
|
constructor({ category, contributor, doc, map, parentSymbol, path, symbol, util }) {
|
|
474
|
-
_SymbolQuery_doc.set(this, void 0);
|
|
475
|
-
_SymbolQuery_node.set(this, void 0);
|
|
476
|
-
/**
|
|
477
|
-
* If only a string URI (instead of a {@link TextDocument}) is provided when constructing this class.
|
|
478
|
-
*
|
|
479
|
-
* If this is `true`, {@link SymbolAdditionUsageWithRange.range} is ignored and treated as `[0, 0)` when entering symbols through this class.
|
|
480
|
-
*/
|
|
481
|
-
_SymbolQuery_createdWithUri.set(this, void 0);
|
|
482
|
-
_SymbolQuery_currentContributor.set(this, void 0);
|
|
483
|
-
_SymbolQuery_hasTriggeredIf.set(this, false
|
|
484
|
-
/**
|
|
485
|
-
* The map where the queried symbol is stored. `undefined` if the map hasn't been created yet.
|
|
486
|
-
*/
|
|
487
|
-
);
|
|
488
|
-
/**
|
|
489
|
-
* The map where the queried symbol is stored. `undefined` if the map hasn't been created yet.
|
|
490
|
-
*/
|
|
491
|
-
_SymbolQuery_map.set(this, void 0);
|
|
492
|
-
_SymbolQuery_parentSymbol.set(this, void 0);
|
|
493
|
-
/**
|
|
494
|
-
* The queried symbol. `undefined` if the symbol hasn't been created yet.
|
|
495
|
-
*/
|
|
496
|
-
_SymbolQuery_symbol.set(this, void 0);
|
|
497
500
|
this.category = category;
|
|
498
501
|
this.path = path;
|
|
499
502
|
if (typeof doc === 'string') {
|
|
500
|
-
doc =
|
|
501
|
-
|
|
503
|
+
doc = TextDocument.create(doc, '', 0, '');
|
|
504
|
+
this.#createdWithUri = true;
|
|
502
505
|
}
|
|
503
506
|
else if (isDocAndNode(doc)) {
|
|
504
|
-
|
|
507
|
+
this.#node = doc.node;
|
|
505
508
|
doc = doc.doc;
|
|
506
509
|
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
510
|
+
this.#doc = doc;
|
|
511
|
+
this.#currentContributor = contributor;
|
|
512
|
+
this.#map = map;
|
|
513
|
+
this.#parentSymbol = parentSymbol;
|
|
514
|
+
this.#symbol = symbol;
|
|
512
515
|
this.util = util;
|
|
513
516
|
}
|
|
514
|
-
get symbol() {
|
|
515
|
-
return __classPrivateFieldGet(this, _SymbolQuery_symbol, "f");
|
|
516
|
-
}
|
|
517
|
-
get visibleMembers() {
|
|
518
|
-
return SymbolUtil.filterVisibleSymbols(__classPrivateFieldGet(this, _SymbolQuery_doc, "f").uri, this.path.length === 0 ? __classPrivateFieldGet(this, _SymbolQuery_map, "f") : __classPrivateFieldGet(this, _SymbolQuery_symbol, "f")?.members);
|
|
519
|
-
}
|
|
520
517
|
heyGimmeDaSymbol() {
|
|
521
|
-
return
|
|
518
|
+
return this.#symbol;
|
|
522
519
|
}
|
|
523
520
|
with(fn) {
|
|
524
521
|
fn(this);
|
|
525
522
|
return this;
|
|
526
523
|
}
|
|
527
524
|
if(predicate, fn) {
|
|
528
|
-
if (predicate.call(this,
|
|
529
|
-
fn.call(this,
|
|
530
|
-
|
|
525
|
+
if (predicate.call(this, this.#symbol, this)) {
|
|
526
|
+
fn.call(this, this.#symbol, this);
|
|
527
|
+
this.#hasTriggeredIf = true;
|
|
531
528
|
}
|
|
532
529
|
return this;
|
|
533
530
|
}
|
|
@@ -577,8 +574,8 @@ class SymbolQuery {
|
|
|
577
574
|
* Calls `fn` if none of the former `if` conditions are met.
|
|
578
575
|
*/
|
|
579
576
|
else(fn) {
|
|
580
|
-
if (!
|
|
581
|
-
fn.call(this,
|
|
577
|
+
if (!this.#hasTriggeredIf) {
|
|
578
|
+
fn.call(this, this.#symbol, this);
|
|
582
579
|
}
|
|
583
580
|
return this;
|
|
584
581
|
}
|
|
@@ -598,16 +595,15 @@ class SymbolQuery {
|
|
|
598
595
|
}
|
|
599
596
|
_enter(addition) {
|
|
600
597
|
const getMap = (addition) => {
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
return __classPrivateFieldGet(this, _SymbolQuery_map, "f");
|
|
598
|
+
if (this.#map && SymbolUtil.areVisibilitiesCompatible(addition.data?.visibility, this.#symbol?.visibility)) {
|
|
599
|
+
return this.#map;
|
|
604
600
|
}
|
|
605
601
|
if (this.path.length > 1) {
|
|
606
|
-
if (
|
|
607
|
-
if (!SymbolUtil.areVisibilitiesCompatible(addition.data?.visibility,
|
|
608
|
-
throw new Error(`Cannot enter member “${this.getPath()}” of ${SymbolFormatter.stringifyVisibility(addition.data?.visibility)} visibility to parent of ${SymbolFormatter.stringifyVisibility(
|
|
602
|
+
if (this.#parentSymbol) {
|
|
603
|
+
if (!SymbolUtil.areVisibilitiesCompatible(addition.data?.visibility, this.#parentSymbol.visibility)) {
|
|
604
|
+
throw new Error(`Cannot enter member “${this.getPath()}” of ${SymbolFormatter.stringifyVisibility(addition.data?.visibility)} visibility to parent of ${SymbolFormatter.stringifyVisibility(this.#parentSymbol.visibility)} visibility`);
|
|
609
605
|
}
|
|
610
|
-
return
|
|
606
|
+
return this.#parentSymbol.members ??= {};
|
|
611
607
|
}
|
|
612
608
|
}
|
|
613
609
|
else {
|
|
@@ -616,10 +612,10 @@ class SymbolQuery {
|
|
|
616
612
|
table = this.util.global;
|
|
617
613
|
}
|
|
618
614
|
else if (addition.data?.visibility === 1 /* SymbolVisibility.File */) {
|
|
619
|
-
if (!
|
|
615
|
+
if (!this.#node) {
|
|
620
616
|
throw new Error(`Cannot enter “${this.getPath()}” with ${SymbolFormatter.stringifyVisibility(addition.data?.visibility)} visibility as no node is supplied`);
|
|
621
617
|
}
|
|
622
|
-
let node =
|
|
618
|
+
let node = this.#node;
|
|
623
619
|
while (node) {
|
|
624
620
|
if (node.type === 'file') {
|
|
625
621
|
table = node.locals;
|
|
@@ -632,10 +628,10 @@ class SymbolQuery {
|
|
|
632
628
|
}
|
|
633
629
|
}
|
|
634
630
|
else {
|
|
635
|
-
if (!
|
|
631
|
+
if (!this.#node) {
|
|
636
632
|
throw new Error(`Cannot enter “${this.getPath()}” with ${SymbolFormatter.stringifyVisibility(addition.data?.visibility)} visibility as no node is supplied`);
|
|
637
633
|
}
|
|
638
|
-
let node =
|
|
634
|
+
let node = this.#node;
|
|
639
635
|
while (node) {
|
|
640
636
|
if (node.locals) {
|
|
641
637
|
table = node.locals;
|
|
@@ -648,18 +644,18 @@ class SymbolQuery {
|
|
|
648
644
|
}
|
|
649
645
|
}
|
|
650
646
|
// TODO: Move part of symbol from global to table.
|
|
651
|
-
return table[
|
|
647
|
+
return table[this.category] ??= {};
|
|
652
648
|
}
|
|
653
649
|
throw new Error(`Cannot create the symbol map for “${this.getPath()}”`);
|
|
654
650
|
};
|
|
655
651
|
// Treat `usage.range` as `[0, 0)` if this class was constructed with a string URI (instead of a `TextDocument`).
|
|
656
|
-
if (
|
|
657
|
-
addition.usage.range =
|
|
652
|
+
if (this.#createdWithUri && SymbolAdditionUsageWithRange.is(addition.usage)) {
|
|
653
|
+
addition.usage.range = Range.create(0, 0);
|
|
658
654
|
}
|
|
659
|
-
|
|
660
|
-
|
|
655
|
+
this.#map = getMap(addition);
|
|
656
|
+
this.#symbol = this.util.enterMap(this.#parentSymbol, this.#map, this.category, this.path, this.path[this.path.length - 1], addition, this.#doc, this.#currentContributor);
|
|
661
657
|
if (addition.usage?.node) {
|
|
662
|
-
addition.usage.node.symbol =
|
|
658
|
+
addition.usage.node.symbol = this.#symbol;
|
|
663
659
|
}
|
|
664
660
|
}
|
|
665
661
|
/**
|
|
@@ -693,13 +689,13 @@ class SymbolQuery {
|
|
|
693
689
|
* after the error is thrown.
|
|
694
690
|
*/
|
|
695
691
|
resolveAlias() {
|
|
696
|
-
if (
|
|
697
|
-
const result = this.util.resolveAlias(
|
|
692
|
+
if (this.#symbol) {
|
|
693
|
+
const result = this.util.resolveAlias(this.#symbol);
|
|
698
694
|
if (!result) {
|
|
699
695
|
throw new Error('The current symbol points to an non-existent symbol.');
|
|
700
696
|
}
|
|
701
|
-
|
|
702
|
-
|
|
697
|
+
this.#symbol = result;
|
|
698
|
+
this.#map = result.parentMap;
|
|
703
699
|
}
|
|
704
700
|
return this;
|
|
705
701
|
}
|
|
@@ -708,7 +704,7 @@ class SymbolQuery {
|
|
|
708
704
|
let doc, identifier, fn;
|
|
709
705
|
if (arguments.length === 2) {
|
|
710
706
|
// Ensure the member query result will not unknowingly have a dummy TextDocument passed down from this class.
|
|
711
|
-
doc =
|
|
707
|
+
doc = this.#createdWithUri ? this.#doc.uri : this.#doc;
|
|
712
708
|
identifier = arguments[0];
|
|
713
709
|
fn = arguments[1];
|
|
714
710
|
}
|
|
@@ -717,20 +713,20 @@ class SymbolQuery {
|
|
|
717
713
|
identifier = arguments[1];
|
|
718
714
|
fn = arguments[2];
|
|
719
715
|
}
|
|
720
|
-
if (
|
|
716
|
+
if (this.#symbol === undefined) {
|
|
721
717
|
throw new Error(`Tried to query member symbol “${identifier}” from an undefined symbol (path “${this.path.join('.')}”)`);
|
|
722
718
|
}
|
|
723
|
-
const memberDoc = typeof doc === 'string' && doc ===
|
|
724
|
-
?
|
|
719
|
+
const memberDoc = typeof doc === 'string' && doc === this.#doc.uri && !this.#createdWithUri
|
|
720
|
+
? this.#doc
|
|
725
721
|
: doc;
|
|
726
|
-
const memberMap =
|
|
722
|
+
const memberMap = this.#symbol.members;
|
|
727
723
|
const memberSymbol = memberMap?.[identifier];
|
|
728
724
|
const memberQueryResult = new SymbolQuery({
|
|
729
725
|
category: this.category,
|
|
730
726
|
doc: memberDoc,
|
|
731
|
-
contributor:
|
|
727
|
+
contributor: this.#currentContributor,
|
|
732
728
|
map: memberMap,
|
|
733
|
-
parentSymbol:
|
|
729
|
+
parentSymbol: this.#symbol,
|
|
734
730
|
path: [...this.path, identifier],
|
|
735
731
|
symbol: memberSymbol,
|
|
736
732
|
util: this.util,
|
|
@@ -755,18 +751,21 @@ class SymbolQuery {
|
|
|
755
751
|
return `${this.category}.${this.path.join('/')}`;
|
|
756
752
|
}
|
|
757
753
|
}
|
|
758
|
-
_SymbolQuery_doc = new WeakMap(), _SymbolQuery_node = new WeakMap(), _SymbolQuery_createdWithUri = new WeakMap(), _SymbolQuery_currentContributor = new WeakMap(), _SymbolQuery_hasTriggeredIf = new WeakMap(), _SymbolQuery_map = new WeakMap(), _SymbolQuery_parentSymbol = new WeakMap(), _SymbolQuery_symbol = new WeakMap();
|
|
759
754
|
__decorate([
|
|
760
755
|
DelayModeSupport((self) => self.util)
|
|
761
756
|
], SymbolQuery.prototype, "_enter", null);
|
|
762
|
-
exports.SymbolQuery = SymbolQuery;
|
|
763
757
|
/* istanbul ignore next */
|
|
764
758
|
/**
|
|
765
759
|
* A series of methods for converting symbol structures to human-readable outputs. Mostly for debug purposes.
|
|
766
760
|
*/
|
|
767
|
-
var SymbolFormatter;
|
|
761
|
+
export var SymbolFormatter;
|
|
768
762
|
(function (SymbolFormatter) {
|
|
769
763
|
const IndentChar = '+ ';
|
|
764
|
+
function assertEqual(a, b) {
|
|
765
|
+
if (a !== b) {
|
|
766
|
+
throw new Error(`Assertion error: ${a} !== ${b}`);
|
|
767
|
+
}
|
|
768
|
+
}
|
|
770
769
|
function stringifySymbolStack(stack) {
|
|
771
770
|
return stack.map(table => stringifySymbolTable(table)).join('\n------------\n');
|
|
772
771
|
}
|
|
@@ -787,7 +786,7 @@ var SymbolFormatter;
|
|
|
787
786
|
const ans = [];
|
|
788
787
|
for (const identifier of Object.keys(map)) {
|
|
789
788
|
const symbol = map[identifier];
|
|
790
|
-
|
|
789
|
+
assertEqual(identifier, symbol.identifier);
|
|
791
790
|
ans.push(stringifySymbol(symbol, indent));
|
|
792
791
|
}
|
|
793
792
|
return ans.join(`\n${indent}------------\n`);
|
|
@@ -798,7 +797,7 @@ var SymbolFormatter;
|
|
|
798
797
|
return 'undefined';
|
|
799
798
|
}
|
|
800
799
|
const ans = [];
|
|
801
|
-
|
|
800
|
+
assertEqual(symbol.path[symbol.path.length - 1], symbol.identifier);
|
|
802
801
|
ans.push(`SYMBOL ${symbol.path.join('.')}` +
|
|
803
802
|
` {${symbol.category}${symbol.subcategory ? ` (${symbol.subcategory})` : ''}}` +
|
|
804
803
|
` [${stringifyVisibility(symbol.visibility, symbol.visibilityRestriction)}]`);
|
|
@@ -808,7 +807,7 @@ var SymbolFormatter;
|
|
|
808
807
|
if (symbol.desc) {
|
|
809
808
|
ans.push(`${IndentChar}description: ${symbol.desc}`);
|
|
810
809
|
}
|
|
811
|
-
for (const type of
|
|
810
|
+
for (const type of SymbolUsageTypes) {
|
|
812
811
|
if (symbol[type]) {
|
|
813
812
|
ans.push(`${IndentChar}${type}:\n${symbol[type].map(v => `${indent}${IndentChar.repeat(2)}${JSON.stringify(v)}`).join(`\n${indent}${IndentChar.repeat(2)}------------\n`)}`);
|
|
814
813
|
}
|
|
@@ -851,7 +850,7 @@ symbol:
|
|
|
851
850
|
${stringifySymbol(result.symbol, IndentChar)}`;
|
|
852
851
|
}
|
|
853
852
|
SymbolFormatter.stringifyLookupResult = stringifyLookupResult;
|
|
854
|
-
})(SymbolFormatter
|
|
853
|
+
})(SymbolFormatter || (SymbolFormatter = {}));
|
|
855
854
|
/**
|
|
856
855
|
* Make a method support delay mode: if the {@link SymbolUtil} is in delay mode, the actual invocation of the method will be
|
|
857
856
|
* stored to the {@link SymbolUtil._delayedOps} array.
|
package/lib/symbol/UriBinder.js
CHANGED
package/lib/symbol/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './Symbol';
|
|
2
|
-
export * from './SymbolUtil';
|
|
3
|
-
export * from './UriBinder';
|
|
1
|
+
export * from './Symbol.js';
|
|
2
|
+
export * from './SymbolUtil.js';
|
|
3
|
+
export * from './UriBinder.js';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/symbol/index.js
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./Symbol"), exports);
|
|
18
|
-
__exportStar(require("./SymbolUtil"), exports);
|
|
19
|
-
__exportStar(require("./UriBinder"), exports);
|
|
1
|
+
export * from './Symbol.js';
|
|
2
|
+
export * from './SymbolUtil.js';
|
|
3
|
+
export * from './UriBinder.js';
|
|
20
4
|
//# sourceMappingURL=index.js.map
|