@spyglassmc/core 0.1.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 +10 -0
- package/lib/common/Heap.d.ts +1 -0
- package/lib/common/Heap.js +2 -0
- package/lib/common/index.d.ts +2 -0
- package/lib/common/index.js +14 -0
- package/lib/common/util.d.ts +120 -0
- package/lib/common/util.js +292 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +20 -0
- package/lib/node/AstNode.d.ts +64 -0
- package/lib/node/AstNode.js +108 -0
- package/lib/node/BooleanNode.d.ts +13 -0
- package/lib/node/BooleanNode.js +20 -0
- package/lib/node/CommentNode.d.ts +12 -0
- package/lib/node/CommentNode.js +11 -0
- package/lib/node/ErrorNode.d.ts +8 -0
- package/lib/node/ErrorNode.js +12 -0
- package/lib/node/FileNode.d.ts +21 -0
- package/lib/node/FileNode.js +11 -0
- package/lib/node/FloatNode.d.ts +13 -0
- package/lib/node/FloatNode.js +21 -0
- package/lib/node/IntegerNode.d.ts +13 -0
- package/lib/node/IntegerNode.js +20 -0
- package/lib/node/ListNode.d.ts +15 -0
- package/lib/node/ListNode.js +11 -0
- package/lib/node/LiteralNode.d.ts +19 -0
- package/lib/node/LiteralNode.js +22 -0
- package/lib/node/LongNode.d.ts +13 -0
- package/lib/node/LongNode.js +20 -0
- package/lib/node/RecordNode.d.ts +20 -0
- package/lib/node/RecordNode.js +11 -0
- package/lib/node/ResourceLocationNode.d.ts +41 -0
- package/lib/node/ResourceLocationNode.js +65 -0
- package/lib/node/Sequence.d.ts +22 -0
- package/lib/node/Sequence.js +11 -0
- package/lib/node/StringNode.d.ts +63 -0
- package/lib/node/StringNode.js +43 -0
- package/lib/node/SymbolNode.d.ts +21 -0
- package/lib/node/SymbolNode.js +22 -0
- package/lib/node/TableNode.d.ts +17 -0
- package/lib/node/TableNode.js +11 -0
- package/lib/node/index.d.ts +16 -0
- package/lib/node/index.js +28 -0
- package/lib/parser/Parser.d.ts +16 -0
- package/lib/parser/Parser.js +5 -0
- package/lib/parser/boolean.d.ts +4 -0
- package/lib/parser/boolean.js +11 -0
- package/lib/parser/comment.d.ts +12 -0
- package/lib/parser/comment.js +34 -0
- package/lib/parser/empty.d.ts +3 -0
- package/lib/parser/empty.js +7 -0
- package/lib/parser/error.d.ts +8 -0
- package/lib/parser/error.js +22 -0
- package/lib/parser/file.d.ts +9 -0
- package/lib/parser/file.js +37 -0
- package/lib/parser/float.d.ts +33 -0
- package/lib/parser/float.js +57 -0
- package/lib/parser/index.d.ts +17 -0
- package/lib/parser/index.js +36 -0
- package/lib/parser/integer.d.ts +33 -0
- package/lib/parser/integer.js +46 -0
- package/lib/parser/list.d.ts +12 -0
- package/lib/parser/list.js +70 -0
- package/lib/parser/literal.d.ts +5 -0
- package/lib/parser/literal.js +41 -0
- package/lib/parser/long.d.ts +33 -0
- package/lib/parser/long.js +50 -0
- package/lib/parser/record.d.ts +22 -0
- package/lib/parser/record.js +97 -0
- package/lib/parser/resourceLocation.d.ts +4 -0
- package/lib/parser/resourceLocation.js +67 -0
- package/lib/parser/string.d.ts +18 -0
- package/lib/parser/string.js +129 -0
- package/lib/parser/symbol.d.ts +12 -0
- package/lib/parser/symbol.js +33 -0
- package/lib/parser/table.d.ts +22 -0
- package/lib/parser/table.js +97 -0
- package/lib/parser/util.d.ts +134 -0
- package/lib/parser/util.js +224 -0
- package/lib/processor/ColorInfoProvider.d.ts +87 -0
- package/lib/processor/ColorInfoProvider.js +141 -0
- package/lib/processor/InlayHintProvider.d.ts +8 -0
- package/lib/processor/InlayHintProvider.js +3 -0
- package/lib/processor/SignatureHelpProvider.d.ts +18 -0
- package/lib/processor/SignatureHelpProvider.js +3 -0
- package/lib/processor/checker/Checker.d.ts +7 -0
- package/lib/processor/checker/Checker.js +7 -0
- package/lib/processor/checker/builtin.d.ts +23 -0
- package/lib/processor/checker/builtin.js +83 -0
- package/lib/processor/checker/index.d.ts +3 -0
- package/lib/processor/checker/index.js +28 -0
- package/lib/processor/colorizer/Colorizer.d.ts +23 -0
- package/lib/processor/colorizer/Colorizer.js +70 -0
- package/lib/processor/colorizer/builtin.d.ts +17 -0
- package/lib/processor/colorizer/builtin.js +84 -0
- package/lib/processor/colorizer/index.d.ts +3 -0
- package/lib/processor/colorizer/index.js +28 -0
- package/lib/processor/completer/Completer.d.ts +75 -0
- package/lib/processor/completer/Completer.js +92 -0
- package/lib/processor/completer/builtin.d.ts +30 -0
- package/lib/processor/completer/builtin.js +172 -0
- package/lib/processor/completer/index.d.ts +3 -0
- package/lib/processor/completer/index.js +28 -0
- package/lib/processor/formatter/Formatter.d.ts +6 -0
- package/lib/processor/formatter/Formatter.js +19 -0
- package/lib/processor/formatter/builtin.d.ts +15 -0
- package/lib/processor/formatter/builtin.js +60 -0
- package/lib/processor/formatter/index.d.ts +3 -0
- package/lib/processor/formatter/index.js +28 -0
- package/lib/processor/index.d.ts +10 -0
- package/lib/processor/index.js +22 -0
- package/lib/processor/linter/Linter.d.ts +4 -0
- package/lib/processor/linter/Linter.js +3 -0
- package/lib/processor/linter/builtin/undeclaredSymbol.d.ts +4 -0
- package/lib/processor/linter/builtin/undeclaredSymbol.js +73 -0
- package/lib/processor/linter/builtin.d.ts +15 -0
- package/lib/processor/linter/builtin.js +120 -0
- package/lib/processor/linter/index.d.ts +3 -0
- package/lib/processor/linter/index.js +28 -0
- package/lib/processor/util.d.ts +17 -0
- package/lib/processor/util.js +32 -0
- package/lib/service/CacheService.d.ts +54 -0
- package/lib/service/CacheService.js +195 -0
- package/lib/service/CommandExecutor.d.ts +3 -0
- package/lib/service/CommandExecutor.js +7 -0
- package/lib/service/Config.d.ts +218 -0
- package/lib/service/Config.js +264 -0
- package/lib/service/Context.d.ts +143 -0
- package/lib/service/Context.js +143 -0
- package/lib/service/Dependency.d.ts +10 -0
- package/lib/service/Dependency.js +11 -0
- package/lib/service/Downloader.d.ts +67 -0
- package/lib/service/Downloader.js +185 -0
- package/lib/service/ErrorReporter.d.ts +27 -0
- package/lib/service/ErrorReporter.js +49 -0
- package/lib/service/FileService.d.ts +96 -0
- package/lib/service/FileService.js +224 -0
- package/lib/service/Hover.d.ts +10 -0
- package/lib/service/Hover.js +16 -0
- package/lib/service/Logger.d.ts +31 -0
- package/lib/service/Logger.js +30 -0
- package/lib/service/MetaRegistry.d.ts +106 -0
- package/lib/service/MetaRegistry.js +192 -0
- package/lib/service/Operations.d.ts +8 -0
- package/lib/service/Operations.js +26 -0
- package/lib/service/Profiler.d.ts +33 -0
- package/lib/service/Profiler.js +76 -0
- package/lib/service/Project.d.ts +173 -0
- package/lib/service/Project.js +593 -0
- package/lib/service/Service.d.ts +55 -0
- package/lib/service/Service.js +207 -0
- package/lib/service/SymbolLocations.d.ts +17 -0
- package/lib/service/SymbolLocations.js +16 -0
- package/lib/service/SymbolRegistrar.d.ts +5 -0
- package/lib/service/SymbolRegistrar.js +3 -0
- package/lib/service/fileUtil.d.ts +121 -0
- package/lib/service/fileUtil.js +268 -0
- package/lib/service/index.d.ts +18 -0
- package/lib/service/index.js +33 -0
- package/lib/source/IndexMap.d.ts +16 -0
- package/lib/source/IndexMap.js +46 -0
- package/lib/source/LanguageError.d.ts +27 -0
- package/lib/source/LanguageError.js +15 -0
- package/lib/source/Location.d.ts +19 -0
- package/lib/source/Location.js +25 -0
- package/lib/source/Offset.d.ts +13 -0
- package/lib/source/Offset.js +25 -0
- package/lib/source/Position.d.ts +23 -0
- package/lib/source/Position.js +43 -0
- package/lib/source/PositionRange.d.ts +38 -0
- package/lib/source/PositionRange.js +83 -0
- package/lib/source/Range.d.ts +68 -0
- package/lib/source/Range.js +155 -0
- package/lib/source/Source.d.ts +110 -0
- package/lib/source/Source.js +222 -0
- package/lib/source/index.d.ts +9 -0
- package/lib/source/index.js +21 -0
- package/lib/symbol/Symbol.d.ts +219 -0
- package/lib/symbol/Symbol.js +324 -0
- package/lib/symbol/SymbolUtil.d.ts +407 -0
- package/lib/symbol/SymbolUtil.js +880 -0
- package/lib/symbol/UriBinder.d.ts +3 -0
- package/lib/symbol/UriBinder.js +3 -0
- package/lib/symbol/index.d.ts +4 -0
- package/lib/symbol/index.js +16 -0
- package/package.json +41 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
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 _MetaRegistry_languages, _MetaRegistry_checkers, _MetaRegistry_colorizers, _MetaRegistry_completers, _MetaRegistry_dependencyProviders, _MetaRegistry_formatters, _MetaRegistry_inlayHintProviders, _MetaRegistry_linters, _MetaRegistry_parsers, _MetaRegistry_signatureHelpProviders, _MetaRegistry_symbolRegistrars, _MetaRegistry_uriBinders;
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.MetaRegistry = void 0;
|
|
10
|
+
const common_1 = require("../common");
|
|
11
|
+
const processor_1 = require("../processor");
|
|
12
|
+
/* istanbul ignore next */
|
|
13
|
+
/**
|
|
14
|
+
* The meta registry of Spyglass. You can register new parsers, processors, and languages here.
|
|
15
|
+
*/
|
|
16
|
+
class MetaRegistry {
|
|
17
|
+
constructor() {
|
|
18
|
+
/**
|
|
19
|
+
* A map from language IDs to language options.
|
|
20
|
+
*/
|
|
21
|
+
_MetaRegistry_languages.set(this, new Map());
|
|
22
|
+
_MetaRegistry_checkers.set(this, new Map());
|
|
23
|
+
_MetaRegistry_colorizers.set(this, new Map());
|
|
24
|
+
_MetaRegistry_completers.set(this, new Map());
|
|
25
|
+
_MetaRegistry_dependencyProviders.set(this, new Map());
|
|
26
|
+
_MetaRegistry_formatters.set(this, new Map());
|
|
27
|
+
_MetaRegistry_inlayHintProviders.set(this, new Set());
|
|
28
|
+
_MetaRegistry_linters.set(this, new Map());
|
|
29
|
+
_MetaRegistry_parsers.set(this, new Map());
|
|
30
|
+
_MetaRegistry_signatureHelpProviders.set(this, new Set());
|
|
31
|
+
_MetaRegistry_symbolRegistrars.set(this, new Map());
|
|
32
|
+
_MetaRegistry_uriBinders.set(this, new Set());
|
|
33
|
+
processor_1.checker.registerCheckers(this);
|
|
34
|
+
processor_1.colorizer.registerColorizers(this);
|
|
35
|
+
processor_1.completer.registerCompleters(this);
|
|
36
|
+
processor_1.formatter.registerFormatters(this);
|
|
37
|
+
processor_1.linter.registerLinters(this);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Registers a new language.
|
|
41
|
+
* @param languageID The language ID. e.g. `"mcfunction"`
|
|
42
|
+
* @param options The language options for this language.
|
|
43
|
+
*/
|
|
44
|
+
registerLanguage(languageID, options) {
|
|
45
|
+
__classPrivateFieldGet(this, _MetaRegistry_languages, "f").set(languageID, options);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* An array of all registered language IDs.
|
|
49
|
+
*/
|
|
50
|
+
getLanguages() {
|
|
51
|
+
return Array.from(__classPrivateFieldGet(this, _MetaRegistry_languages, "f").keys());
|
|
52
|
+
}
|
|
53
|
+
isSupportedLanguage(language) {
|
|
54
|
+
return __classPrivateFieldGet(this, _MetaRegistry_languages, "f").has(language);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* An array of file extensions (including the leading dot (`.`)) that are supported.
|
|
58
|
+
*/
|
|
59
|
+
getSupportedFileExtensions() {
|
|
60
|
+
return [...__classPrivateFieldGet(this, _MetaRegistry_languages, "f").values()].flatMap(v => v.extensions);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* An array of characters that trigger a completion request.
|
|
64
|
+
*/
|
|
65
|
+
getTriggerCharacters() {
|
|
66
|
+
return Array.from(__classPrivateFieldGet(this, _MetaRegistry_languages, "f").values()).flatMap(v => v.triggerCharacters ?? []);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @param fileExtension The file extension including the leading dot. e.g. `".mcfunction"`.
|
|
70
|
+
* @returns The language ID registered for the file extension, or `undefined`.
|
|
71
|
+
*/
|
|
72
|
+
getLanguageID(fileExtension) {
|
|
73
|
+
for (const [languageID, { extensions }] of __classPrivateFieldGet(this, _MetaRegistry_languages, "f")) {
|
|
74
|
+
if (extensions.includes(fileExtension)) {
|
|
75
|
+
return languageID;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
hasChecker(type) {
|
|
81
|
+
return __classPrivateFieldGet(this, _MetaRegistry_checkers, "f").has(type);
|
|
82
|
+
}
|
|
83
|
+
getChecker(type) {
|
|
84
|
+
return __classPrivateFieldGet(this, _MetaRegistry_checkers, "f").get(type) ?? processor_1.checker.fallback;
|
|
85
|
+
}
|
|
86
|
+
registerChecker(type, checker) {
|
|
87
|
+
__classPrivateFieldGet(this, _MetaRegistry_checkers, "f").set(type, checker);
|
|
88
|
+
}
|
|
89
|
+
hasColorizer(type) {
|
|
90
|
+
return __classPrivateFieldGet(this, _MetaRegistry_colorizers, "f").has(type);
|
|
91
|
+
}
|
|
92
|
+
getColorizer(type) {
|
|
93
|
+
return __classPrivateFieldGet(this, _MetaRegistry_colorizers, "f").get(type) ?? processor_1.colorizer.fallback;
|
|
94
|
+
}
|
|
95
|
+
registerColorizer(type, colorizer) {
|
|
96
|
+
__classPrivateFieldGet(this, _MetaRegistry_colorizers, "f").set(type, colorizer);
|
|
97
|
+
}
|
|
98
|
+
hasCompleter(type) {
|
|
99
|
+
return __classPrivateFieldGet(this, _MetaRegistry_completers, "f").has(type);
|
|
100
|
+
}
|
|
101
|
+
getCompleter(type) {
|
|
102
|
+
return __classPrivateFieldGet(this, _MetaRegistry_completers, "f").get(type) ?? processor_1.completer.fallback;
|
|
103
|
+
}
|
|
104
|
+
registerCompleter(type, completer) {
|
|
105
|
+
__classPrivateFieldGet(this, _MetaRegistry_completers, "f").set(type, completer);
|
|
106
|
+
}
|
|
107
|
+
shouldComplete(languageID, triggerCharacter) {
|
|
108
|
+
const language = __classPrivateFieldGet(this, _MetaRegistry_languages, "f").get(languageID);
|
|
109
|
+
return !triggerCharacter || !!language?.triggerCharacters?.includes(triggerCharacter);
|
|
110
|
+
}
|
|
111
|
+
getCompleterForLanguageID(languageID) {
|
|
112
|
+
return __classPrivateFieldGet(this, _MetaRegistry_languages, "f").get(languageID)?.completer ?? processor_1.completer.fallback;
|
|
113
|
+
}
|
|
114
|
+
getDependencyProvider(key) {
|
|
115
|
+
return __classPrivateFieldGet(this, _MetaRegistry_dependencyProviders, "f").get(key);
|
|
116
|
+
}
|
|
117
|
+
registerDependencyProvider(key, provider) {
|
|
118
|
+
__classPrivateFieldGet(this, _MetaRegistry_dependencyProviders, "f").set(key, provider);
|
|
119
|
+
}
|
|
120
|
+
hasFormatter(type) {
|
|
121
|
+
return __classPrivateFieldGet(this, _MetaRegistry_formatters, "f").has(type);
|
|
122
|
+
}
|
|
123
|
+
getFormatter(type) {
|
|
124
|
+
return __classPrivateFieldGet(this, _MetaRegistry_formatters, "f").get(type) ?? processor_1.formatter.fallback;
|
|
125
|
+
}
|
|
126
|
+
registerFormatter(type, formatter) {
|
|
127
|
+
__classPrivateFieldGet(this, _MetaRegistry_formatters, "f").set(type, formatter);
|
|
128
|
+
}
|
|
129
|
+
registerInlayHintProvider(provider) {
|
|
130
|
+
__classPrivateFieldGet(this, _MetaRegistry_inlayHintProviders, "f").add(provider);
|
|
131
|
+
}
|
|
132
|
+
get inlayHintProviders() {
|
|
133
|
+
return __classPrivateFieldGet(this, _MetaRegistry_inlayHintProviders, "f");
|
|
134
|
+
}
|
|
135
|
+
getLinter(ruleName) {
|
|
136
|
+
return __classPrivateFieldGet(this, _MetaRegistry_linters, "f").get(ruleName) ?? {
|
|
137
|
+
configValidator: () => false,
|
|
138
|
+
linter: processor_1.linter.noop,
|
|
139
|
+
nodePredicate: () => false,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
registerLinter(ruleName, options) {
|
|
143
|
+
__classPrivateFieldGet(this, _MetaRegistry_linters, "f").set(ruleName, options);
|
|
144
|
+
}
|
|
145
|
+
hasParser(id) {
|
|
146
|
+
return __classPrivateFieldGet(this, _MetaRegistry_parsers, "f").has(id);
|
|
147
|
+
}
|
|
148
|
+
getParser(id) {
|
|
149
|
+
const ans = __classPrivateFieldGet(this, _MetaRegistry_parsers, "f").get(id);
|
|
150
|
+
if (!ans) {
|
|
151
|
+
throw new Error(`There is no parser '${id}'`);
|
|
152
|
+
}
|
|
153
|
+
return ans;
|
|
154
|
+
}
|
|
155
|
+
getParserLazily(id) {
|
|
156
|
+
return common_1.Lazy.create(() => this.getParser(id));
|
|
157
|
+
}
|
|
158
|
+
registerParser(id, parser) {
|
|
159
|
+
__classPrivateFieldGet(this, _MetaRegistry_parsers, "f").set(id, parser);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* @returns The corresponding `Parser` for the language ID.
|
|
163
|
+
* @throws If there's no such language in the registry.
|
|
164
|
+
*/
|
|
165
|
+
getParserForLanguageId(languageID) {
|
|
166
|
+
if (__classPrivateFieldGet(this, _MetaRegistry_languages, "f").has(languageID)) {
|
|
167
|
+
return __classPrivateFieldGet(this, _MetaRegistry_languages, "f").get(languageID).parser;
|
|
168
|
+
}
|
|
169
|
+
throw new Error(`There is no parser registered for language ID '${languageID}'`);
|
|
170
|
+
}
|
|
171
|
+
registerSignatureHelpProvider(provider) {
|
|
172
|
+
__classPrivateFieldGet(this, _MetaRegistry_signatureHelpProviders, "f").add(provider);
|
|
173
|
+
}
|
|
174
|
+
get signatureHelpProviders() {
|
|
175
|
+
return __classPrivateFieldGet(this, _MetaRegistry_signatureHelpProviders, "f");
|
|
176
|
+
}
|
|
177
|
+
registerSymbolRegistrar(id, registrar) {
|
|
178
|
+
__classPrivateFieldGet(this, _MetaRegistry_symbolRegistrars, "f").set(id, registrar);
|
|
179
|
+
}
|
|
180
|
+
get symbolRegistrars() {
|
|
181
|
+
return __classPrivateFieldGet(this, _MetaRegistry_symbolRegistrars, "f");
|
|
182
|
+
}
|
|
183
|
+
registerUriBinder(uriBinder) {
|
|
184
|
+
__classPrivateFieldGet(this, _MetaRegistry_uriBinders, "f").add(uriBinder);
|
|
185
|
+
}
|
|
186
|
+
get uriBinders() {
|
|
187
|
+
return __classPrivateFieldGet(this, _MetaRegistry_uriBinders, "f");
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
exports.MetaRegistry = MetaRegistry;
|
|
191
|
+
_MetaRegistry_languages = new WeakMap(), _MetaRegistry_checkers = new WeakMap(), _MetaRegistry_colorizers = new WeakMap(), _MetaRegistry_completers = new WeakMap(), _MetaRegistry_dependencyProviders = new WeakMap(), _MetaRegistry_formatters = new WeakMap(), _MetaRegistry_inlayHintProviders = new WeakMap(), _MetaRegistry_linters = new WeakMap(), _MetaRegistry_parsers = new WeakMap(), _MetaRegistry_signatureHelpProviders = new WeakMap(), _MetaRegistry_symbolRegistrars = new WeakMap(), _MetaRegistry_uriBinders = new WeakMap();
|
|
192
|
+
//# sourceMappingURL=MetaRegistry.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Operations = void 0;
|
|
4
|
+
class Operations {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.undoOps = [];
|
|
7
|
+
this.redoOps = [];
|
|
8
|
+
}
|
|
9
|
+
set(obj, key, value) {
|
|
10
|
+
const oldValue = obj[key];
|
|
11
|
+
const op = () => { obj[key] = value; };
|
|
12
|
+
this.redoOps.push(op);
|
|
13
|
+
this.undoOps.push(() => { obj[key] = oldValue; });
|
|
14
|
+
op();
|
|
15
|
+
}
|
|
16
|
+
undo() {
|
|
17
|
+
for (let i = this.undoOps.length - 1; i >= 0; i--) {
|
|
18
|
+
this.undoOps[i]();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
redo() {
|
|
22
|
+
this.redoOps.forEach(f => f());
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.Operations = Operations;
|
|
26
|
+
//# sourceMappingURL=Operations.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Logger } from './Logger';
|
|
2
|
+
/**
|
|
3
|
+
* @example
|
|
4
|
+
* ```typescript
|
|
5
|
+
* const __profiler = profilerFactory.get('id')
|
|
6
|
+
*
|
|
7
|
+
* // Do Task 1 here
|
|
8
|
+
* // ...
|
|
9
|
+
* __profiler.task('Task 1')
|
|
10
|
+
*
|
|
11
|
+
* // Do Task 2 here
|
|
12
|
+
* // ...
|
|
13
|
+
* __profiler.task('Task 2').finalize()
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export interface Profiler {
|
|
17
|
+
/**
|
|
18
|
+
* Call after a task has been finished.
|
|
19
|
+
*/
|
|
20
|
+
task(name: string): this;
|
|
21
|
+
/**
|
|
22
|
+
* Call after the whole procedure that is being profiled is done.
|
|
23
|
+
*/
|
|
24
|
+
finalize(): void;
|
|
25
|
+
}
|
|
26
|
+
export declare class ProfilerFactory {
|
|
27
|
+
#private;
|
|
28
|
+
private readonly logger;
|
|
29
|
+
constructor(logger: Logger, enabledProfilers: string[]);
|
|
30
|
+
get(id: string): Profiler;
|
|
31
|
+
static noop(): ProfilerFactory;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=Profiler.d.ts.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
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");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
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");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _ProfilerImpl_finalized, _ProfilerImpl_startTime, _ProfilerImpl_lastTime, _ProfilerImpl_tasks, _ProfilerImpl_longestTaskNameLength, _ProfilerFactory_enabledProfilers;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ProfilerFactory = void 0;
|
|
16
|
+
const perf_hooks_1 = require("perf_hooks");
|
|
17
|
+
const Logger_1 = require("./Logger");
|
|
18
|
+
const TotalTaskName = 'Total';
|
|
19
|
+
class ProfilerImpl {
|
|
20
|
+
constructor(id, logger) {
|
|
21
|
+
this.id = id;
|
|
22
|
+
this.logger = logger;
|
|
23
|
+
_ProfilerImpl_finalized.set(this, false);
|
|
24
|
+
_ProfilerImpl_startTime.set(this, void 0);
|
|
25
|
+
_ProfilerImpl_lastTime.set(this, void 0);
|
|
26
|
+
_ProfilerImpl_tasks.set(this, []);
|
|
27
|
+
_ProfilerImpl_longestTaskNameLength.set(this, 0);
|
|
28
|
+
__classPrivateFieldSet(this, _ProfilerImpl_startTime, __classPrivateFieldSet(this, _ProfilerImpl_lastTime, perf_hooks_1.performance.now(), "f"), "f");
|
|
29
|
+
}
|
|
30
|
+
task(name) {
|
|
31
|
+
if (__classPrivateFieldGet(this, _ProfilerImpl_finalized, "f")) {
|
|
32
|
+
throw new Error('The profiler is finalized.');
|
|
33
|
+
}
|
|
34
|
+
const time = perf_hooks_1.performance.now();
|
|
35
|
+
__classPrivateFieldGet(this, _ProfilerImpl_tasks, "f").push([name, time - __classPrivateFieldGet(this, _ProfilerImpl_lastTime, "f")]);
|
|
36
|
+
__classPrivateFieldSet(this, _ProfilerImpl_lastTime, time, "f");
|
|
37
|
+
__classPrivateFieldSet(this, _ProfilerImpl_longestTaskNameLength, Math.max(__classPrivateFieldGet(this, _ProfilerImpl_longestTaskNameLength, "f"), name.length), "f");
|
|
38
|
+
this.logger.info(`[Profiler: ${this.id}] Done: ${name}`);
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
finalize() {
|
|
42
|
+
__classPrivateFieldSet(this, _ProfilerImpl_finalized, true, "f");
|
|
43
|
+
__classPrivateFieldGet(this, _ProfilerImpl_tasks, "f").push([TotalTaskName, __classPrivateFieldGet(this, _ProfilerImpl_lastTime, "f") - __classPrivateFieldGet(this, _ProfilerImpl_startTime, "f")]);
|
|
44
|
+
__classPrivateFieldSet(this, _ProfilerImpl_longestTaskNameLength, Math.max(__classPrivateFieldGet(this, _ProfilerImpl_longestTaskNameLength, "f"), TotalTaskName.length), "f");
|
|
45
|
+
this.logger.info(`[Profiler: ${this.id}] == Summary ==`);
|
|
46
|
+
for (const [name, time] of __classPrivateFieldGet(this, _ProfilerImpl_tasks, "f")) {
|
|
47
|
+
this.logger.info(`[Profiler: ${this.id}] ${name}${' '.repeat(__classPrivateFieldGet(this, _ProfilerImpl_longestTaskNameLength, "f") - name.length)} - ${time} ms`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
_ProfilerImpl_finalized = new WeakMap(), _ProfilerImpl_startTime = new WeakMap(), _ProfilerImpl_lastTime = new WeakMap(), _ProfilerImpl_tasks = new WeakMap(), _ProfilerImpl_longestTaskNameLength = new WeakMap();
|
|
52
|
+
class NoopImpl {
|
|
53
|
+
task() { return this; }
|
|
54
|
+
finalize() { }
|
|
55
|
+
}
|
|
56
|
+
class ProfilerFactory {
|
|
57
|
+
constructor(logger, enabledProfilers) {
|
|
58
|
+
this.logger = logger;
|
|
59
|
+
_ProfilerFactory_enabledProfilers.set(this, void 0);
|
|
60
|
+
__classPrivateFieldSet(this, _ProfilerFactory_enabledProfilers, new Set(enabledProfilers), "f");
|
|
61
|
+
}
|
|
62
|
+
get(id) {
|
|
63
|
+
if (__classPrivateFieldGet(this, _ProfilerFactory_enabledProfilers, "f").has(id)) {
|
|
64
|
+
return new ProfilerImpl(id, this.logger);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
return new NoopImpl();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
static noop() {
|
|
71
|
+
return new ProfilerFactory(Logger_1.Logger.noop(), []);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.ProfilerFactory = ProfilerFactory;
|
|
75
|
+
_ProfilerFactory_enabledProfilers = new WeakMap();
|
|
76
|
+
//# sourceMappingURL=Profiler.js.map
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import EventEmitter from 'events';
|
|
3
|
+
import type { TextDocumentContentChangeEvent } from 'vscode-languageserver-textdocument';
|
|
4
|
+
import { TextDocument } from 'vscode-languageserver-textdocument';
|
|
5
|
+
import type { AstNode } from '../node';
|
|
6
|
+
import { FileNode } from '../node';
|
|
7
|
+
import type { LanguageError } from '../source';
|
|
8
|
+
import { SymbolUtil } from '../symbol';
|
|
9
|
+
import { CacheService } from './CacheService';
|
|
10
|
+
import type { Config } from './Config';
|
|
11
|
+
import { Downloader } from './Downloader';
|
|
12
|
+
import { FileService } from './FileService';
|
|
13
|
+
import type { RootUriString } from './fileUtil';
|
|
14
|
+
import { Logger } from './Logger';
|
|
15
|
+
import { MetaRegistry } from './MetaRegistry';
|
|
16
|
+
import { ProfilerFactory } from './Profiler';
|
|
17
|
+
export declare type ProjectInitializerContext = Pick<Project, 'cacheRoot' | 'config' | 'downloader' | 'logger' | 'meta' | 'projectRoot'>;
|
|
18
|
+
export declare type ProjectInitializer = (this: void, ctx: ProjectInitializerContext) => PromiseLike<Record<string, string> | void> | Record<string, string> | void;
|
|
19
|
+
interface Options {
|
|
20
|
+
cacheRoot: string;
|
|
21
|
+
downloader?: Downloader;
|
|
22
|
+
fs?: FileService;
|
|
23
|
+
initializers?: readonly ProjectInitializer[];
|
|
24
|
+
logger?: Logger;
|
|
25
|
+
profilers?: ProfilerFactory;
|
|
26
|
+
/**
|
|
27
|
+
* A file path to the root of this project.
|
|
28
|
+
*/
|
|
29
|
+
projectPath: string;
|
|
30
|
+
symbols?: SymbolUtil;
|
|
31
|
+
}
|
|
32
|
+
export interface DocAndNode {
|
|
33
|
+
doc: TextDocument;
|
|
34
|
+
node: FileNode<AstNode>;
|
|
35
|
+
}
|
|
36
|
+
interface DocumentEvent extends DocAndNode {
|
|
37
|
+
}
|
|
38
|
+
interface DocumentErrorEvent extends DocumentEvent {
|
|
39
|
+
errors: LanguageError[];
|
|
40
|
+
}
|
|
41
|
+
interface FileEvent {
|
|
42
|
+
uri: string;
|
|
43
|
+
}
|
|
44
|
+
interface EmptyEvent {
|
|
45
|
+
}
|
|
46
|
+
interface RootsEvent {
|
|
47
|
+
roots: readonly RootUriString[];
|
|
48
|
+
}
|
|
49
|
+
interface SymbolRegistrarEvent {
|
|
50
|
+
id: string;
|
|
51
|
+
checksum: string | undefined;
|
|
52
|
+
}
|
|
53
|
+
export declare type ProjectData = Pick<Project, 'cacheRoot' | 'config' | 'downloader' | 'ensureParsedAndChecked' | 'fs' | 'get' | 'logger' | 'meta' | 'profilers' | 'projectRoot' | 'roots' | 'symbols' | 'ctx'>;
|
|
54
|
+
export declare namespace ProjectData {
|
|
55
|
+
function mock(data?: Partial<ProjectData>): ProjectData;
|
|
56
|
+
}
|
|
57
|
+
export interface Project extends EventEmitter {
|
|
58
|
+
on(event: 'documentErrorred', callbackFn: (data: DocumentErrorEvent) => void): this;
|
|
59
|
+
on(event: 'documentUpdated', callbackFn: (data: DocumentEvent) => void): this;
|
|
60
|
+
on(event: 'documentRemoved', callbackFn: (data: FileEvent) => void): this;
|
|
61
|
+
on(event: `file${'Created' | 'Modified' | 'Deleted'}`, callbackFn: (data: FileEvent) => void): this;
|
|
62
|
+
on(event: 'ready', callbackFn: (data: EmptyEvent) => void): this;
|
|
63
|
+
on(event: 'rootsUpdated', callbackFn: (data: RootsEvent) => void): this;
|
|
64
|
+
on(event: 'symbolRegistrarExecuted', callbackFn: (data: SymbolRegistrarEvent) => void): this;
|
|
65
|
+
once(event: 'documentErrorred', callbackFn: (data: DocumentErrorEvent) => void): this;
|
|
66
|
+
once(event: 'documentUpdated', callbackFn: (data: DocumentEvent) => void): this;
|
|
67
|
+
once(event: 'documentRemoved', callbackFn: (data: FileEvent) => void): this;
|
|
68
|
+
once(event: `file${'Created' | 'Modified' | 'Deleted'}`, callbackFn: (data: FileEvent) => void): this;
|
|
69
|
+
once(event: 'ready', callbackFn: (data: EmptyEvent) => void): this;
|
|
70
|
+
once(event: 'rootsUpdated', callbackFn: (data: RootsEvent) => void): this;
|
|
71
|
+
once(event: 'symbolRegistrarExecuted', callbackFn: (data: SymbolRegistrarEvent) => void): this;
|
|
72
|
+
emit(event: 'documentErrorred', data: DocumentErrorEvent): boolean;
|
|
73
|
+
emit(event: 'documentUpdated', data: DocumentEvent): boolean;
|
|
74
|
+
emit(event: 'documentRemoved', data: FileEvent): boolean;
|
|
75
|
+
emit(event: `file${'Created' | 'Modified' | 'Deleted'}`, data: FileEvent): boolean;
|
|
76
|
+
emit(event: 'ready', data: EmptyEvent): boolean;
|
|
77
|
+
emit(event: 'rootsUpdated', data: RootsEvent): boolean;
|
|
78
|
+
emit(event: 'symbolRegistrarExecuted', data: SymbolRegistrarEvent): boolean;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Manage all tracked documents and errors.
|
|
82
|
+
*/
|
|
83
|
+
export declare class Project extends EventEmitter {
|
|
84
|
+
#private;
|
|
85
|
+
private static readonly RootSuffix;
|
|
86
|
+
readonly cacheService: CacheService;
|
|
87
|
+
config: Config;
|
|
88
|
+
readonly downloader: Downloader;
|
|
89
|
+
readonly fs: FileService;
|
|
90
|
+
readonly logger: Logger;
|
|
91
|
+
readonly meta: MetaRegistry;
|
|
92
|
+
readonly profilers: ProfilerFactory;
|
|
93
|
+
readonly projectPath: string;
|
|
94
|
+
readonly projectRoot: RootUriString;
|
|
95
|
+
symbols: SymbolUtil;
|
|
96
|
+
/**
|
|
97
|
+
* All tracked root URIs. Each URI in this array is guaranteed to end with a slash (`/`).
|
|
98
|
+
*
|
|
99
|
+
* Includes the roots of all dependencies, the project root, and all data pack roots identified
|
|
100
|
+
* by `pack.mcmeta` files.
|
|
101
|
+
*
|
|
102
|
+
* Some URIs in the array may overlap with each other. In such cases, the deeper ones are guaranteed to come
|
|
103
|
+
* before the shallower ones (e.g. `file:///foo/bar/` will come before `file:///foo/`).
|
|
104
|
+
*/
|
|
105
|
+
get roots(): readonly RootUriString[];
|
|
106
|
+
/**
|
|
107
|
+
* Arbitrary information that will be included in the `project` property of all `Context`s.
|
|
108
|
+
*/
|
|
109
|
+
get ctx(): Record<string, string>;
|
|
110
|
+
/**
|
|
111
|
+
* File path to a directory where all cache files of Spyglass should be stored.
|
|
112
|
+
*/
|
|
113
|
+
get cacheRoot(): string;
|
|
114
|
+
private updateRoots;
|
|
115
|
+
/**
|
|
116
|
+
* Get all files that are tracked and supported.
|
|
117
|
+
*
|
|
118
|
+
* Files in cached archives may not show up in the result as those files
|
|
119
|
+
* are not loaded into the memory.
|
|
120
|
+
*/
|
|
121
|
+
getTrackedFiles(): string[];
|
|
122
|
+
constructor({ cacheRoot, downloader, fs, initializers, logger, profilers, projectPath, }: Options);
|
|
123
|
+
private setInitPromise;
|
|
124
|
+
private setReadyPromise;
|
|
125
|
+
init(): Promise<this>;
|
|
126
|
+
ready(): Promise<this>;
|
|
127
|
+
/**
|
|
128
|
+
* Behavior of the `Project` instance is undefined after this function has settled.
|
|
129
|
+
*/
|
|
130
|
+
close(): Promise<void>;
|
|
131
|
+
restart(): Promise<void>;
|
|
132
|
+
resetCache(): void;
|
|
133
|
+
/**
|
|
134
|
+
* @returns The language ID of the file, or the file extension without the leading dot.
|
|
135
|
+
*/
|
|
136
|
+
private getLanguageID;
|
|
137
|
+
/**
|
|
138
|
+
* @returns The cached `TextDocument` and `AstNode` for the URI, or `undefined` when such data isn't available in cache.
|
|
139
|
+
*/
|
|
140
|
+
get(uri: string): DocAndNode | undefined;
|
|
141
|
+
/**
|
|
142
|
+
* @throws FS-related errors
|
|
143
|
+
*/
|
|
144
|
+
ensureParsed(uri: string): Promise<DocAndNode | undefined>;
|
|
145
|
+
private parseAndCache;
|
|
146
|
+
private parse;
|
|
147
|
+
private cache;
|
|
148
|
+
private check;
|
|
149
|
+
ensureChecked(doc: TextDocument, node: FileNode<AstNode>): Promise<void>;
|
|
150
|
+
private lint;
|
|
151
|
+
ensureLinted(doc: TextDocument, node: FileNode<AstNode>): void;
|
|
152
|
+
ensureParsedAndChecked(uri: string): Promise<DocAndNode | undefined>;
|
|
153
|
+
private bind;
|
|
154
|
+
/**
|
|
155
|
+
* Notify that a new document was opened in the editor.
|
|
156
|
+
*/
|
|
157
|
+
onDidOpen(uri: string, languageID: string, version: number, content: string): void;
|
|
158
|
+
/**
|
|
159
|
+
* Notify that an existing document was changed in the editor.
|
|
160
|
+
* @throws If there is no `TextDocument` corresponding to the URI.
|
|
161
|
+
*/
|
|
162
|
+
onDidChange(uri: string, changes: TextDocumentContentChangeEvent[], version: number): void;
|
|
163
|
+
/**
|
|
164
|
+
* Notify that an existing document was closed in the editor.
|
|
165
|
+
*/
|
|
166
|
+
onDidClose(uri: string): void;
|
|
167
|
+
showCacheRoot(): Promise<void>;
|
|
168
|
+
private tryClearingCache;
|
|
169
|
+
private shouldRemove;
|
|
170
|
+
private isOnlyWatched;
|
|
171
|
+
}
|
|
172
|
+
export {};
|
|
173
|
+
//# sourceMappingURL=Project.d.ts.map
|