@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/node/SymbolNode.d.ts
CHANGED
|
@@ -48,14 +48,6 @@ export function resourceLocation(options) {
|
|
|
48
48
|
if (!ans.namespace && options.isPredicate) {
|
|
49
49
|
ctx.err.report(localize('parser.resource-location.namespace-expected'), ans);
|
|
50
50
|
}
|
|
51
|
-
if (options.category) {
|
|
52
|
-
const fullRaw = ResourceLocation.lengthen(options.namespacePathSep === '.'
|
|
53
|
-
? raw.replace('.', ResourceLocation.NamespacePathSep)
|
|
54
|
-
: raw);
|
|
55
|
-
ctx.symbols
|
|
56
|
-
.query(ctx.doc, ans.isTag ? `tag/${options.category}` : options.category, fullRaw)
|
|
57
|
-
.enter({ usage: { type: options.usageType, node: ans, accessType: options.accessType } });
|
|
58
|
-
}
|
|
59
51
|
}
|
|
60
52
|
return ans;
|
|
61
53
|
};
|
package/lib/parser/string.d.ts
CHANGED
|
@@ -6,11 +6,11 @@ import type { Parser, Result, Returnable } from './Parser.js';
|
|
|
6
6
|
export declare function string(options: StringOptions): InfallibleParser<StringNode>;
|
|
7
7
|
export declare function parseStringValue<T extends Returnable>(parser: Parser<T>, value: string, map: IndexMap, ctx: ParserContext): Result<T>;
|
|
8
8
|
export declare const BrigadierUnquotableCharacters: readonly ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "_", ".", "+", "-"];
|
|
9
|
-
export declare const BrigadierUnquotableCharacterSet: Set<"0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "." | "i" | "p" | "-" | "+" | "e" | "a" | "b" | "c" | "d" | "f" | "g" | "h" | "j" | "
|
|
9
|
+
export declare const BrigadierUnquotableCharacterSet: Set<"0" | "k" | "v" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "." | "i" | "p" | "-" | "+" | "e" | "a" | "b" | "c" | "d" | "f" | "g" | "h" | "j" | "l" | "m" | "n" | "o" | "q" | "r" | "s" | "t" | "u" | "w" | "x" | "y" | "z" | "_" | "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z">;
|
|
10
10
|
export declare const BrigadierUnquotablePattern: RegExp;
|
|
11
11
|
export declare const BrigadierUnquotableOption: {
|
|
12
12
|
allowEmpty: boolean;
|
|
13
|
-
allowList: Set<"0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "." | "i" | "p" | "-" | "+" | "e" | "a" | "b" | "c" | "d" | "f" | "g" | "h" | "j" | "
|
|
13
|
+
allowList: Set<"0" | "k" | "v" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "." | "i" | "p" | "-" | "+" | "e" | "a" | "b" | "c" | "d" | "f" | "g" | "h" | "j" | "l" | "m" | "n" | "o" | "q" | "r" | "s" | "t" | "u" | "w" | "x" | "y" | "z" | "_" | "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z">;
|
|
14
14
|
};
|
|
15
15
|
export declare const BrigadierStringOptions: StringOptions;
|
|
16
16
|
export declare const brigadierString: InfallibleParser<StringNode>;
|
package/lib/parser/symbol.js
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
import { Range } from '../source/index.js';
|
|
2
2
|
export function symbol(param) {
|
|
3
3
|
const options = getOptions(param);
|
|
4
|
-
return (src,
|
|
4
|
+
return (src, _ctx) => {
|
|
5
5
|
const ans = {
|
|
6
6
|
type: 'symbol',
|
|
7
7
|
range: Range.create(src),
|
|
8
8
|
options,
|
|
9
9
|
value: src.readRemaining(),
|
|
10
10
|
};
|
|
11
|
-
if (ans.value) {
|
|
12
|
-
const path = options.parentPath ? [...options.parentPath, ans.value] : [ans.value];
|
|
13
|
-
ctx.symbols
|
|
14
|
-
.query(ctx.doc, options.category, ...path)
|
|
15
|
-
.enter({ usage: { type: options.usageType, node: ans, accessType: options.accessType } });
|
|
16
|
-
}
|
|
17
11
|
ans.range.end = src.cursor;
|
|
18
12
|
return ans;
|
|
19
13
|
};
|
package/lib/parser/util.js
CHANGED
|
@@ -7,7 +7,6 @@ export function attempt(parser, src, ctx) {
|
|
|
7
7
|
const tmpCtx = {
|
|
8
8
|
...ctx,
|
|
9
9
|
err: new ErrorReporter(),
|
|
10
|
-
symbols: ctx.symbols.clone(),
|
|
11
10
|
};
|
|
12
11
|
const result = parser(tmpSrc, tmpCtx);
|
|
13
12
|
return {
|
|
@@ -17,7 +16,6 @@ export function attempt(parser, src, ctx) {
|
|
|
17
16
|
updateSrcAndCtx: () => {
|
|
18
17
|
src.innerCursor = tmpSrc.innerCursor;
|
|
19
18
|
ctx.err.absorb(tmpCtx.err);
|
|
20
|
-
tmpCtx.symbols.applyDelayedEdits();
|
|
21
19
|
},
|
|
22
20
|
};
|
|
23
21
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import type { DeepReadonly } from '../common/index.js';
|
|
1
2
|
import type { AstNode } from '../node/index.js';
|
|
2
3
|
import type { ProcessorContext } from '../service/index.js';
|
|
3
4
|
export interface InlayHint {
|
|
4
5
|
offset: number;
|
|
5
6
|
text: string;
|
|
6
7
|
}
|
|
7
|
-
export declare type InlayHintProvider<N = AstNode> = (node: N
|
|
8
|
+
export declare type InlayHintProvider<N extends AstNode = AstNode> = (node: DeepReadonly<N>, ctx: ProcessorContext) => readonly InlayHint[];
|
|
8
9
|
//# sourceMappingURL=InlayHintProvider.d.ts.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DeepReadonly } from '../common/index.js';
|
|
1
2
|
import type { AstNode } from '../node/index.js';
|
|
2
3
|
import type { SignatureHelpProviderContext } from '../service/index.js';
|
|
3
4
|
export interface SignatureHelp {
|
|
@@ -14,5 +15,5 @@ export interface ParameterInfo {
|
|
|
14
15
|
label: [number, number];
|
|
15
16
|
documentation?: string;
|
|
16
17
|
}
|
|
17
|
-
export declare type SignatureHelpProvider<N = AstNode> = (node: N
|
|
18
|
+
export declare type SignatureHelpProvider<N extends AstNode = AstNode> = (node: DeepReadonly<N>, ctx: SignatureHelpProviderContext) => SignatureHelp | undefined;
|
|
18
19
|
//# sourceMappingURL=SignatureHelpProvider.d.ts.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { AstNode } from '../../node/index.js';
|
|
2
|
+
import type { BinderContext } from '../../service/index.js';
|
|
3
|
+
declare const IsAsync: unique symbol;
|
|
4
|
+
export declare type Binder<N extends AstNode> = SyncBinder<N> | AsyncBinder<N>;
|
|
5
|
+
export interface SyncBinderInitializer<N extends AstNode> {
|
|
6
|
+
(node: N, ctx: BinderContext): void;
|
|
7
|
+
}
|
|
8
|
+
export interface SyncBinder<N extends AstNode> extends SyncBinderInitializer<N> {
|
|
9
|
+
[IsAsync]?: never;
|
|
10
|
+
}
|
|
11
|
+
export declare const SyncBinder: Readonly<{
|
|
12
|
+
create<N extends AstNode>(binder: SyncBinderInitializer<N>): SyncBinder<N>;
|
|
13
|
+
is(binder: Binder<any>): binder is SyncBinder<any>;
|
|
14
|
+
}>;
|
|
15
|
+
interface AsyncBinderInitializer<N extends AstNode> {
|
|
16
|
+
(node: N, ctx: BinderContext): Promise<void>;
|
|
17
|
+
}
|
|
18
|
+
export interface AsyncBinder<N extends AstNode> extends AsyncBinderInitializer<N> {
|
|
19
|
+
[IsAsync]: true;
|
|
20
|
+
}
|
|
21
|
+
export declare const AsyncBinder: Readonly<{
|
|
22
|
+
create<N extends AstNode>(binder: AsyncBinderInitializer<N>): AsyncBinder<N>;
|
|
23
|
+
is(binder: Binder<any>): binder is AsyncBinder<any>;
|
|
24
|
+
}>;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=Binder.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const IsAsync = Symbol('IsAsyncBinder');
|
|
2
|
+
export const SyncBinder = Object.freeze({
|
|
3
|
+
create(binder) {
|
|
4
|
+
return binder;
|
|
5
|
+
},
|
|
6
|
+
is(binder) {
|
|
7
|
+
return !binder[IsAsync];
|
|
8
|
+
},
|
|
9
|
+
});
|
|
10
|
+
export const AsyncBinder = Object.freeze({
|
|
11
|
+
create(binder) {
|
|
12
|
+
return Object.assign(binder, { [IsAsync]: true });
|
|
13
|
+
},
|
|
14
|
+
is(binder) {
|
|
15
|
+
return binder[IsAsync];
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
//# sourceMappingURL=Binder.js.map
|
|
@@ -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,17 +1,17 @@
|
|
|
1
1
|
import { localize } from '@spyglassmc/locales';
|
|
2
|
+
import { StateProxy } from '../../common/index.js';
|
|
2
3
|
import { ResourceLocationNode } from '../../node/index.js';
|
|
3
|
-
import { ErrorReporter
|
|
4
|
+
import { ErrorReporter } from '../../service/index.js';
|
|
4
5
|
import { traversePreOrder } from '../util.js';
|
|
5
6
|
export function attempt(checker, node, ctx) {
|
|
6
7
|
const tempCtx = {
|
|
7
8
|
...ctx,
|
|
8
9
|
err: new ErrorReporter(),
|
|
9
|
-
ops: new Operations(),
|
|
10
10
|
symbols: ctx.symbols.clone(),
|
|
11
11
|
};
|
|
12
12
|
// FIXME: await
|
|
13
13
|
checker(node, tempCtx);
|
|
14
|
-
|
|
14
|
+
StateProxy.undoChanges(node);
|
|
15
15
|
const totalErrorSpan = tempCtx.err.errors
|
|
16
16
|
.map(e => e.range.end - e.range.start)
|
|
17
17
|
.reduce((a, b) => a + b, 0);
|
|
@@ -20,7 +20,7 @@ export function attempt(checker, node, ctx) {
|
|
|
20
20
|
totalErrorSpan,
|
|
21
21
|
updateNodeAndCtx: () => {
|
|
22
22
|
ctx.err.absorb(tempCtx.err);
|
|
23
|
-
|
|
23
|
+
StateProxy.redoChanges(node);
|
|
24
24
|
tempCtx.symbols.applyDelayedEdits();
|
|
25
25
|
},
|
|
26
26
|
};
|
|
@@ -52,7 +52,7 @@ export const fallback = async (node, ctx) => {
|
|
|
52
52
|
promises.push(result);
|
|
53
53
|
}
|
|
54
54
|
});
|
|
55
|
-
await Promise.
|
|
55
|
+
await Promise.all(promises);
|
|
56
56
|
};
|
|
57
57
|
export const dispatchSync = (node, ctx) => {
|
|
58
58
|
for (const child of node.children ?? []) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import type { DeepReadonly } from '../../common/index.js';
|
|
1
2
|
import type { AstNode } from '../../node/index.js';
|
|
2
3
|
import type { ColorizerContext } from '../../service/index.js';
|
|
3
4
|
import type { RangeLike } from '../../source/index.js';
|
|
4
5
|
import { Range } from '../../source/index.js';
|
|
5
|
-
export declare type Colorizer<N = AstNode> = (node: N
|
|
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,8 +1,9 @@
|
|
|
1
|
+
import type { DeepReadonly } from '../../index.js';
|
|
1
2
|
import type { AstNode } from '../../node/index.js';
|
|
2
3
|
import type { CompleterContext } from '../../service/index.js';
|
|
3
4
|
import type { RangeLike } from '../../source/index.js';
|
|
4
5
|
import { Range } from '../../source/index.js';
|
|
5
|
-
export declare type Completer<N = AstNode> = (node: N
|
|
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,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DeepReadonly } from '../../common/index.js';
|
|
1
2
|
import type { BooleanBaseNode } from '../../node/BooleanNode.js';
|
|
2
3
|
import type { FileNode, LiteralBaseNode, PairNode, RecordBaseNode, ResourceLocationNode, StringBaseNode, SymbolBaseNode } from '../../node/index.js';
|
|
3
4
|
import { AstNode } from '../../node/index.js';
|
|
@@ -18,8 +19,8 @@ export declare const file: Completer<FileNode<AstNode>>;
|
|
|
18
19
|
export declare const literal: Completer<LiteralBaseNode>;
|
|
19
20
|
export declare const noop: Completer<any>;
|
|
20
21
|
interface RecordOptions<K extends AstNode, V extends AstNode, N extends RecordBaseNode<K, V>> {
|
|
21
|
-
key: (record: N
|
|
22
|
-
value: (record: N
|
|
22
|
+
key: (record: DeepReadonly<N>, pair: DeepReadonly<PairNode<K, V>> | undefined, ctx: CompleterContext, range: RangeLike, insertValue: boolean, insertPairEnd: boolean, existingKeys: DeepReadonly<K>[]) => CompletionItem[];
|
|
23
|
+
value: (record: DeepReadonly<N>, pair: DeepReadonly<PairNode<K, V>>, ctx: CompleterContext) => CompletionItem[];
|
|
23
24
|
}
|
|
24
25
|
export declare function record<K extends AstNode, V extends AstNode, N extends RecordBaseNode<K, V>>(o: RecordOptions<K, V, N>): Completer<N>;
|
|
25
26
|
export declare const resourceLocation: Completer<ResourceLocationNode>;
|
|
@@ -9,7 +9,7 @@ import { CompletionItem } from './Completer.js';
|
|
|
9
9
|
*/
|
|
10
10
|
export const dispatch = (node, ctx) => {
|
|
11
11
|
const child = AstNode.findShallowestChild({
|
|
12
|
-
node,
|
|
12
|
+
node: node,
|
|
13
13
|
needle: ctx.offset,
|
|
14
14
|
endInclusive: true,
|
|
15
15
|
predicate: n => ctx.meta.hasCompleter(n.type),
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { DeepReadonly } from '../../common/index.js';
|
|
1
2
|
import type { AstNode } from '../../node/index.js';
|
|
2
3
|
import type { FormatterContext } from '../../service/index.js';
|
|
3
|
-
export declare type Formatter<N = AstNode> = (node: N
|
|
4
|
+
export declare type Formatter<N extends AstNode = AstNode> = (node: DeepReadonly<N>, ctx: FormatterContext) => string;
|
|
4
5
|
export declare function formatterContextIndentation(ctx: FormatterContext, additionalLevels?: number): string;
|
|
5
6
|
export declare function indentFormatter(ctx: FormatterContext, additionalLevels?: number): FormatterContext;
|
|
6
7
|
//# sourceMappingURL=Formatter.d.ts.map
|
package/lib/processor/index.d.ts
CHANGED
package/lib/processor/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import type { StateProxy } from '../../index.js';
|
|
1
2
|
import type { AstNode } from '../../node/index.js';
|
|
2
3
|
import type { LinterContext } from '../../service/index.js';
|
|
3
|
-
export declare type Linter<N extends AstNode> = (node: N
|
|
4
|
+
export declare type Linter<N extends AstNode> = (node: StateProxy<N>, ctx: LinterContext) => void;
|
|
4
5
|
//# sourceMappingURL=Linter.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { Logger } from '../../common/index.js';
|
|
1
2
|
import type { AstNode, StringBaseNode } from '../../node/index.js';
|
|
2
|
-
import type {
|
|
3
|
+
import type { MetaRegistry } from '../../service/index.js';
|
|
3
4
|
import type { Linter } from './Linter.js';
|
|
4
5
|
export declare const noop: Linter<AstNode>;
|
|
5
6
|
/**
|
package/lib/processor/util.d.ts
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
|
+
import type { DeepReadonly } from '../index.js';
|
|
1
2
|
import type { AstNode } from '../node/index.js';
|
|
2
|
-
import { Range } from '../source/index.js';
|
|
3
3
|
declare type Callback<R> = (this: void, node: AstNode, parents: AstNode[]) => R;
|
|
4
|
-
export declare function traversePreOrder(node: AstNode
|
|
5
|
-
|
|
6
|
-
node: AstNode | undefined;
|
|
7
|
-
/**
|
|
8
|
-
* Ordered from the closest parent to the root node.
|
|
9
|
-
*/
|
|
10
|
-
parents: AstNode[];
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* @returns The shallowest node that is fully contained within `range`.
|
|
14
|
-
*/
|
|
15
|
-
export declare function findNode(node: AstNode, range: Range): NodeResult;
|
|
4
|
+
export declare function traversePreOrder<CN extends AstNode>(node: DeepReadonly<AstNode>, shouldContinue: Callback<unknown>, shouldCallFn: (this: void, node: AstNode, parents: AstNode[]) => node is CN, fn: (this: void, node: CN, parents: AstNode[]) => void): void;
|
|
5
|
+
export declare function traversePreOrder(node: DeepReadonly<AstNode>, shouldContinue: Callback<unknown>, shouldCallFn: Callback<unknown>, fn: Callback<void>): void;
|
|
16
6
|
export {};
|
|
17
7
|
//# sourceMappingURL=util.d.ts.map
|
package/lib/processor/util.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Range } from '../source/index.js';
|
|
2
1
|
export function traversePreOrder(node, shouldContinue, shouldCallFn, fn) {
|
|
3
2
|
traversePreOrderImpl(node, shouldContinue, shouldCallFn, fn, []);
|
|
4
3
|
}
|
|
@@ -15,13 +14,4 @@ function traversePreOrderImpl(node, shouldContinue, shouldCallFn, fn, parents) {
|
|
|
15
14
|
parents.shift();
|
|
16
15
|
}
|
|
17
16
|
}
|
|
18
|
-
/**
|
|
19
|
-
* @returns The shallowest node that is fully contained within `range`.
|
|
20
|
-
*/
|
|
21
|
-
export function findNode(node, range) {
|
|
22
|
-
let ans = { node: undefined, parents: [] };
|
|
23
|
-
// TODO: Binary search here.
|
|
24
|
-
traversePreOrder(node, (node) => ans.node === undefined && Range.intersects(node.range, range), (node) => Range.containsRange(range, node.range), (node, parents) => ans = { node, parents: [...parents] });
|
|
25
|
-
return ans;
|
|
26
|
-
}
|
|
27
17
|
//# sourceMappingURL=util.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
1
2
|
import { SymbolTable } from '../symbol/index.js';
|
|
2
3
|
import type { RootUriString } from './fileUtil.js';
|
|
3
4
|
import type { Project } from './Project.js';
|
|
@@ -48,6 +49,7 @@ export declare class CacheService {
|
|
|
48
49
|
* @returns If the cache file was saved successfully.
|
|
49
50
|
*/
|
|
50
51
|
save(): Promise<boolean>;
|
|
52
|
+
hasFileChangedSinceCache(doc: TextDocument): Promise<boolean>;
|
|
51
53
|
reset(): void;
|
|
52
54
|
}
|
|
53
55
|
export {};
|
|
@@ -178,6 +178,9 @@ export class CacheService {
|
|
|
178
178
|
}
|
|
179
179
|
return false;
|
|
180
180
|
}
|
|
181
|
+
async hasFileChangedSinceCache(doc) {
|
|
182
|
+
return this.checksums.files[doc.uri] !== await this.project.externals.crypto.getSha1(doc.getText());
|
|
183
|
+
}
|
|
181
184
|
reset() {
|
|
182
185
|
this.checksums = Checksums.create();
|
|
183
186
|
}
|
package/lib/service/Context.d.ts
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Logger } from '../common/index.js';
|
|
3
3
|
import type { Range } from '../source/index.js';
|
|
4
4
|
import { ReadonlySource } from '../source/index.js';
|
|
5
|
-
import type {
|
|
5
|
+
import type { SymbolUtil } from '../symbol/index.js';
|
|
6
6
|
import type { Config } from './Config.js';
|
|
7
7
|
import { ErrorReporter } from './ErrorReporter.js';
|
|
8
8
|
import type { FileService } from './FileService.js';
|
|
9
9
|
import type { RootUriString } from './fileUtil.js';
|
|
10
|
-
import type {
|
|
10
|
+
import type { LinterErrorReporter } from './index.js';
|
|
11
11
|
import type { MetaRegistry } from './MetaRegistry.js';
|
|
12
|
-
import { Operations } from './Operations.js';
|
|
13
12
|
import type { ProfilerFactory } from './Profiler.js';
|
|
14
|
-
import type {
|
|
13
|
+
import type { ProjectData } from './Project.js';
|
|
15
14
|
export interface ContextBase {
|
|
16
15
|
fs: FileService;
|
|
17
|
-
getDocAndNode: (uri: string) => DocAndNode | undefined;
|
|
18
|
-
global: SymbolTable;
|
|
19
16
|
logger: Logger;
|
|
20
17
|
meta: MetaRegistry;
|
|
21
18
|
profilers: ProfilerFactory;
|
|
@@ -29,7 +26,6 @@ export interface ParserContext extends ContextBase {
|
|
|
29
26
|
config: Config;
|
|
30
27
|
doc: TextDocument;
|
|
31
28
|
err: ErrorReporter;
|
|
32
|
-
symbols: SymbolUtil;
|
|
33
29
|
}
|
|
34
30
|
interface ParserContextOptions {
|
|
35
31
|
doc: TextDocument;
|
|
@@ -69,14 +65,22 @@ interface ProcessorWithOffsetContextOptions extends ProcessorContextOptions {
|
|
|
69
65
|
declare namespace ProcessorWithOffsetContext {
|
|
70
66
|
function create(project: ProjectData, opts: ProcessorWithOffsetContextOptions): ProcessorWithOffsetContext;
|
|
71
67
|
}
|
|
68
|
+
export interface BinderContext extends ProcessorContext {
|
|
69
|
+
err: ErrorReporter;
|
|
70
|
+
ensureBindingStarted: (this: void, uri: string) => Promise<unknown>;
|
|
71
|
+
}
|
|
72
|
+
interface BinderContextOptions extends ProcessorContextOptions {
|
|
73
|
+
err?: ErrorReporter;
|
|
74
|
+
}
|
|
75
|
+
export declare namespace BinderContext {
|
|
76
|
+
function create(project: ProjectData, opts: BinderContextOptions): BinderContext;
|
|
77
|
+
}
|
|
72
78
|
export interface CheckerContext extends ProcessorContext {
|
|
73
79
|
err: ErrorReporter;
|
|
74
|
-
|
|
75
|
-
ensureChecked: (this: void, uri: string) => Promise<unknown>;
|
|
80
|
+
ensureBindingStarted: (this: void, uri: string) => Promise<unknown>;
|
|
76
81
|
}
|
|
77
82
|
interface CheckerContextOptions extends ProcessorContextOptions {
|
|
78
83
|
err?: ErrorReporter;
|
|
79
|
-
ops?: Operations;
|
|
80
84
|
}
|
|
81
85
|
export declare namespace CheckerContext {
|
|
82
86
|
function create(project: ProjectData, opts: CheckerContextOptions): CheckerContext;
|
|
@@ -133,7 +137,6 @@ export declare namespace SignatureHelpProviderContext {
|
|
|
133
137
|
function create(project: ProjectData, opts: SignatureHelpProviderContextOptions): SignatureHelpProviderContext;
|
|
134
138
|
}
|
|
135
139
|
export interface UriBinderContext extends ContextBase {
|
|
136
|
-
/** @deprecated */
|
|
137
140
|
symbols: SymbolUtil;
|
|
138
141
|
}
|
|
139
142
|
export declare namespace UriBinderContext {
|
package/lib/service/Context.js
CHANGED
|
@@ -2,14 +2,11 @@
|
|
|
2
2
|
import { formatterContextIndentation } from '../processor/index.js';
|
|
3
3
|
import { ReadonlySource } from '../source/index.js';
|
|
4
4
|
import { ErrorReporter } from './ErrorReporter.js';
|
|
5
|
-
import { Operations } from './Operations.js';
|
|
6
5
|
export var ContextBase;
|
|
7
6
|
(function (ContextBase) {
|
|
8
7
|
function create(project) {
|
|
9
8
|
return {
|
|
10
9
|
fs: project.fs,
|
|
11
|
-
getDocAndNode: project.get.bind(project),
|
|
12
|
-
global: project.symbols.global,
|
|
13
10
|
logger: project.logger,
|
|
14
11
|
meta: project.meta,
|
|
15
12
|
profilers: project.profilers,
|
|
@@ -27,7 +24,6 @@ export var ParserContext;
|
|
|
27
24
|
config: project.config,
|
|
28
25
|
doc: opts.doc,
|
|
29
26
|
err: opts.err ?? new ErrorReporter(),
|
|
30
|
-
symbols: project.symbols,
|
|
31
27
|
};
|
|
32
28
|
}
|
|
33
29
|
ParserContext.create = create;
|
|
@@ -65,14 +61,24 @@ var ProcessorWithOffsetContext;
|
|
|
65
61
|
}
|
|
66
62
|
ProcessorWithOffsetContext.create = create;
|
|
67
63
|
})(ProcessorWithOffsetContext || (ProcessorWithOffsetContext = {}));
|
|
64
|
+
export var BinderContext;
|
|
65
|
+
(function (BinderContext) {
|
|
66
|
+
function create(project, opts) {
|
|
67
|
+
return {
|
|
68
|
+
...ProcessorContext.create(project, opts),
|
|
69
|
+
err: opts.err ?? new ErrorReporter(),
|
|
70
|
+
ensureBindingStarted: project.ensureBindingStarted?.bind(project),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
BinderContext.create = create;
|
|
74
|
+
})(BinderContext || (BinderContext = {}));
|
|
68
75
|
export var CheckerContext;
|
|
69
76
|
(function (CheckerContext) {
|
|
70
77
|
function create(project, opts) {
|
|
71
78
|
return {
|
|
72
79
|
...ProcessorContext.create(project, opts),
|
|
73
80
|
err: opts.err ?? new ErrorReporter(),
|
|
74
|
-
|
|
75
|
-
ensureChecked: project.ensureParsedAndChecked?.bind(project),
|
|
81
|
+
ensureBindingStarted: project.ensureBindingStarted?.bind(project),
|
|
76
82
|
};
|
|
77
83
|
}
|
|
78
84
|
CheckerContext.create = create;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { ExternalDownloaderOptions, Externals, RemoteUriString } from '../common/index.js';
|
|
1
|
+
import type { ExternalDownloaderOptions, Externals, Logger, RemoteUriString } from '../common/index.js';
|
|
2
2
|
import type { RootUriString } from './fileUtil.js';
|
|
3
|
-
import type { Logger } from './Logger.js';
|
|
4
3
|
export interface DownloaderDownloadOut {
|
|
5
4
|
cacheUri?: string;
|
|
6
5
|
checksum?: string;
|