@spyglassmc/core 0.2.0 → 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/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 +0 -0
- 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/externals/NodeJsExternals.js +1 -0
- package/lib/common/index.d.ts +6 -0
- package/lib/common/index.js +6 -0
- package/lib/common/util.d.ts +33 -5
- package/lib/common/util.js +43 -11
- package/lib/node/AstNode.d.ts +9 -8
- package/lib/node/CommentNode.d.ts +5 -4
- package/lib/node/CommentNode.js +4 -6
- package/lib/node/FileNode.d.ts +5 -1
- package/lib/node/FileNode.js +1 -1
- package/lib/node/FloatNode.d.ts +1 -1
- package/lib/node/IntegerNode.d.ts +1 -1
- package/lib/node/LiteralNode.d.ts +1 -1
- package/lib/node/LongNode.d.ts +1 -1
- package/lib/node/ResourceLocationNode.d.ts +3 -3
- package/lib/node/StringNode.d.ts +1 -1
- package/lib/node/SymbolNode.d.ts +1 -1
- package/lib/parser/resourceLocation.js +0 -8
- package/lib/parser/string.d.ts +2 -2
- package/lib/parser/symbol.js +1 -7
- package/lib/parser/util.js +0 -2
- package/lib/processor/InlayHintProvider.d.ts +2 -1
- package/lib/processor/SignatureHelpProvider.d.ts +2 -1
- 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/builtin.js +5 -5
- package/lib/processor/colorizer/Colorizer.d.ts +2 -1
- package/lib/processor/completer/Completer.d.ts +2 -1
- package/lib/processor/completer/builtin.d.ts +3 -2
- package/lib/processor/completer/builtin.js +1 -1
- package/lib/processor/formatter/Formatter.d.ts +2 -1
- package/lib/processor/index.d.ts +1 -0
- package/lib/processor/index.js +1 -0
- package/lib/processor/linter/Linter.d.ts +2 -1
- package/lib/processor/linter/builtin.d.ts +2 -1
- package/lib/processor/util.d.ts +3 -13
- package/lib/processor/util.js +0 -10
- package/lib/service/CacheService.d.ts +2 -0
- package/lib/service/CacheService.js +3 -0
- package/lib/service/Context.d.ts +15 -12
- package/lib/service/Context.js +12 -6
- package/lib/service/Downloader.d.ts +1 -2
- package/lib/service/FileService.d.ts +1 -2
- package/lib/service/MetaRegistry.d.ts +8 -3
- package/lib/service/MetaRegistry.js +20 -1
- package/lib/service/Profiler.d.ts +3 -2
- package/lib/service/Profiler.js +58 -6
- package/lib/service/Project.d.ts +55 -24
- package/lib/service/Project.js +265 -166
- package/lib/service/Service.d.ts +1 -1
- package/lib/service/UriProcessor.d.ts +5 -0
- package/lib/service/UriProcessor.js +2 -0
- package/lib/service/index.d.ts +1 -2
- package/lib/service/index.js +1 -2
- package/lib/symbol/Symbol.d.ts +3 -2
- package/lib/symbol/SymbolUtil.d.ts +8 -7
- package/lib/symbol/SymbolUtil.js +31 -9
- package/lib/symbol/index.d.ts +0 -1
- package/lib/symbol/index.js +0 -1
- package/package.json +2 -2
- package/lib/service/Operations.d.ts +0 -8
- package/lib/service/Operations.js +0 -20
- package/lib/symbol/UriBinder.d.ts +0 -3
- package/lib/symbol/UriBinder.js +0 -2
package/lib/symbol/Symbol.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
2
|
+
import type { DeepReadonly } from '../common/index.js';
|
|
2
3
|
import type { RangeLike } from '../source/index.js';
|
|
3
4
|
import { PositionRange, Range } from '../source/index.js';
|
|
4
5
|
export declare const McdocCategories: readonly ["mcdoc", "mcdoc/dispatcher"];
|
|
@@ -39,8 +40,8 @@ export interface SymbolPath {
|
|
|
39
40
|
path: readonly string[];
|
|
40
41
|
}
|
|
41
42
|
export declare namespace SymbolPath {
|
|
42
|
-
function fromSymbol(symbol: Symbol): SymbolPath;
|
|
43
|
-
function fromSymbol(symbol: Symbol | undefined): SymbolPath | undefined;
|
|
43
|
+
function fromSymbol(symbol: DeepReadonly<Symbol>): SymbolPath;
|
|
44
|
+
function fromSymbol(symbol: DeepReadonly<Symbol> | undefined): SymbolPath | undefined;
|
|
44
45
|
/**
|
|
45
46
|
* Equivalent {@link SymbolPath}s will always be serialized into the same string value.
|
|
46
47
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
2
|
-
import type { ExternalEventEmitter, Externals } from '../common/index.js';
|
|
2
|
+
import type { DeepReadonly, ExternalEventEmitter, Externals } from '../common/index.js';
|
|
3
3
|
import type { AstNode } from '../node/index.js';
|
|
4
4
|
import type { RangeLike } from '../source/index.js';
|
|
5
5
|
import type { AllCategory, Symbol, SymbolLocationBuiltInContributor, SymbolLocationMetadata, SymbolMap, SymbolMetadata, SymbolTable, SymbolUsageType } from './Symbol.js';
|
|
@@ -179,27 +179,27 @@ export declare class SymbolUtil implements ExternalEventEmitter {
|
|
|
179
179
|
/**
|
|
180
180
|
* @returns If the symbol has declarations or definitions.
|
|
181
181
|
*/
|
|
182
|
-
static isDeclared(symbol: Symbol | undefined): boolean;
|
|
182
|
+
static isDeclared(symbol: DeepReadonly<Symbol> | undefined): boolean;
|
|
183
183
|
/**
|
|
184
184
|
* @returns If the symbol has definitions, or declarations and implementations.
|
|
185
185
|
*/
|
|
186
|
-
static isDefined(symbol: Symbol | undefined): symbol is Symbol;
|
|
186
|
+
static isDefined(symbol: DeepReadonly<Symbol> | undefined): symbol is Symbol;
|
|
187
187
|
/**
|
|
188
188
|
* @returns If the symbol has implementations or definitions.
|
|
189
189
|
*/
|
|
190
|
-
static isImplemented(symbol: Symbol | undefined): symbol is Symbol;
|
|
190
|
+
static isImplemented(symbol: DeepReadonly<Symbol> | undefined): symbol is Symbol;
|
|
191
191
|
/**
|
|
192
192
|
* @returns If the symbol has references.
|
|
193
193
|
*/
|
|
194
|
-
static isReferenced(symbol: Symbol | undefined): symbol is Symbol;
|
|
194
|
+
static isReferenced(symbol: DeepReadonly<Symbol> | undefined): symbol is Symbol;
|
|
195
195
|
/**
|
|
196
196
|
* @returns If the symbol has type definitions.
|
|
197
197
|
*/
|
|
198
|
-
static isTypeDefined(symbol: Symbol | undefined): symbol is Symbol;
|
|
198
|
+
static isTypeDefined(symbol: DeepReadonly<Symbol> | undefined): symbol is Symbol;
|
|
199
199
|
/**
|
|
200
200
|
* @throws If the symbol does not have any declarations or definitions.
|
|
201
201
|
*/
|
|
202
|
-
static getDeclaredLocation(symbol: Symbol): SymbolLocation;
|
|
202
|
+
static getDeclaredLocation(symbol: DeepReadonly<Symbol>): SymbolLocation;
|
|
203
203
|
static forEachSymbolInMap(map: SymbolMap, fn: (symbol: Symbol) => unknown): void;
|
|
204
204
|
static forEachSymbol(table: SymbolTable, fn: (symbol: Symbol) => unknown): void;
|
|
205
205
|
static forEachLocationOfSymbol(symbol: Symbol, fn: (data: {
|
|
@@ -293,6 +293,7 @@ export declare class SymbolQuery {
|
|
|
293
293
|
util: SymbolUtil;
|
|
294
294
|
});
|
|
295
295
|
heyGimmeDaSymbol(): Symbol | undefined;
|
|
296
|
+
getData<T>(predicate: (this: void, value: unknown) => value is T): T | undefined;
|
|
296
297
|
with(fn: QueryMemberCallback): this;
|
|
297
298
|
if(predicate: (this: void, symbol: Symbol | undefined) => symbol is undefined, fn: QueryCallback<undefined>): this;
|
|
298
299
|
if(predicate: (this: void, symbol: Symbol | undefined) => symbol is Symbol, fn: QueryCallback<Symbol>): this;
|
package/lib/symbol/SymbolUtil.js
CHANGED
|
@@ -160,6 +160,15 @@ export class SymbolUtil {
|
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
lookup(category, path, node) {
|
|
163
|
+
while (node) {
|
|
164
|
+
if (node.locals) {
|
|
165
|
+
const result = SymbolUtil.lookupTable(node.locals, category, path);
|
|
166
|
+
if (result.symbol) {
|
|
167
|
+
return result;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
node = node.parent;
|
|
171
|
+
}
|
|
163
172
|
return SymbolUtil.lookupTable(this.global, category, path);
|
|
164
173
|
}
|
|
165
174
|
query(doc, category, ...path) {
|
|
@@ -517,6 +526,10 @@ export class SymbolQuery {
|
|
|
517
526
|
heyGimmeDaSymbol() {
|
|
518
527
|
return this.#symbol;
|
|
519
528
|
}
|
|
529
|
+
getData(predicate) {
|
|
530
|
+
const data = this.#symbol?.data;
|
|
531
|
+
return predicate(data) ? data : undefined;
|
|
532
|
+
}
|
|
520
533
|
with(fn) {
|
|
521
534
|
fn(this);
|
|
522
535
|
return this;
|
|
@@ -594,26 +607,35 @@ export class SymbolQuery {
|
|
|
594
607
|
return this.else(() => this.resolveAlias());
|
|
595
608
|
}
|
|
596
609
|
_enter(addition) {
|
|
610
|
+
/**
|
|
611
|
+
* Get a proper visibility from the addition:
|
|
612
|
+
* * If the visibility is specified, use it.
|
|
613
|
+
* * If the visibility is `undefined`, use the visibility of the symbol, or `Public` if unapplicable.
|
|
614
|
+
*/
|
|
615
|
+
const getAdditionVisibility = (addition) => {
|
|
616
|
+
return addition.data?.visibility ?? this.symbol?.visibility ?? 2 /* SymbolVisibility.Public */;
|
|
617
|
+
};
|
|
597
618
|
const getMap = (addition) => {
|
|
598
|
-
|
|
619
|
+
const additionVisibility = getAdditionVisibility(addition);
|
|
620
|
+
if (this.#map && SymbolUtil.areVisibilitiesCompatible(additionVisibility, this.#symbol?.visibility)) {
|
|
599
621
|
return this.#map;
|
|
600
622
|
}
|
|
601
623
|
if (this.path.length > 1) {
|
|
602
624
|
if (this.#parentSymbol) {
|
|
603
|
-
if (!SymbolUtil.areVisibilitiesCompatible(
|
|
604
|
-
throw new Error(`Cannot enter member “${this.getPath()}” of ${SymbolFormatter.stringifyVisibility(
|
|
625
|
+
if (!SymbolUtil.areVisibilitiesCompatible(additionVisibility, this.#parentSymbol.visibility)) {
|
|
626
|
+
throw new Error(`Cannot enter member “${this.getPath()}” of ${SymbolFormatter.stringifyVisibility(additionVisibility)} visibility to parent of ${SymbolFormatter.stringifyVisibility(this.#parentSymbol.visibility)} visibility`);
|
|
605
627
|
}
|
|
606
628
|
return this.#parentSymbol.members ??= {};
|
|
607
629
|
}
|
|
608
630
|
}
|
|
609
631
|
else {
|
|
610
632
|
let table;
|
|
611
|
-
if (SymbolUtil.isVisibilityInGlobal(
|
|
633
|
+
if (SymbolUtil.isVisibilityInGlobal(additionVisibility)) {
|
|
612
634
|
table = this.util.global;
|
|
613
635
|
}
|
|
614
|
-
else if (
|
|
636
|
+
else if (additionVisibility === 1 /* SymbolVisibility.File */) {
|
|
615
637
|
if (!this.#node) {
|
|
616
|
-
throw new Error(`Cannot enter “${this.getPath()}” with ${SymbolFormatter.stringifyVisibility(
|
|
638
|
+
throw new Error(`Cannot enter “${this.getPath()}” with ${SymbolFormatter.stringifyVisibility(additionVisibility)} visibility as no node is supplied`);
|
|
617
639
|
}
|
|
618
640
|
let node = this.#node;
|
|
619
641
|
while (node) {
|
|
@@ -624,12 +646,12 @@ export class SymbolQuery {
|
|
|
624
646
|
node = node.parent;
|
|
625
647
|
}
|
|
626
648
|
if (!table) {
|
|
627
|
-
throw new Error(`Cannot enter “${this.getPath()}” with ${SymbolFormatter.stringifyVisibility(
|
|
649
|
+
throw new Error(`Cannot enter “${this.getPath()}” with ${SymbolFormatter.stringifyVisibility(additionVisibility)} visibility as no file node is supplied`);
|
|
628
650
|
}
|
|
629
651
|
}
|
|
630
652
|
else {
|
|
631
653
|
if (!this.#node) {
|
|
632
|
-
throw new Error(`Cannot enter “${this.getPath()}” with ${SymbolFormatter.stringifyVisibility(
|
|
654
|
+
throw new Error(`Cannot enter “${this.getPath()}” with ${SymbolFormatter.stringifyVisibility(additionVisibility)} visibility as no node is supplied`);
|
|
633
655
|
}
|
|
634
656
|
let node = this.#node;
|
|
635
657
|
while (node) {
|
|
@@ -640,7 +662,7 @@ export class SymbolQuery {
|
|
|
640
662
|
node = node.parent;
|
|
641
663
|
}
|
|
642
664
|
if (!table) {
|
|
643
|
-
throw new Error(`Cannot enter “${this.getPath()}” with ${SymbolFormatter.stringifyVisibility(
|
|
665
|
+
throw new Error(`Cannot enter “${this.getPath()}” with ${SymbolFormatter.stringifyVisibility(additionVisibility)} visibility as no node with locals is supplied`);
|
|
644
666
|
}
|
|
645
667
|
}
|
|
646
668
|
// TODO: Move part of symbol from global to table.
|
package/lib/symbol/index.d.ts
CHANGED
package/lib/symbol/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spyglassmc/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
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.
|
|
26
|
+
"@spyglassmc/locales": "0.3.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/decompress": "^4.2.3",
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export class Operations {
|
|
2
|
-
undoOps = [];
|
|
3
|
-
redoOps = [];
|
|
4
|
-
set(obj, key, value) {
|
|
5
|
-
const oldValue = obj[key];
|
|
6
|
-
const op = () => { obj[key] = value; };
|
|
7
|
-
this.redoOps.push(op);
|
|
8
|
-
this.undoOps.push(() => { obj[key] = oldValue; });
|
|
9
|
-
op();
|
|
10
|
-
}
|
|
11
|
-
undo() {
|
|
12
|
-
for (let i = this.undoOps.length - 1; i >= 0; i--) {
|
|
13
|
-
this.undoOps[i]();
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
redo() {
|
|
17
|
-
this.redoOps.forEach(f => f());
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=Operations.js.map
|
package/lib/symbol/UriBinder.js
DELETED