@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
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const symbol_1 = require("../../../symbol");
|
|
8
|
-
const undeclaredSymbol = (node, ctx) => {
|
|
9
|
-
if (!node.symbol || symbol_1.SymbolUtil.isDeclared(node.symbol)) {
|
|
1
|
+
import { localeQuote, localize } from '@spyglassmc/locales';
|
|
2
|
+
import { Arrayable, ResourceLocation } from '../../../common/index.js';
|
|
3
|
+
import { LinterSeverity, SymbolLinterConfig as Config } from '../../../service/index.js';
|
|
4
|
+
import { SymbolUtil } from '../../../symbol/index.js';
|
|
5
|
+
export const undeclaredSymbol = (node, ctx) => {
|
|
6
|
+
if (!node.symbol || SymbolUtil.isDeclared(node.symbol)) {
|
|
10
7
|
return;
|
|
11
8
|
}
|
|
12
9
|
const action = getAction(ctx.ruleValue, node.symbol, ctx);
|
|
13
|
-
if (
|
|
10
|
+
if (Config.Action.isDeclare(action)) {
|
|
14
11
|
ctx.symbols
|
|
15
12
|
.query({ doc: ctx.doc, node }, node.symbol.category, ...node.symbol.path)
|
|
16
13
|
.amend({
|
|
@@ -18,28 +15,27 @@ const undeclaredSymbol = (node, ctx) => {
|
|
|
18
15
|
usage: { type: 'declaration', node },
|
|
19
16
|
});
|
|
20
17
|
}
|
|
21
|
-
if (
|
|
22
|
-
const severityOverride = action.report === 'inherit' ? undefined :
|
|
23
|
-
ctx.err.lint(
|
|
18
|
+
if (Config.Action.isReport(action)) {
|
|
19
|
+
const severityOverride = action.report === 'inherit' ? undefined : LinterSeverity.toErrorSeverity(action.report);
|
|
20
|
+
ctx.err.lint(localize('linter.undeclared-symbol.message', node.symbol.category, localeQuote(node.symbol.identifier)), node, undefined, severityOverride);
|
|
24
21
|
}
|
|
25
22
|
};
|
|
26
|
-
exports.undeclaredSymbol = undeclaredSymbol;
|
|
27
23
|
function getAction(config, symbol, ctx) {
|
|
28
|
-
if (
|
|
24
|
+
if (Config.Action.is(config)) {
|
|
29
25
|
return config;
|
|
30
26
|
}
|
|
31
27
|
function test(conditions) {
|
|
32
28
|
function testSingleCondition(condition) {
|
|
33
|
-
const resourceLocation =
|
|
34
|
-
const namespace = resourceLocation.slice(0, resourceLocation.indexOf(
|
|
35
|
-
return ((condition.category ?
|
|
36
|
-
(condition.namespace ?
|
|
37
|
-
(condition.excludeNamespace ? !
|
|
38
|
-
(condition.pattern ?
|
|
39
|
-
(condition.excludePattern ? !
|
|
29
|
+
const resourceLocation = ResourceLocation.lengthen(symbol.identifier);
|
|
30
|
+
const namespace = resourceLocation.slice(0, resourceLocation.indexOf(ResourceLocation.NamespacePathSep));
|
|
31
|
+
return ((condition.category ? Arrayable.toArray(condition.category).includes(symbol.category) : true) &&
|
|
32
|
+
(condition.namespace ? Arrayable.toArray(condition.namespace).includes(namespace) : true) &&
|
|
33
|
+
(condition.excludeNamespace ? !Arrayable.toArray(condition.excludeNamespace).includes(namespace) : true) &&
|
|
34
|
+
(condition.pattern ? Arrayable.toArray(condition.pattern).some(p => new RegExp(p).test(symbol.identifier)) : true) &&
|
|
35
|
+
(condition.excludePattern ? !Arrayable.toArray(condition.excludePattern).some(p => new RegExp(p).test(symbol.identifier)) : true));
|
|
40
36
|
}
|
|
41
37
|
try {
|
|
42
|
-
return
|
|
38
|
+
return Arrayable.toArray(conditions).some(testSingleCondition);
|
|
43
39
|
}
|
|
44
40
|
catch (e) {
|
|
45
41
|
// Illegal RegExp.
|
|
@@ -48,7 +44,7 @@ function getAction(config, symbol, ctx) {
|
|
|
48
44
|
}
|
|
49
45
|
}
|
|
50
46
|
function evaluateComplexes(complexes) {
|
|
51
|
-
for (const complex of
|
|
47
|
+
for (const complex of Arrayable.toArray(complexes)) {
|
|
52
48
|
if (complex.if && !test(complex.if)) {
|
|
53
49
|
continue;
|
|
54
50
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
1
|
+
import type { Logger } from '../../common/index.js';
|
|
2
|
+
import type { AstNode, StringBaseNode } from '../../node/index.js';
|
|
3
|
+
import type { MetaRegistry } from '../../service/index.js';
|
|
4
|
+
import type { Linter } from './Linter.js';
|
|
4
5
|
export declare const noop: Linter<AstNode>;
|
|
5
6
|
/**
|
|
6
7
|
* @param key The name of the key on the {@link AstNode} that contains the value to be validated.
|
|
@@ -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,11 +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) {
|
|
80
|
+
})(configValidator || (configValidator = {}));
|
|
81
|
+
export function registerLinters(meta) {
|
|
88
82
|
meta.registerLinter('nameOfObjective', {
|
|
89
83
|
configValidator: configValidator.nameConvention,
|
|
90
84
|
linter: nameConvention('value'),
|
|
@@ -107,9 +101,8 @@ function registerLinters(meta) {
|
|
|
107
101
|
});
|
|
108
102
|
meta.registerLinter('undeclaredSymbol', {
|
|
109
103
|
configValidator: configValidator.symbolLinterConfig,
|
|
110
|
-
linter:
|
|
111
|
-
nodePredicate: n => n.symbol && !
|
|
104
|
+
linter: undeclaredSymbol,
|
|
105
|
+
nodePredicate: n => n.symbol && !McdocCategories.includes(n.symbol.category),
|
|
112
106
|
});
|
|
113
107
|
}
|
|
114
|
-
exports.registerLinters = registerLinters;
|
|
115
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,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.linter = void 0;
|
|
30
|
-
exports.linter = __importStar(require("./builtin"));
|
|
31
|
-
__exportStar(require("./Linter"), exports);
|
|
1
|
+
export * as linter from './builtin.js';
|
|
2
|
+
export * from './Linter.js';
|
|
32
3
|
//# sourceMappingURL=index.js.map
|
package/lib/processor/util.d.ts
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
1
|
+
import type { DeepReadonly } from '../index.js';
|
|
2
|
+
import type { AstNode } from '../node/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,11 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.findNode = exports.traversePreOrder = void 0;
|
|
4
|
-
const source_1 = require("../source");
|
|
5
|
-
function traversePreOrder(node, shouldContinue, shouldCallFn, fn) {
|
|
1
|
+
export function traversePreOrder(node, shouldContinue, shouldCallFn, fn) {
|
|
6
2
|
traversePreOrderImpl(node, shouldContinue, shouldCallFn, fn, []);
|
|
7
3
|
}
|
|
8
|
-
exports.traversePreOrder = traversePreOrder;
|
|
9
4
|
function traversePreOrderImpl(node, shouldContinue, shouldCallFn, fn, parents) {
|
|
10
5
|
if (shouldCallFn(node, parents)) {
|
|
11
6
|
fn(node, parents);
|
|
@@ -19,14 +14,4 @@ function traversePreOrderImpl(node, shouldContinue, shouldCallFn, fn, parents) {
|
|
|
19
14
|
parents.shift();
|
|
20
15
|
}
|
|
21
16
|
}
|
|
22
|
-
/**
|
|
23
|
-
* @returns The shallowest node that is fully contained within `range`.
|
|
24
|
-
*/
|
|
25
|
-
function findNode(node, range) {
|
|
26
|
-
let ans = { node: undefined, parents: [] };
|
|
27
|
-
// TODO: Binary search here.
|
|
28
|
-
traversePreOrder(node, (node) => ans.node === undefined && source_1.Range.intersects(node.range, range), (node) => source_1.Range.containsRange(range, node.range), (node, parents) => ans = { node, parents: [...parents] });
|
|
29
|
-
return ans;
|
|
30
|
-
}
|
|
31
|
-
exports.findNode = findNode;
|
|
32
17
|
//# sourceMappingURL=util.js.map
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
import
|
|
1
|
+
import type { TextDocument } from 'vscode-languageserver-textdocument';
|
|
2
|
+
import type { PosRangeLanguageError } from '../source/index.js';
|
|
3
|
+
import { SymbolTable } from '../symbol/index.js';
|
|
4
|
+
import type { RootUriString } from './fileUtil.js';
|
|
5
|
+
import type { Project } from './Project.js';
|
|
4
6
|
/**
|
|
5
7
|
* The format version of the cache. Should be increased when any changes that
|
|
6
8
|
* could invalidate the cache are introduced to the Spyglass codebase.
|
|
7
9
|
*/
|
|
8
|
-
export declare const LatestCacheVersion =
|
|
10
|
+
export declare const LatestCacheVersion = 2;
|
|
9
11
|
/**
|
|
10
12
|
* Checksums of cached files or roots.
|
|
11
13
|
*/
|
|
@@ -17,6 +19,7 @@ interface Checksums {
|
|
|
17
19
|
declare namespace Checksums {
|
|
18
20
|
function create(): Checksums;
|
|
19
21
|
}
|
|
22
|
+
declare type ErrorCache = Record<string, readonly PosRangeLanguageError[]>;
|
|
20
23
|
interface LoadResult {
|
|
21
24
|
symbols: SymbolTable;
|
|
22
25
|
}
|
|
@@ -31,24 +34,26 @@ export declare class CacheService {
|
|
|
31
34
|
private readonly cacheRoot;
|
|
32
35
|
private readonly project;
|
|
33
36
|
checksums: Checksums;
|
|
37
|
+
errors: ErrorCache;
|
|
34
38
|
/**
|
|
35
39
|
* @param cacheRoot File path to the directory where cache files by Spyglass should be stored.
|
|
36
40
|
* @param project
|
|
37
41
|
*/
|
|
38
|
-
constructor(cacheRoot:
|
|
42
|
+
constructor(cacheRoot: RootUriString, project: Project);
|
|
39
43
|
/**
|
|
40
44
|
* @throws
|
|
41
45
|
*
|
|
42
|
-
* @returns `${cacheRoot}
|
|
46
|
+
* @returns `${cacheRoot}symbols/${sha1(projectRoot)}.json`
|
|
43
47
|
*/
|
|
44
|
-
private
|
|
48
|
+
private getCacheFileUri;
|
|
45
49
|
load(): Promise<LoadResult>;
|
|
46
50
|
validate(): Promise<ValidateResult>;
|
|
47
51
|
/**
|
|
48
52
|
* @returns If the cache file was saved successfully.
|
|
49
53
|
*/
|
|
50
54
|
save(): Promise<boolean>;
|
|
51
|
-
|
|
55
|
+
hasFileChangedSinceCache(doc: TextDocument): Promise<boolean>;
|
|
56
|
+
reset(): LoadResult;
|
|
52
57
|
}
|
|
53
58
|
export {};
|
|
54
59
|
//# sourceMappingURL=CacheService.d.ts.map
|
|
@@ -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_hasValidatedFiles, _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 = 2;
|
|
28
9
|
var Checksums;
|
|
29
10
|
(function (Checksums) {
|
|
30
11
|
function create() {
|
|
@@ -36,7 +17,12 @@ 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
|
+
errors = {};
|
|
25
|
+
#hasValidatedFiles = false;
|
|
40
26
|
/**
|
|
41
27
|
* @param cacheRoot File path to the directory where cache files by Spyglass should be stored.
|
|
42
28
|
* @param project
|
|
@@ -44,30 +30,22 @@ class CacheService {
|
|
|
44
30
|
constructor(cacheRoot, project) {
|
|
45
31
|
this.cacheRoot = cacheRoot;
|
|
46
32
|
this.project = project;
|
|
47
|
-
this.
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* @param cacheRoot File path to the directory where cache files by Spyglass should be stored.
|
|
51
|
-
* @param project
|
|
52
|
-
*/
|
|
53
|
-
);
|
|
54
|
-
_CacheService_cacheFilePath.set(this, void 0);
|
|
55
|
-
this.project.on('documentUpdated', ({ doc }) => {
|
|
56
|
-
if (!__classPrivateFieldGet(this, _CacheService_hasValidatedFiles, "f")) {
|
|
33
|
+
this.project.on('documentUpdated', async ({ doc }) => {
|
|
34
|
+
if (!this.#hasValidatedFiles) {
|
|
57
35
|
return;
|
|
58
36
|
}
|
|
59
37
|
try {
|
|
60
38
|
// TODO: Don't update this for every single change.
|
|
61
|
-
this.checksums.files[doc.uri] =
|
|
39
|
+
this.checksums.files[doc.uri] = await this.project.externals.crypto.getSha1(doc.getText());
|
|
62
40
|
}
|
|
63
41
|
catch (e) {
|
|
64
|
-
if (!
|
|
42
|
+
if (!this.project.externals.error.isKind(e, 'EISDIR')) {
|
|
65
43
|
this.project.logger.error(`[CacheService#hash-file] ${doc.uri}`);
|
|
66
44
|
}
|
|
67
45
|
}
|
|
68
46
|
});
|
|
69
47
|
this.project.on('rootsUpdated', async ({ roots }) => {
|
|
70
|
-
if (!
|
|
48
|
+
if (!this.#hasValidatedFiles) {
|
|
71
49
|
return;
|
|
72
50
|
}
|
|
73
51
|
for (const root of roots) {
|
|
@@ -75,7 +53,7 @@ class CacheService {
|
|
|
75
53
|
this.checksums.roots[root] = await this.project.fs.hash(root);
|
|
76
54
|
}
|
|
77
55
|
catch (e) {
|
|
78
|
-
if (!
|
|
56
|
+
if (!this.project.externals.error.isKind(e, 'EISDIR')) {
|
|
79
57
|
this.project.logger.error(`[CacheService#hash-root] ${root}`);
|
|
80
58
|
}
|
|
81
59
|
}
|
|
@@ -86,35 +64,40 @@ class CacheService {
|
|
|
86
64
|
this.checksums.symbolRegistrars[id] = checksum;
|
|
87
65
|
}
|
|
88
66
|
});
|
|
67
|
+
this.project.on('documentErrored', ({ uri, errors }) => {
|
|
68
|
+
this.errors[uri] = errors;
|
|
69
|
+
});
|
|
89
70
|
}
|
|
71
|
+
#cacheFilePath;
|
|
90
72
|
/**
|
|
91
73
|
* @throws
|
|
92
74
|
*
|
|
93
|
-
* @returns `${cacheRoot}
|
|
75
|
+
* @returns `${cacheRoot}symbols/${sha1(projectRoot)}.json`
|
|
94
76
|
*/
|
|
95
|
-
|
|
96
|
-
return
|
|
77
|
+
async getCacheFileUri() {
|
|
78
|
+
return this.#cacheFilePath ??= new Uri(`symbols/${await this.project.externals.crypto.getSha1(this.project.projectRoot)}.json.gz`, this.cacheRoot).toString();
|
|
97
79
|
}
|
|
98
80
|
async load() {
|
|
99
81
|
const __profiler = this.project.profilers.get('cache#load');
|
|
100
82
|
const ans = { symbols: {} };
|
|
101
83
|
let filePath;
|
|
102
84
|
try {
|
|
103
|
-
filePath = this.
|
|
85
|
+
filePath = await this.getCacheFileUri();
|
|
104
86
|
this.project.logger.info(`[CacheService#load] symbolCachePath = “${filePath}”`);
|
|
105
|
-
const cache = await
|
|
87
|
+
const cache = await fileUtil.readGzippedJson(this.project.externals, filePath);
|
|
106
88
|
__profiler.task('Read File');
|
|
107
|
-
if (cache.version ===
|
|
89
|
+
if (cache.version === LatestCacheVersion) {
|
|
108
90
|
this.checksums = cache.checksums;
|
|
109
|
-
|
|
91
|
+
this.errors = cache.errors;
|
|
92
|
+
ans.symbols = SymbolTable.link(cache.symbols);
|
|
110
93
|
__profiler.task('Link Symbols');
|
|
111
94
|
}
|
|
112
95
|
else {
|
|
113
|
-
this.project.logger.info(`[CacheService#load] Unsupported cache format ${cache.version}; expected ${
|
|
96
|
+
this.project.logger.info(`[CacheService#load] Unsupported cache format ${cache.version}; expected ${LatestCacheVersion}`);
|
|
114
97
|
}
|
|
115
98
|
}
|
|
116
99
|
catch (e) {
|
|
117
|
-
if (!(
|
|
100
|
+
if (!this.project.externals.error.isKind(e, 'ENOENT')) {
|
|
118
101
|
this.project.logger.error('[CacheService#load] ', e);
|
|
119
102
|
}
|
|
120
103
|
}
|
|
@@ -137,7 +120,7 @@ class CacheService {
|
|
|
137
120
|
}
|
|
138
121
|
}
|
|
139
122
|
catch (e) {
|
|
140
|
-
if (!
|
|
123
|
+
if (!this.project.externals.error.isKind(e, 'EISDIR')) {
|
|
141
124
|
this.project.logger.error(`[CacheService#hash-file] ${uri}`);
|
|
142
125
|
}
|
|
143
126
|
// Failed calculating hash. Assume the root has changed.
|
|
@@ -158,7 +141,7 @@ class CacheService {
|
|
|
158
141
|
}
|
|
159
142
|
}
|
|
160
143
|
catch (e) {
|
|
161
|
-
if ((
|
|
144
|
+
if (this.project.externals.error.isKind(e, 'ENOENT') || this.project.externals.error.isKind(e, 'EISDIR')) {
|
|
162
145
|
ans.removedFiles.push(uri);
|
|
163
146
|
}
|
|
164
147
|
else {
|
|
@@ -173,7 +156,7 @@ class CacheService {
|
|
|
173
156
|
ans.addedFiles.push(uri);
|
|
174
157
|
}
|
|
175
158
|
}
|
|
176
|
-
|
|
159
|
+
this.#hasValidatedFiles = true;
|
|
177
160
|
return ans;
|
|
178
161
|
}
|
|
179
162
|
/**
|
|
@@ -183,15 +166,16 @@ class CacheService {
|
|
|
183
166
|
const __profiler = this.project.profilers.get('cache#save');
|
|
184
167
|
let filePath;
|
|
185
168
|
try {
|
|
186
|
-
filePath = this.
|
|
169
|
+
filePath = await this.getCacheFileUri();
|
|
187
170
|
const cache = {
|
|
188
|
-
|
|
171
|
+
version: LatestCacheVersion,
|
|
189
172
|
projectRoot: this.project.projectRoot,
|
|
190
|
-
|
|
191
|
-
|
|
173
|
+
checksums: this.checksums,
|
|
174
|
+
symbols: SymbolTable.unlink(this.project.symbols.global),
|
|
175
|
+
errors: this.errors,
|
|
192
176
|
};
|
|
193
177
|
__profiler.task('Unlink Symbols');
|
|
194
|
-
await
|
|
178
|
+
await fileUtil.writeGzippedJson(this.project.externals, filePath, cache);
|
|
195
179
|
__profiler.task('Write File').finalize();
|
|
196
180
|
return true;
|
|
197
181
|
}
|
|
@@ -200,10 +184,14 @@ class CacheService {
|
|
|
200
184
|
}
|
|
201
185
|
return false;
|
|
202
186
|
}
|
|
187
|
+
async hasFileChangedSinceCache(doc) {
|
|
188
|
+
return this.checksums.files[doc.uri] !== await this.project.externals.crypto.getSha1(doc.getText());
|
|
189
|
+
}
|
|
203
190
|
reset() {
|
|
191
|
+
this.#hasValidatedFiles = false;
|
|
204
192
|
this.checksums = Checksums.create();
|
|
193
|
+
this.errors = {};
|
|
194
|
+
return { symbols: {} };
|
|
205
195
|
}
|
|
206
196
|
}
|
|
207
|
-
exports.CacheService = CacheService;
|
|
208
|
-
_CacheService_hasValidatedFiles = new WeakMap(), _CacheService_cacheFilePath = new WeakMap();
|
|
209
197
|
//# 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
|
|
@@ -200,21 +199,21 @@ declare type ErrorEvent = {
|
|
|
200
199
|
error: unknown;
|
|
201
200
|
uri: string;
|
|
202
201
|
};
|
|
203
|
-
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);
|
|
204
208
|
on(event: 'changed', callbackFn: (data: ConfigEvent) => void): this;
|
|
205
209
|
on(event: 'error', callbackFn: (data: ErrorEvent) => void): this;
|
|
206
210
|
once(event: 'changed', callbackFn: (data: ConfigEvent) => void): this;
|
|
207
211
|
once(event: 'error', callbackFn: (data: ErrorEvent) => void): this;
|
|
208
212
|
emit(event: 'changed', data: ConfigEvent): boolean;
|
|
209
213
|
emit(event: 'error', data: ErrorEvent): boolean;
|
|
210
|
-
}
|
|
211
|
-
export declare class ConfigService extends EventEmitter {
|
|
212
|
-
private readonly project;
|
|
213
|
-
static readonly ConfigFileNames: readonly ["spyglass.json", ".spyglassrc.json"];
|
|
214
|
-
constructor(project: Project);
|
|
215
214
|
load(): Promise<Config>;
|
|
216
215
|
private static isConfigFile;
|
|
217
|
-
|
|
216
|
+
static merge(base: Config, ...overrides: any[]): Config;
|
|
218
217
|
}
|
|
219
218
|
export {};
|
|
220
219
|
//# sourceMappingURL=Config.d.ts.map
|