@spyglassmc/core 0.1.0 → 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.d.ts +21 -0
- package/lib/common/TwoWayMap.js +69 -0
- 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 -13
- package/lib/common/util.d.ts +17 -34
- package/lib/common/util.js +32 -113
- package/lib/index.d.ts +7 -7
- package/lib/index.js +7 -19
- 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 +4 -4
- package/lib/node/LiteralNode.js +5 -8
- 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 +6 -8
- package/lib/node/ResourceLocationNode.js +9 -12
- package/lib/node/Sequence.d.ts +4 -3
- package/lib/node/Sequence.js +4 -6
- 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 +5 -8
- package/lib/node/index.d.ts +15 -15
- package/lib/node/index.js +15 -27
- 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 -34
- 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 +7 -7
- package/lib/parser/string.js +40 -44
- package/lib/parser/symbol.d.ts +3 -3
- package/lib/parser/symbol.js +3 -7
- package/lib/parser/util.d.ts +30 -12
- package/lib/parser/util.js +78 -63
- 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 +5 -4
- package/lib/processor/checker/builtin.js +26 -28
- package/lib/processor/checker/index.d.ts +2 -2
- package/lib/processor/checker/index.js +2 -27
- 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 -27
- 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 +58 -74
- package/lib/processor/completer/index.d.ts +2 -2
- package/lib/processor/completer/index.js +2 -27
- 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 -27
- package/lib/processor/index.d.ts +9 -9
- package/lib/processor/index.js +9 -21
- 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 +23 -27
- package/lib/processor/linter/builtin.d.ts +3 -3
- package/lib/processor/linter/builtin.js +19 -31
- package/lib/processor/linter/index.d.ts +2 -2
- package/lib/processor/linter/index.js +2 -27
- 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 +38 -48
- package/lib/service/Config.d.ts +17 -16
- package/lib/service/Config.js +56 -51
- package/lib/service/Context.d.ts +14 -14
- package/lib/service/Context.js +30 -32
- package/lib/service/Dependency.js +2 -5
- package/lib/service/Downloader.d.ts +10 -39
- package/lib/service/Downloader.js +37 -106
- package/lib/service/ErrorReporter.d.ts +2 -2
- package/lib/service/ErrorReporter.js +11 -15
- package/lib/service/FileService.d.ts +41 -14
- package/lib/service/FileService.js +107 -81
- 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 +50 -51
- package/lib/service/Project.js +240 -238
- package/lib/service/Service.d.ts +19 -29
- package/lib/service/Service.js +57 -53
- 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 +21 -41
- package/lib/service/fileUtil.js +59 -129
- package/lib/service/index.d.ts +17 -17
- package/lib/service/index.js +17 -31
- 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 +3 -6
- 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 +12 -4
- package/lib/source/Source.js +84 -29
- package/lib/source/index.d.ts +8 -8
- package/lib/source/index.js +8 -20
- package/lib/symbol/Symbol.d.ts +15 -15
- package/lib/symbol/Symbol.js +53 -68
- package/lib/symbol/SymbolUtil.d.ts +23 -33
- package/lib/symbol/SymbolUtil.js +162 -163
- 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 -15
- package/package.json +7 -4
- package/lib/common/Heap.d.ts +0 -1
- package/lib/common/Heap.js +0 -2
- package/lib/node/TableNode.d.ts +0 -17
- package/lib/node/TableNode.js +0 -11
- package/lib/parser/table.d.ts +0 -22
- package/lib/parser/table.js +0 -97
- package/lib/service/CommandExecutor.d.ts +0 -3
- package/lib/service/CommandExecutor.js +0 -7
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const symbol_1 = require("../../symbol");
|
|
8
|
-
const undeclaredSymbol_1 = require("./builtin/undeclaredSymbol");
|
|
9
|
-
const noop = () => { };
|
|
10
|
-
exports.noop = noop;
|
|
1
|
+
import { localeQuote, localize } from '@spyglassmc/locales';
|
|
2
|
+
import { isAllowedCharacter } from '../../parser/index.js';
|
|
3
|
+
import { SymbolLinterConfig } from '../../service/index.js';
|
|
4
|
+
import { McdocCategories } from '../../symbol/index.js';
|
|
5
|
+
import { undeclaredSymbol } from './builtin/undeclaredSymbol.js';
|
|
6
|
+
export const noop = () => { };
|
|
11
7
|
/**
|
|
12
8
|
* @param key The name of the key on the {@link AstNode} that contains the value to be validated.
|
|
13
9
|
*/
|
|
14
|
-
function nameConvention(key) {
|
|
10
|
+
export function nameConvention(key) {
|
|
15
11
|
return (node, ctx) => {
|
|
16
12
|
if (typeof node[key] !== 'string') {
|
|
17
13
|
throw new Error(`Trying to access property "${key}" of node type "${node.type}"`);
|
|
@@ -21,7 +17,7 @@ function nameConvention(key) {
|
|
|
21
17
|
// SECURITY: ReDoS attack. The risk is acceptable at the moment.
|
|
22
18
|
const regex = new RegExp(ctx.ruleValue);
|
|
23
19
|
if (!name.match(regex)) {
|
|
24
|
-
ctx.err.lint(
|
|
20
|
+
ctx.err.lint(localize('linter.name-convention.illegal', localeQuote(name), localeQuote(ctx.ruleValue)), node);
|
|
25
21
|
}
|
|
26
22
|
}
|
|
27
23
|
catch (e) {
|
|
@@ -29,11 +25,10 @@ function nameConvention(key) {
|
|
|
29
25
|
}
|
|
30
26
|
};
|
|
31
27
|
}
|
|
32
|
-
|
|
33
|
-
const quote = (node, ctx) => {
|
|
28
|
+
export const quote = (node, ctx) => {
|
|
34
29
|
const config = ctx.ruleValue;
|
|
35
30
|
const mustValueBeQuoted = node.options.unquotable
|
|
36
|
-
? [...node.value].some(c => !
|
|
31
|
+
? [...node.value].some(c => !isAllowedCharacter(c, node.options.unquotable))
|
|
37
32
|
: true;
|
|
38
33
|
const isQuoteRequired = config.always || mustValueBeQuoted;
|
|
39
34
|
const isQuoteProhibited = config.always === false && !mustValueBeQuoted;
|
|
@@ -53,18 +48,17 @@ const quote = (node, ctx) => {
|
|
|
53
48
|
// TODO: Error no quote expected
|
|
54
49
|
}
|
|
55
50
|
};
|
|
56
|
-
|
|
57
|
-
var configValidator;
|
|
51
|
+
export var configValidator;
|
|
58
52
|
(function (configValidator) {
|
|
59
53
|
function getDocLink(name) {
|
|
60
54
|
return `https://spyglassmc.com/user/lint/${name}`;
|
|
61
55
|
}
|
|
62
56
|
function wrapError(name, msg) {
|
|
63
|
-
return `[Invalid Linter Config] [${name}] ${
|
|
57
|
+
return `[Invalid Linter Config] [${name}] ${localize('linter-config-validator.wrapper', msg, getDocLink(name))}`;
|
|
64
58
|
}
|
|
65
59
|
function nameConvention(name, val, logger) {
|
|
66
60
|
if (typeof val !== 'string') {
|
|
67
|
-
logger.error(wrapError(name,
|
|
61
|
+
logger.error(wrapError(name, localize('linter-config-validator.name-convention.type')));
|
|
68
62
|
return false;
|
|
69
63
|
}
|
|
70
64
|
try {
|
|
@@ -72,7 +66,7 @@ var configValidator;
|
|
|
72
66
|
new RegExp(val);
|
|
73
67
|
}
|
|
74
68
|
catch (e) {
|
|
75
|
-
logger.error(wrapError(name,
|
|
69
|
+
logger.error(wrapError(name, localize('') // FIXME
|
|
76
70
|
), e);
|
|
77
71
|
return false;
|
|
78
72
|
}
|
|
@@ -80,16 +74,11 @@ var configValidator;
|
|
|
80
74
|
}
|
|
81
75
|
configValidator.nameConvention = nameConvention;
|
|
82
76
|
function symbolLinterConfig(_name, value, _logger) {
|
|
83
|
-
return
|
|
77
|
+
return SymbolLinterConfig.is(value);
|
|
84
78
|
}
|
|
85
79
|
configValidator.symbolLinterConfig = symbolLinterConfig;
|
|
86
|
-
})(configValidator
|
|
87
|
-
function registerLinters(meta) {
|
|
88
|
-
meta.registerLinter('nameOfNbtKey', {
|
|
89
|
-
configValidator: configValidator.nameConvention,
|
|
90
|
-
linter: nameConvention('value'),
|
|
91
|
-
nodePredicate: n => n.parent?.parent?.type === 'nbt:compound' && n.parent.type === 'pair' && n.type === 'string',
|
|
92
|
-
});
|
|
80
|
+
})(configValidator || (configValidator = {}));
|
|
81
|
+
export function registerLinters(meta) {
|
|
93
82
|
meta.registerLinter('nameOfObjective', {
|
|
94
83
|
configValidator: configValidator.nameConvention,
|
|
95
84
|
linter: nameConvention('value'),
|
|
@@ -112,9 +101,8 @@ function registerLinters(meta) {
|
|
|
112
101
|
});
|
|
113
102
|
meta.registerLinter('undeclaredSymbol', {
|
|
114
103
|
configValidator: configValidator.symbolLinterConfig,
|
|
115
|
-
linter:
|
|
116
|
-
nodePredicate: n => n.symbol && !
|
|
104
|
+
linter: undeclaredSymbol,
|
|
105
|
+
nodePredicate: n => n.symbol && !McdocCategories.includes(n.symbol.category),
|
|
117
106
|
});
|
|
118
107
|
}
|
|
119
|
-
exports.registerLinters = registerLinters;
|
|
120
108
|
//# sourceMappingURL=builtin.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * as linter from './builtin';
|
|
2
|
-
export * from './Linter';
|
|
1
|
+
export * as linter from './builtin.js';
|
|
2
|
+
export * from './Linter.js';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,28 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
22
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
23
|
-
};
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.linter = void 0;
|
|
26
|
-
exports.linter = __importStar(require("./builtin"));
|
|
27
|
-
__exportStar(require("./Linter"), exports);
|
|
1
|
+
export * as linter from './builtin.js';
|
|
2
|
+
export * from './Linter.js';
|
|
28
3
|
//# sourceMappingURL=index.js.map
|
package/lib/processor/util.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AstNode } from '../node';
|
|
2
|
-
import { Range } from '../source';
|
|
1
|
+
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
4
|
export declare function traversePreOrder(node: AstNode, shouldContinue: Callback<unknown>, shouldCallFn: Callback<unknown>, fn: Callback<unknown>): void;
|
|
5
5
|
interface NodeResult {
|
package/lib/processor/util.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.findNode = exports.traversePreOrder = void 0;
|
|
4
|
-
const source_1 = require("../source");
|
|
5
|
-
function traversePreOrder(node, shouldContinue, shouldCallFn, fn) {
|
|
1
|
+
import { Range } from '../source/index.js';
|
|
2
|
+
export function traversePreOrder(node, shouldContinue, shouldCallFn, fn) {
|
|
6
3
|
traversePreOrderImpl(node, shouldContinue, shouldCallFn, fn, []);
|
|
7
4
|
}
|
|
8
|
-
exports.traversePreOrder = traversePreOrder;
|
|
9
5
|
function traversePreOrderImpl(node, shouldContinue, shouldCallFn, fn, parents) {
|
|
10
6
|
if (shouldCallFn(node, parents)) {
|
|
11
7
|
fn(node, parents);
|
|
@@ -22,11 +18,10 @@ function traversePreOrderImpl(node, shouldContinue, shouldCallFn, fn, parents) {
|
|
|
22
18
|
/**
|
|
23
19
|
* @returns The shallowest node that is fully contained within `range`.
|
|
24
20
|
*/
|
|
25
|
-
function findNode(node, range) {
|
|
21
|
+
export function findNode(node, range) {
|
|
26
22
|
let ans = { node: undefined, parents: [] };
|
|
27
23
|
// TODO: Binary search here.
|
|
28
|
-
traversePreOrder(node, (node) => ans.node === undefined &&
|
|
24
|
+
traversePreOrder(node, (node) => ans.node === undefined && Range.intersects(node.range, range), (node) => Range.containsRange(range, node.range), (node, parents) => ans = { node, parents: [...parents] });
|
|
29
25
|
return ans;
|
|
30
26
|
}
|
|
31
|
-
exports.findNode = findNode;
|
|
32
27
|
//# sourceMappingURL=util.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { SymbolTable } from '../symbol';
|
|
2
|
-
import type { RootUriString } from './fileUtil';
|
|
3
|
-
import type { Project } from './Project';
|
|
1
|
+
import { SymbolTable } from '../symbol/index.js';
|
|
2
|
+
import type { RootUriString } from './fileUtil.js';
|
|
3
|
+
import type { Project } from './Project.js';
|
|
4
4
|
/**
|
|
5
5
|
* The format version of the cache. Should be increased when any changes that
|
|
6
6
|
* could invalidate the cache are introduced to the Spyglass codebase.
|
|
@@ -35,13 +35,13 @@ export declare class CacheService {
|
|
|
35
35
|
* @param cacheRoot File path to the directory where cache files by Spyglass should be stored.
|
|
36
36
|
* @param project
|
|
37
37
|
*/
|
|
38
|
-
constructor(cacheRoot:
|
|
38
|
+
constructor(cacheRoot: RootUriString, project: Project);
|
|
39
39
|
/**
|
|
40
40
|
* @throws
|
|
41
41
|
*
|
|
42
|
-
* @returns `${cacheRoot}
|
|
42
|
+
* @returns `${cacheRoot}symbols/${sha1(projectRoot)}.json`
|
|
43
43
|
*/
|
|
44
|
-
private
|
|
44
|
+
private getCacheFileUri;
|
|
45
45
|
load(): Promise<LoadResult>;
|
|
46
46
|
validate(): Promise<ValidateResult>;
|
|
47
47
|
/**
|
|
@@ -1,30 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
8
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
11
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
12
|
-
};
|
|
13
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
-
};
|
|
16
|
-
var _CacheService_cacheFilePath;
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.CacheService = exports.LatestCacheVersion = void 0;
|
|
19
|
-
const path_1 = __importDefault(require("path"));
|
|
20
|
-
const common_1 = require("../common");
|
|
21
|
-
const symbol_1 = require("../symbol");
|
|
22
|
-
const fileUtil_1 = require("./fileUtil");
|
|
1
|
+
import { Uri } from '../common/index.js';
|
|
2
|
+
import { SymbolTable } from '../symbol/index.js';
|
|
3
|
+
import { fileUtil } from './fileUtil.js';
|
|
23
4
|
/**
|
|
24
5
|
* The format version of the cache. Should be increased when any changes that
|
|
25
6
|
* could invalidate the cache are introduced to the Spyglass codebase.
|
|
26
7
|
*/
|
|
27
|
-
|
|
8
|
+
export const LatestCacheVersion = 1;
|
|
28
9
|
var Checksums;
|
|
29
10
|
(function (Checksums) {
|
|
30
11
|
function create() {
|
|
@@ -36,7 +17,11 @@ var Checksums;
|
|
|
36
17
|
}
|
|
37
18
|
Checksums.create = create;
|
|
38
19
|
})(Checksums || (Checksums = {}));
|
|
39
|
-
class CacheService {
|
|
20
|
+
export class CacheService {
|
|
21
|
+
cacheRoot;
|
|
22
|
+
project;
|
|
23
|
+
checksums = Checksums.create();
|
|
24
|
+
#hasValidatedFiles = false;
|
|
40
25
|
/**
|
|
41
26
|
* @param cacheRoot File path to the directory where cache files by Spyglass should be stored.
|
|
42
27
|
* @param project
|
|
@@ -44,26 +29,30 @@ class CacheService {
|
|
|
44
29
|
constructor(cacheRoot, project) {
|
|
45
30
|
this.cacheRoot = cacheRoot;
|
|
46
31
|
this.project = project;
|
|
47
|
-
this.
|
|
48
|
-
|
|
49
|
-
|
|
32
|
+
this.project.on('documentUpdated', async ({ doc }) => {
|
|
33
|
+
if (!this.#hasValidatedFiles) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
50
36
|
try {
|
|
51
37
|
// TODO: Don't update this for every single change.
|
|
52
|
-
this.checksums.files[doc.uri] =
|
|
38
|
+
this.checksums.files[doc.uri] = await this.project.externals.crypto.getSha1(doc.getText());
|
|
53
39
|
}
|
|
54
40
|
catch (e) {
|
|
55
|
-
if (!
|
|
41
|
+
if (!this.project.externals.error.isKind(e, 'EISDIR')) {
|
|
56
42
|
this.project.logger.error(`[CacheService#hash-file] ${doc.uri}`);
|
|
57
43
|
}
|
|
58
44
|
}
|
|
59
45
|
});
|
|
60
46
|
this.project.on('rootsUpdated', async ({ roots }) => {
|
|
47
|
+
if (!this.#hasValidatedFiles) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
61
50
|
for (const root of roots) {
|
|
62
51
|
try {
|
|
63
52
|
this.checksums.roots[root] = await this.project.fs.hash(root);
|
|
64
53
|
}
|
|
65
54
|
catch (e) {
|
|
66
|
-
if (!
|
|
55
|
+
if (!this.project.externals.error.isKind(e, 'EISDIR')) {
|
|
67
56
|
this.project.logger.error(`[CacheService#hash-root] ${root}`);
|
|
68
57
|
}
|
|
69
58
|
}
|
|
@@ -75,34 +64,36 @@ class CacheService {
|
|
|
75
64
|
}
|
|
76
65
|
});
|
|
77
66
|
}
|
|
67
|
+
#cacheFilePath;
|
|
78
68
|
/**
|
|
79
69
|
* @throws
|
|
80
70
|
*
|
|
81
|
-
* @returns `${cacheRoot}
|
|
71
|
+
* @returns `${cacheRoot}symbols/${sha1(projectRoot)}.json`
|
|
82
72
|
*/
|
|
83
|
-
|
|
84
|
-
return
|
|
73
|
+
async getCacheFileUri() {
|
|
74
|
+
return this.#cacheFilePath ??= new Uri(`symbols/${await this.project.externals.crypto.getSha1(this.project.projectRoot)}.json.gz`, this.cacheRoot).toString();
|
|
85
75
|
}
|
|
86
76
|
async load() {
|
|
87
77
|
const __profiler = this.project.profilers.get('cache#load');
|
|
88
78
|
const ans = { symbols: {} };
|
|
89
79
|
let filePath;
|
|
90
80
|
try {
|
|
91
|
-
filePath = this.
|
|
92
|
-
|
|
81
|
+
filePath = await this.getCacheFileUri();
|
|
82
|
+
this.project.logger.info(`[CacheService#load] symbolCachePath = “${filePath}”`);
|
|
83
|
+
const cache = await fileUtil.readGzippedJson(this.project.externals, filePath);
|
|
93
84
|
__profiler.task('Read File');
|
|
94
|
-
if (cache.version ===
|
|
85
|
+
if (cache.version === LatestCacheVersion) {
|
|
95
86
|
this.checksums = cache.checksums;
|
|
96
|
-
ans.symbols =
|
|
87
|
+
ans.symbols = SymbolTable.link(cache.symbols);
|
|
97
88
|
__profiler.task('Link Symbols');
|
|
98
89
|
}
|
|
99
90
|
else {
|
|
100
|
-
this.project.logger.info(`[CacheService#load] Unsupported cache format ${cache.version}; expected ${
|
|
91
|
+
this.project.logger.info(`[CacheService#load] Unsupported cache format ${cache.version}; expected ${LatestCacheVersion}`);
|
|
101
92
|
}
|
|
102
93
|
}
|
|
103
94
|
catch (e) {
|
|
104
|
-
if (!(
|
|
105
|
-
this.project.logger.error(
|
|
95
|
+
if (!this.project.externals.error.isKind(e, 'ENOENT')) {
|
|
96
|
+
this.project.logger.error('[CacheService#load] ', e);
|
|
106
97
|
}
|
|
107
98
|
}
|
|
108
99
|
__profiler.finalize();
|
|
@@ -124,7 +115,7 @@ class CacheService {
|
|
|
124
115
|
}
|
|
125
116
|
}
|
|
126
117
|
catch (e) {
|
|
127
|
-
if (!
|
|
118
|
+
if (!this.project.externals.error.isKind(e, 'EISDIR')) {
|
|
128
119
|
this.project.logger.error(`[CacheService#hash-file] ${uri}`);
|
|
129
120
|
}
|
|
130
121
|
// Failed calculating hash. Assume the root has changed.
|
|
@@ -145,7 +136,7 @@ class CacheService {
|
|
|
145
136
|
}
|
|
146
137
|
}
|
|
147
138
|
catch (e) {
|
|
148
|
-
if ((
|
|
139
|
+
if (this.project.externals.error.isKind(e, 'ENOENT') || this.project.externals.error.isKind(e, 'EISDIR')) {
|
|
149
140
|
ans.removedFiles.push(uri);
|
|
150
141
|
}
|
|
151
142
|
else {
|
|
@@ -160,6 +151,7 @@ class CacheService {
|
|
|
160
151
|
ans.addedFiles.push(uri);
|
|
161
152
|
}
|
|
162
153
|
}
|
|
154
|
+
this.#hasValidatedFiles = true;
|
|
163
155
|
return ans;
|
|
164
156
|
}
|
|
165
157
|
/**
|
|
@@ -169,15 +161,15 @@ class CacheService {
|
|
|
169
161
|
const __profiler = this.project.profilers.get('cache#save');
|
|
170
162
|
let filePath;
|
|
171
163
|
try {
|
|
172
|
-
filePath = this.
|
|
164
|
+
filePath = await this.getCacheFileUri();
|
|
173
165
|
const cache = {
|
|
174
166
|
checksums: this.checksums,
|
|
175
167
|
projectRoot: this.project.projectRoot,
|
|
176
|
-
symbols:
|
|
177
|
-
version:
|
|
168
|
+
symbols: SymbolTable.unlink(this.project.symbols.global),
|
|
169
|
+
version: LatestCacheVersion,
|
|
178
170
|
};
|
|
179
171
|
__profiler.task('Unlink Symbols');
|
|
180
|
-
await
|
|
172
|
+
await fileUtil.writeGzippedJson(this.project.externals, filePath, cache);
|
|
181
173
|
__profiler.task('Write File').finalize();
|
|
182
174
|
return true;
|
|
183
175
|
}
|
|
@@ -190,6 +182,4 @@ class CacheService {
|
|
|
190
182
|
this.checksums = Checksums.create();
|
|
191
183
|
}
|
|
192
184
|
}
|
|
193
|
-
exports.CacheService = CacheService;
|
|
194
|
-
_CacheService_cacheFilePath = new WeakMap();
|
|
195
185
|
//# sourceMappingURL=CacheService.js.map
|
package/lib/service/Config.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import type { Project } from './Project';
|
|
1
|
+
import type { ExternalEventEmitter } from '../common/index.js';
|
|
2
|
+
import { Arrayable } from '../common/index.js';
|
|
3
|
+
import { ErrorSeverity } from '../source/index.js';
|
|
4
|
+
import type { Project } from './Project.js';
|
|
6
5
|
export interface Config {
|
|
7
6
|
/**
|
|
8
7
|
* Environment settings. Unlike other configs, all involved root folders must have the same `env` settings. It is undocumented
|
|
@@ -24,15 +23,17 @@ export interface Config {
|
|
|
24
23
|
}
|
|
25
24
|
export interface EnvConfig {
|
|
26
25
|
/**
|
|
27
|
-
* Where to download data like `mcmeta` or `
|
|
26
|
+
* Where to download data like `mcmeta` or `vanilla-mcdoc` from (case-insensitive).
|
|
28
27
|
*
|
|
29
|
-
* * `GitHub`
|
|
30
|
-
* * `
|
|
28
|
+
* * `GitHub`: Recommended, unless you have trouble connecting to `raw.githubusercontent.com`.
|
|
29
|
+
* * `fastly`
|
|
30
|
+
* * `jsDelivr`
|
|
31
|
+
* * A custom URL, with placeholder variables: `${user}`, `${repo}`, `${tag}`, and `${path}`.
|
|
31
32
|
*/
|
|
32
33
|
dataSource: string;
|
|
33
34
|
/**
|
|
34
35
|
* A list of data packs the current project depends on. Each value in this array can be either an absolute file path
|
|
35
|
-
* to a data pack folder or data pack archive (e.g. `.zip` or `.tar.gz`), or a special string like `@
|
|
36
|
+
* to a data pack folder or data pack archive (e.g. `.zip` or `.tar.gz`), or a special string like `@vanilla-mcdoc`.
|
|
36
37
|
*/
|
|
37
38
|
dependencies: string[];
|
|
38
39
|
feature: {
|
|
@@ -198,21 +199,21 @@ declare type ErrorEvent = {
|
|
|
198
199
|
error: unknown;
|
|
199
200
|
uri: string;
|
|
200
201
|
};
|
|
201
|
-
export
|
|
202
|
+
export declare class ConfigService implements ExternalEventEmitter {
|
|
203
|
+
#private;
|
|
204
|
+
private readonly project;
|
|
205
|
+
private readonly defaultConfig;
|
|
206
|
+
static readonly ConfigFileNames: readonly ["spyglass.json", ".spyglassrc.json"];
|
|
207
|
+
constructor(project: Project, defaultConfig?: Config);
|
|
202
208
|
on(event: 'changed', callbackFn: (data: ConfigEvent) => void): this;
|
|
203
209
|
on(event: 'error', callbackFn: (data: ErrorEvent) => void): this;
|
|
204
210
|
once(event: 'changed', callbackFn: (data: ConfigEvent) => void): this;
|
|
205
211
|
once(event: 'error', callbackFn: (data: ErrorEvent) => void): this;
|
|
206
212
|
emit(event: 'changed', data: ConfigEvent): boolean;
|
|
207
213
|
emit(event: 'error', data: ErrorEvent): boolean;
|
|
208
|
-
}
|
|
209
|
-
export declare class ConfigService extends EventEmitter {
|
|
210
|
-
private readonly project;
|
|
211
|
-
static readonly ConfigFileNames: readonly ["spyglass.json", ".spyglassrc.json"];
|
|
212
|
-
constructor(project: Project);
|
|
213
214
|
load(): Promise<Config>;
|
|
214
215
|
private static isConfigFile;
|
|
215
|
-
|
|
216
|
+
static merge(base: Config, ...overrides: any[]): Config;
|
|
216
217
|
}
|
|
217
218
|
export {};
|
|
218
219
|
//# sourceMappingURL=Config.d.ts.map
|