@spyglassmc/core 0.1.2 → 0.4.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.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 +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 -17
- package/lib/common/util.d.ts +48 -20
- package/lib/common/util.js +71 -86
- package/lib/index.d.ts +7 -7
- package/lib/index.js +7 -23
- 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 +4 -4
- package/lib/node/LiteralNode.js +4 -7
- 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 +7 -7
- 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 +5 -5
- package/lib/node/StringNode.js +9 -12
- package/lib/node/SymbolNode.d.ts +4 -4
- 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 +12 -24
- package/lib/parser/string.d.ts +7 -7
- package/lib/parser/string.js +36 -42
- package/lib/parser/symbol.d.ts +3 -3
- package/lib/parser/symbol.js +4 -14
- package/lib/parser/util.d.ts +6 -5
- package/lib/parser/util.js +40 -60
- 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 -31
- 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 +34 -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 +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 +47 -63
- package/lib/processor/completer/index.d.ts +2 -2
- package/lib/processor/completer/index.js +2 -31
- 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 -31
- package/lib/processor/index.d.ts +10 -9
- package/lib/processor/index.js +10 -25
- 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 +20 -24
- 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 -31
- package/lib/processor/util.d.ts +4 -14
- package/lib/processor/util.js +1 -16
- package/lib/service/CacheService.d.ts +13 -8
- package/lib/service/CacheService.js +45 -57
- package/lib/service/Config.d.ts +11 -12
- package/lib/service/Config.js +50 -45
- package/lib/service/Context.d.ts +23 -20
- package/lib/service/Context.js +39 -36
- package/lib/service/Dependency.js +2 -5
- package/lib/service/Downloader.d.ts +9 -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 +15 -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/MetaRegistry.d.ts +22 -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 +105 -76
- package/lib/service/Project.js +449 -370
- 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/UriProcessor.d.ts +5 -0
- package/lib/service/UriProcessor.js +2 -0
- package/lib/service/fileUtil.d.ts +15 -45
- package/lib/service/fileUtil.js +38 -143
- package/lib/service/index.d.ts +16 -17
- package/lib/service/index.js +16 -35
- package/lib/source/IndexMap.d.ts +1 -1
- package/lib/source/IndexMap.js +7 -10
- package/lib/source/LanguageError.d.ts +20 -6
- package/lib/source/LanguageError.js +16 -9
- 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 +3 -3
- package/lib/source/PositionRange.js +17 -20
- package/lib/source/Range.d.ts +1 -1
- package/lib/source/Range.js +7 -10
- package/lib/source/Source.d.ts +5 -3
- package/lib/source/Source.js +34 -29
- package/lib/source/index.d.ts +8 -8
- package/lib/source/index.js +8 -24
- package/lib/symbol/Symbol.d.ts +5 -4
- package/lib/symbol/Symbol.js +49 -65
- package/lib/symbol/SymbolUtil.d.ts +29 -31
- package/lib/symbol/SymbolUtil.js +178 -157
- package/lib/symbol/index.d.ts +2 -3
- package/lib/symbol/index.js +2 -19
- 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
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AstNode, SymbolBaseNode } from '../../node/index.js';
|
|
2
|
+
import { ResourceLocationNode } from '../../node/index.js';
|
|
3
|
+
import type { BinderContext, MetaRegistry } from '../../service/index.js';
|
|
4
|
+
import type { Binder } from './Binder.js';
|
|
5
|
+
import { AsyncBinder, SyncBinder } from './Binder.js';
|
|
6
|
+
export declare type AttemptResult = {
|
|
7
|
+
errorAmount: number;
|
|
8
|
+
totalErrorSpan: number;
|
|
9
|
+
updateNodeAndCtx: () => void;
|
|
10
|
+
};
|
|
11
|
+
export declare function attempt<B extends Binder<never>>(binder: B, node: B extends Binder<infer N extends AstNode> ? N : never, ctx: BinderContext): B extends SyncBinder<any> ? AttemptResult : Promise<AttemptResult>;
|
|
12
|
+
declare type ExtractBinder<B extends Binder<never>> = B extends Binder<infer N extends AstNode> ? N : never;
|
|
13
|
+
export declare function any<Binders extends Binder<never>[]>(binders: Binders): Binders extends SyncBinder<never>[] ? SyncBinder<ExtractBinder<Binders[number]>> : AsyncBinder<ExtractBinder<Binders[number]>>;
|
|
14
|
+
/**
|
|
15
|
+
* No operation.
|
|
16
|
+
*/
|
|
17
|
+
export declare const noop: SyncBinder<AstNode>;
|
|
18
|
+
/**
|
|
19
|
+
* Use the shallowest children that have their own binder to validate.
|
|
20
|
+
*/
|
|
21
|
+
export declare const fallback: AsyncBinder<AstNode>;
|
|
22
|
+
export declare const dispatchSync: SyncBinder<AstNode>;
|
|
23
|
+
export declare const resourceLocation: SyncBinder<ResourceLocationNode>;
|
|
24
|
+
export declare const symbol: SyncBinder<SymbolBaseNode>;
|
|
25
|
+
export declare function registerBinders(meta: MetaRegistry): void;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=builtin.d.ts.map
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { localize } from '@spyglassmc/locales';
|
|
2
|
+
import { ResourceLocation, StateProxy } from '../../common/index.js';
|
|
3
|
+
import { ResourceLocationNode } from '../../node/index.js';
|
|
4
|
+
import { ErrorReporter } from '../../service/index.js';
|
|
5
|
+
import { traversePreOrder } from '../util.js';
|
|
6
|
+
import { AsyncBinder, SyncBinder } from './Binder.js';
|
|
7
|
+
export function attempt(binder, node, ctx) {
|
|
8
|
+
const tempCtx = {
|
|
9
|
+
...ctx,
|
|
10
|
+
err: new ErrorReporter(),
|
|
11
|
+
symbols: ctx.symbols.clone(),
|
|
12
|
+
};
|
|
13
|
+
const processAfterBinder = () => {
|
|
14
|
+
StateProxy.undoChanges(node);
|
|
15
|
+
const totalErrorSpan = tempCtx.err.errors
|
|
16
|
+
.map(e => e.range.end - e.range.start)
|
|
17
|
+
.reduce((a, b) => a + b, 0);
|
|
18
|
+
return {
|
|
19
|
+
errorAmount: tempCtx.err.errors.length,
|
|
20
|
+
totalErrorSpan,
|
|
21
|
+
updateNodeAndCtx: () => {
|
|
22
|
+
ctx.err.absorb(tempCtx.err);
|
|
23
|
+
StateProxy.redoChanges(node);
|
|
24
|
+
tempCtx.symbols.applyDelayedEdits();
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
if (SyncBinder.is(binder)) {
|
|
29
|
+
binder(node, tempCtx);
|
|
30
|
+
return processAfterBinder();
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
return (async () => {
|
|
34
|
+
await binder(node, tempCtx);
|
|
35
|
+
return processAfterBinder();
|
|
36
|
+
})();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export function any(binders) {
|
|
40
|
+
if (binders.length === 0) {
|
|
41
|
+
throw new Error('Expected at least one binder');
|
|
42
|
+
}
|
|
43
|
+
const attemptSorter = (a, b) => a.errorAmount - b.errorAmount || a.totalErrorSpan - b.totalErrorSpan;
|
|
44
|
+
if (binders.every(SyncBinder.is)) {
|
|
45
|
+
return SyncBinder.create((node, ctx) => {
|
|
46
|
+
const attempts = binders
|
|
47
|
+
.map(binder => attempt(binder, node, ctx))
|
|
48
|
+
.sort(attemptSorter);
|
|
49
|
+
attempts[0].updateNodeAndCtx();
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
return AsyncBinder.create(async (node, ctx) => {
|
|
54
|
+
const attempts = (await Promise.all(binders.map(binder => attempt(binder, node, ctx))))
|
|
55
|
+
.sort(attemptSorter);
|
|
56
|
+
attempts[0].updateNodeAndCtx();
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* No operation.
|
|
62
|
+
*/
|
|
63
|
+
export const noop = SyncBinder.create(() => { });
|
|
64
|
+
/**
|
|
65
|
+
* Use the shallowest children that have their own binder to validate.
|
|
66
|
+
*/
|
|
67
|
+
export const fallback = AsyncBinder.create(async (node, ctx) => {
|
|
68
|
+
const promises = [];
|
|
69
|
+
traversePreOrder(node, node => !ctx.meta.hasBinder(node.type), node => ctx.meta.hasBinder(node.type), node => {
|
|
70
|
+
const binder = ctx.meta.getBinder(node.type);
|
|
71
|
+
const result = binder(node, ctx);
|
|
72
|
+
if (result instanceof Promise) {
|
|
73
|
+
promises.push(result);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
await Promise.all(promises);
|
|
77
|
+
});
|
|
78
|
+
export const dispatchSync = SyncBinder.create((node, ctx) => {
|
|
79
|
+
for (const child of node.children ?? []) {
|
|
80
|
+
if (ctx.meta.hasBinder(child.type)) {
|
|
81
|
+
const binder = ctx.meta.getBinder(child.type);
|
|
82
|
+
binder(child, ctx);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
export const resourceLocation = SyncBinder.create((node, ctx) => {
|
|
87
|
+
if (node.options.category) {
|
|
88
|
+
const raw = ResourceLocationNode.toString(node, 'full');
|
|
89
|
+
const sanitizedRaw = ResourceLocation.lengthen(node.options.namespacePathSep === '.'
|
|
90
|
+
? raw.replace('.', ResourceLocation.NamespacePathSep)
|
|
91
|
+
: raw);
|
|
92
|
+
ctx.symbols
|
|
93
|
+
.query(ctx.doc, node.isTag ? `tag/${node.options.category}` : node.options.category, sanitizedRaw)
|
|
94
|
+
.enter({ usage: { type: node.options.usageType, node, accessType: node.options.accessType } });
|
|
95
|
+
}
|
|
96
|
+
const full = ResourceLocationNode.toString(node, 'full');
|
|
97
|
+
if (node.options.pool) {
|
|
98
|
+
if (!node.options.pool.includes(full)) {
|
|
99
|
+
ctx.err.report(localize('expected', node.options.pool), node, 3 /* ErrorSeverity.Error */);
|
|
100
|
+
}
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
export const symbol = SyncBinder.create((node, ctx) => {
|
|
105
|
+
if (node.value) {
|
|
106
|
+
const path = node.options.parentPath ? [...node.options.parentPath, node.value] : [node.value];
|
|
107
|
+
ctx.symbols
|
|
108
|
+
.query(ctx.doc, node.options.category, ...path)
|
|
109
|
+
.enter({ usage: { type: node.options.usageType, node: node, accessType: node.options.accessType } });
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
export function registerBinders(meta) {
|
|
113
|
+
meta.registerBinder('resource_location', resourceLocation);
|
|
114
|
+
meta.registerBinder('symbol', symbol);
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=builtin.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AstNode } from '../../node';
|
|
2
|
-
import type { CheckerContext } from '../../service';
|
|
1
|
+
import type { AstNode } from '../../node/index.js';
|
|
2
|
+
import type { CheckerContext } from '../../service/index.js';
|
|
3
3
|
export declare type Checker<N extends AstNode> = (node: N, ctx: CheckerContext) => PromiseLike<void> | void;
|
|
4
4
|
export declare type SyncChecker<N extends AstNode> = (node: N, ctx: CheckerContext) => void;
|
|
5
5
|
export declare type AsyncChecker<N extends AstNode> = (node: N, ctx: CheckerContext) => PromiseLike<void>;
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FallbackChecker = void 0;
|
|
4
1
|
/* istanbul ignore next */
|
|
5
|
-
const FallbackChecker = () => Promise.resolve();
|
|
6
|
-
exports.FallbackChecker = FallbackChecker;
|
|
2
|
+
export const FallbackChecker = () => Promise.resolve();
|
|
7
3
|
//# sourceMappingURL=Checker.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { AstNode, SymbolBaseNode } from '../../node';
|
|
2
|
-
import { ResourceLocationNode } from '../../node';
|
|
3
|
-
import type { CheckerContext, MetaRegistry } from '../../service';
|
|
4
|
-
import type { Checker, SyncChecker } from './Checker';
|
|
1
|
+
import type { AstNode, SymbolBaseNode } from '../../node/index.js';
|
|
2
|
+
import { ResourceLocationNode } from '../../node/index.js';
|
|
3
|
+
import type { CheckerContext, MetaRegistry } from '../../service/index.js';
|
|
4
|
+
import type { Checker, SyncChecker } from './Checker.js';
|
|
5
5
|
export declare type AttemptResult = {
|
|
6
6
|
errorAmount: number;
|
|
7
7
|
totalErrorSpan: number;
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const util_1 = require("../util");
|
|
8
|
-
function attempt(checker, node, ctx) {
|
|
1
|
+
import { localize } from '@spyglassmc/locales';
|
|
2
|
+
import { StateProxy } from '../../common/index.js';
|
|
3
|
+
import { ResourceLocationNode } from '../../node/index.js';
|
|
4
|
+
import { ErrorReporter } from '../../service/index.js';
|
|
5
|
+
import { traversePreOrder } from '../util.js';
|
|
6
|
+
export function attempt(checker, node, ctx) {
|
|
9
7
|
const tempCtx = {
|
|
10
8
|
...ctx,
|
|
11
|
-
err: new
|
|
12
|
-
ops: new service_1.Operations(),
|
|
9
|
+
err: new ErrorReporter(),
|
|
13
10
|
symbols: ctx.symbols.clone(),
|
|
14
11
|
};
|
|
15
12
|
// FIXME: await
|
|
16
13
|
checker(node, tempCtx);
|
|
17
|
-
|
|
14
|
+
StateProxy.undoChanges(node);
|
|
18
15
|
const totalErrorSpan = tempCtx.err.errors
|
|
19
16
|
.map(e => e.range.end - e.range.start)
|
|
20
17
|
.reduce((a, b) => a + b, 0);
|
|
@@ -23,13 +20,12 @@ function attempt(checker, node, ctx) {
|
|
|
23
20
|
totalErrorSpan,
|
|
24
21
|
updateNodeAndCtx: () => {
|
|
25
22
|
ctx.err.absorb(tempCtx.err);
|
|
26
|
-
|
|
23
|
+
StateProxy.redoChanges(node);
|
|
27
24
|
tempCtx.symbols.applyDelayedEdits();
|
|
28
25
|
},
|
|
29
26
|
};
|
|
30
27
|
}
|
|
31
|
-
|
|
32
|
-
function any(checkers) {
|
|
28
|
+
export function any(checkers) {
|
|
33
29
|
if (checkers.length === 0) {
|
|
34
30
|
throw new Error('Expected at least one checker');
|
|
35
31
|
}
|
|
@@ -40,28 +36,25 @@ function any(checkers) {
|
|
|
40
36
|
attempts[0].updateNodeAndCtx();
|
|
41
37
|
};
|
|
42
38
|
}
|
|
43
|
-
exports.any = any;
|
|
44
39
|
/**
|
|
45
40
|
* No operation.
|
|
46
41
|
*/
|
|
47
|
-
const noop = () => { };
|
|
48
|
-
exports.noop = noop;
|
|
42
|
+
export const noop = () => { };
|
|
49
43
|
/**
|
|
50
44
|
* Use the shallowest children that have their own checker to validate.
|
|
51
45
|
*/
|
|
52
|
-
const fallback = async (node, ctx) => {
|
|
46
|
+
export const fallback = async (node, ctx) => {
|
|
53
47
|
const promises = [];
|
|
54
|
-
|
|
48
|
+
traversePreOrder(node, node => !ctx.meta.hasChecker(node.type), node => ctx.meta.hasChecker(node.type), node => {
|
|
55
49
|
const checker = ctx.meta.getChecker(node.type);
|
|
56
50
|
const result = checker(node, ctx);
|
|
57
51
|
if (result instanceof Promise) {
|
|
58
52
|
promises.push(result);
|
|
59
53
|
}
|
|
60
54
|
});
|
|
61
|
-
await Promise.
|
|
55
|
+
await Promise.all(promises);
|
|
62
56
|
};
|
|
63
|
-
|
|
64
|
-
const dispatchSync = (node, ctx) => {
|
|
57
|
+
export const dispatchSync = (node, ctx) => {
|
|
65
58
|
for (const child of node.children ?? []) {
|
|
66
59
|
if (ctx.meta.hasChecker(child.type)) {
|
|
67
60
|
const checker = ctx.meta.getChecker(child.type);
|
|
@@ -69,24 +62,20 @@ const dispatchSync = (node, ctx) => {
|
|
|
69
62
|
}
|
|
70
63
|
}
|
|
71
64
|
};
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
const full = node_1.ResourceLocationNode.toString(node, 'full');
|
|
65
|
+
export const resourceLocation = (node, ctx) => {
|
|
66
|
+
const full = ResourceLocationNode.toString(node, 'full');
|
|
75
67
|
if (node.options.pool) {
|
|
76
68
|
if (!node.options.pool.includes(full)) {
|
|
77
|
-
ctx.err.report(
|
|
69
|
+
ctx.err.report(localize('expected', node.options.pool), node, 3 /* ErrorSeverity.Error */);
|
|
78
70
|
}
|
|
79
71
|
return;
|
|
80
72
|
}
|
|
81
73
|
};
|
|
82
|
-
|
|
83
|
-
const symbol = (_node, _ctx) => {
|
|
74
|
+
export const symbol = (_node, _ctx) => {
|
|
84
75
|
// TODO
|
|
85
76
|
};
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
meta.registerChecker('
|
|
89
|
-
meta.registerChecker('symbol', exports.symbol);
|
|
77
|
+
export function registerCheckers(meta) {
|
|
78
|
+
meta.registerChecker('resource_location', resourceLocation);
|
|
79
|
+
meta.registerChecker('symbol', symbol);
|
|
90
80
|
}
|
|
91
|
-
exports.registerCheckers = registerCheckers;
|
|
92
81
|
//# sourceMappingURL=builtin.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * as checker from './builtin';
|
|
2
|
-
export * from './Checker';
|
|
1
|
+
export * as checker from './builtin.js';
|
|
2
|
+
export * from './Checker.js';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,32 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.checker = void 0;
|
|
30
|
-
exports.checker = __importStar(require("./builtin"));
|
|
31
|
-
__exportStar(require("./Checker"), exports);
|
|
1
|
+
export * as checker from './builtin.js';
|
|
2
|
+
export * from './Checker.js';
|
|
32
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import type { DeepReadonly } from '../../common/index.js';
|
|
2
|
+
import type { AstNode } from '../../node/index.js';
|
|
3
|
+
import type { ColorizerContext } from '../../service/index.js';
|
|
4
|
+
import type { RangeLike } from '../../source/index.js';
|
|
5
|
+
import { Range } from '../../source/index.js';
|
|
6
|
+
export declare type Colorizer<N extends AstNode = AstNode> = (node: DeepReadonly<N>, ctx: ColorizerContext) => readonly ColorToken[];
|
|
6
7
|
export interface ColorToken {
|
|
7
8
|
range: Range;
|
|
8
9
|
type: ColorTokenType;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ColorTokenModifiers = exports.ColorTokenTypes = exports.ColorToken = void 0;
|
|
4
|
-
const source_1 = require("../../source");
|
|
5
|
-
var ColorToken;
|
|
1
|
+
import { Range } from '../../source/index.js';
|
|
2
|
+
export var ColorToken;
|
|
6
3
|
(function (ColorToken) {
|
|
7
4
|
/* istanbul ignore next */
|
|
8
5
|
function create(range, type, modifiers) {
|
|
9
6
|
return {
|
|
10
|
-
range:
|
|
7
|
+
range: Range.get(range),
|
|
11
8
|
type,
|
|
12
9
|
modifiers,
|
|
13
10
|
};
|
|
@@ -22,20 +19,20 @@ var ColorToken;
|
|
|
22
19
|
let nextStart = Math.min(targetRange.start, tokens[0]?.range.start ?? Infinity);
|
|
23
20
|
for (const t of tokens) {
|
|
24
21
|
if (t.range.start > nextStart) {
|
|
25
|
-
ans.push(ColorToken.create(
|
|
22
|
+
ans.push(ColorToken.create(Range.create(nextStart, t.range.start), type, modifiers));
|
|
26
23
|
}
|
|
27
24
|
ans.push(t);
|
|
28
25
|
nextStart = t.range.end;
|
|
29
26
|
}
|
|
30
27
|
if (nextStart < targetRange.end) {
|
|
31
|
-
ans.push(ColorToken.create(
|
|
28
|
+
ans.push(ColorToken.create(Range.create(nextStart, targetRange.end), type, modifiers));
|
|
32
29
|
}
|
|
33
30
|
return ans;
|
|
34
31
|
}
|
|
35
32
|
ColorToken.fillGap = fillGap;
|
|
36
|
-
})(ColorToken
|
|
33
|
+
})(ColorToken || (ColorToken = {}));
|
|
37
34
|
// Built-in LSP semantic tokens: https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#textDocument_semanticTokens
|
|
38
|
-
|
|
35
|
+
export const ColorTokenTypes = Object.freeze([
|
|
39
36
|
'comment',
|
|
40
37
|
'enum',
|
|
41
38
|
'enumMember',
|
|
@@ -57,7 +54,7 @@ exports.ColorTokenTypes = Object.freeze([
|
|
|
57
54
|
'resourceLocation',
|
|
58
55
|
'vector',
|
|
59
56
|
]);
|
|
60
|
-
|
|
57
|
+
export const ColorTokenModifiers = Object.freeze([
|
|
61
58
|
'declaration',
|
|
62
59
|
'defaultLibrary',
|
|
63
60
|
'definition',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { LiteralBaseNode, ResourceLocationBaseNode, StringBaseNode, SymbolBaseNode } from '../../node';
|
|
2
|
-
import type { MetaRegistry } from '../../service';
|
|
3
|
-
import type { Colorizer } from './Colorizer';
|
|
1
|
+
import type { LiteralBaseNode, ResourceLocationBaseNode, StringBaseNode, SymbolBaseNode } from '../../node/index.js';
|
|
2
|
+
import type { MetaRegistry } from '../../service/index.js';
|
|
3
|
+
import type { Colorizer } from './Colorizer.js';
|
|
4
4
|
/**
|
|
5
5
|
* Use the shallowest children that have their own colorizers to provide the color tokens.
|
|
6
6
|
*/
|
|
@@ -1,43 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const source_1 = require("../../source");
|
|
5
|
-
const util_1 = require("../util");
|
|
6
|
-
const Colorizer_1 = require("./Colorizer");
|
|
1
|
+
import { Range } from '../../source/index.js';
|
|
2
|
+
import { traversePreOrder } from '../util.js';
|
|
3
|
+
import { ColorToken } from './Colorizer.js';
|
|
7
4
|
/**
|
|
8
5
|
* Use the shallowest children that have their own colorizers to provide the color tokens.
|
|
9
6
|
*/
|
|
10
|
-
const fallback = (node, ctx) => {
|
|
7
|
+
export const fallback = (node, ctx) => {
|
|
11
8
|
const ans = [];
|
|
12
|
-
|
|
9
|
+
traversePreOrder(node, node => !ctx.meta.hasColorizer(node.type) && (!ctx.range || Range.intersects(node.range, ctx.range)), node => ctx.meta.hasColorizer(node.type), node => {
|
|
13
10
|
const colorizer = ctx.meta.getColorizer(node.type);
|
|
14
11
|
const result = colorizer(node, ctx);
|
|
15
12
|
ans.push(...result);
|
|
16
13
|
});
|
|
17
14
|
return Object.freeze(ans);
|
|
18
15
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return [Colorizer_1.ColorToken.create(node, 'literal')];
|
|
16
|
+
export const boolean = node => {
|
|
17
|
+
return [ColorToken.create(node, 'literal')];
|
|
22
18
|
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return [Colorizer_1.ColorToken.create(node, 'comment')];
|
|
19
|
+
export const comment = node => {
|
|
20
|
+
return [ColorToken.create(node, 'comment')];
|
|
26
21
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return [
|
|
22
|
+
export const error = node => {
|
|
23
|
+
// return [ColorToken.create(node, 'error')]
|
|
24
|
+
return [];
|
|
30
25
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return [Colorizer_1.ColorToken.create(node, node.options.colorTokenType ?? 'literal')];
|
|
26
|
+
export const literal = node => {
|
|
27
|
+
return [ColorToken.create(node, node.options.colorTokenType ?? 'literal')];
|
|
34
28
|
};
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return [Colorizer_1.ColorToken.create(node, 'number')];
|
|
29
|
+
export const number = node => {
|
|
30
|
+
return [ColorToken.create(node, 'number')];
|
|
38
31
|
};
|
|
39
|
-
|
|
40
|
-
const resourceLocation = (node, _ctx) => {
|
|
32
|
+
export const resourceLocation = (node, _ctx) => {
|
|
41
33
|
let type;
|
|
42
34
|
switch (node.options.category) {
|
|
43
35
|
case 'function':
|
|
@@ -48,37 +40,33 @@ const resourceLocation = (node, _ctx) => {
|
|
|
48
40
|
type = 'resourceLocation';
|
|
49
41
|
break;
|
|
50
42
|
}
|
|
51
|
-
return [
|
|
43
|
+
return [ColorToken.create(node, type)];
|
|
52
44
|
};
|
|
53
|
-
|
|
54
|
-
const string = (node, ctx) => {
|
|
45
|
+
export const string = (node, ctx) => {
|
|
55
46
|
if (node.children) {
|
|
56
47
|
const colorizer = ctx.meta.getColorizer(node.children[0].type);
|
|
57
48
|
const result = colorizer(node.children[0], ctx);
|
|
58
49
|
// TODO: Fill the gap between the last token and the ending quote with errors.
|
|
59
|
-
return
|
|
50
|
+
return ColorToken.fillGap(result, node.range, node.options.colorTokenType ?? 'string');
|
|
60
51
|
}
|
|
61
52
|
else {
|
|
62
|
-
return [
|
|
53
|
+
return [ColorToken.create(node, node.options.colorTokenType ?? 'string')];
|
|
63
54
|
}
|
|
64
55
|
};
|
|
65
|
-
|
|
66
|
-
const symbol = node => {
|
|
56
|
+
export const symbol = node => {
|
|
67
57
|
// TODO: Set the modifiers according to `node.symbol`.
|
|
68
|
-
return [
|
|
58
|
+
return [ColorToken.create(node, 'variable')];
|
|
69
59
|
};
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
meta.registerColorizer('
|
|
73
|
-
meta.registerColorizer('
|
|
74
|
-
meta.registerColorizer('
|
|
75
|
-
meta.registerColorizer('
|
|
76
|
-
meta.registerColorizer('
|
|
77
|
-
meta.registerColorizer('
|
|
78
|
-
meta.registerColorizer('
|
|
79
|
-
meta.registerColorizer('
|
|
80
|
-
meta.registerColorizer('
|
|
81
|
-
meta.registerColorizer('symbol', exports.symbol);
|
|
60
|
+
export function registerColorizers(meta) {
|
|
61
|
+
meta.registerColorizer('boolean', boolean);
|
|
62
|
+
meta.registerColorizer('comment', comment);
|
|
63
|
+
meta.registerColorizer('error', error);
|
|
64
|
+
meta.registerColorizer('float', number);
|
|
65
|
+
meta.registerColorizer('integer', number);
|
|
66
|
+
meta.registerColorizer('long', number);
|
|
67
|
+
meta.registerColorizer('literal', literal);
|
|
68
|
+
meta.registerColorizer('resource_location', resourceLocation);
|
|
69
|
+
meta.registerColorizer('string', string);
|
|
70
|
+
meta.registerColorizer('symbol', symbol);
|
|
82
71
|
}
|
|
83
|
-
exports.registerColorizers = registerColorizers;
|
|
84
72
|
//# sourceMappingURL=builtin.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * as colorizer from './builtin';
|
|
2
|
-
export * from './Colorizer';
|
|
1
|
+
export * as colorizer from './builtin.js';
|
|
2
|
+
export * from './Colorizer.js';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,32 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.colorizer = void 0;
|
|
30
|
-
exports.colorizer = __importStar(require("./builtin"));
|
|
31
|
-
__exportStar(require("./Colorizer"), exports);
|
|
1
|
+
export * as colorizer from './builtin.js';
|
|
2
|
+
export * from './Colorizer.js';
|
|
32
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
5
|
-
|
|
1
|
+
import type { DeepReadonly } from '../../index.js';
|
|
2
|
+
import type { AstNode } from '../../node/index.js';
|
|
3
|
+
import type { CompleterContext } from '../../service/index.js';
|
|
4
|
+
import type { RangeLike } from '../../source/index.js';
|
|
5
|
+
import { Range } from '../../source/index.js';
|
|
6
|
+
export declare type Completer<N extends AstNode = AstNode> = (node: DeepReadonly<N>, ctx: CompleterContext) => CompletionItem[];
|
|
6
7
|
export declare const enum CompletionKind {
|
|
7
8
|
Text = 1,
|
|
8
9
|
Method = 2,
|