@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
package/lib/service/Hover.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.Hover = void 0;
|
|
4
|
-
const source_1 = require("../source");
|
|
5
|
-
var Hover;
|
|
1
|
+
import { Range } from '../source/index.js';
|
|
2
|
+
export var Hover;
|
|
6
3
|
(function (Hover) {
|
|
7
4
|
/* istanbul ignore next */
|
|
8
5
|
function create(range, markdown) {
|
|
9
6
|
return {
|
|
10
|
-
range:
|
|
7
|
+
range: Range.get(range),
|
|
11
8
|
markdown,
|
|
12
9
|
};
|
|
13
10
|
}
|
|
14
11
|
Hover.create = create;
|
|
15
|
-
})(Hover
|
|
12
|
+
})(Hover || (Hover = {}));
|
|
16
13
|
//# sourceMappingURL=Hover.js.map
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import type { Formatter } from '../processor/formatter';
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
9
|
-
import type { DependencyKey, DependencyProvider } from './Dependency';
|
|
10
|
-
import type { FileExtension } from './fileUtil';
|
|
11
|
-
import type {
|
|
12
|
-
import type {
|
|
1
|
+
import type { Logger } from '../common/index.js';
|
|
2
|
+
import { Lazy } from '../common/index.js';
|
|
3
|
+
import type { AstNode } from '../node/index.js';
|
|
4
|
+
import type { Parser } from '../parser/index.js';
|
|
5
|
+
import type { Formatter } from '../processor/formatter/index.js';
|
|
6
|
+
import type { Binder, Checker, Colorizer, Completer, InlayHintProvider } from '../processor/index.js';
|
|
7
|
+
import type { Linter } from '../processor/linter/Linter.js';
|
|
8
|
+
import type { SignatureHelpProvider } from '../processor/SignatureHelpProvider.js';
|
|
9
|
+
import type { DependencyKey, DependencyProvider } from './Dependency.js';
|
|
10
|
+
import type { FileExtension } from './fileUtil.js';
|
|
11
|
+
import type { SymbolRegistrar } from './SymbolRegistrar.js';
|
|
12
|
+
import type { UriBinder, UriSorter, UriSorterRegistration } from './UriProcessor.js';
|
|
13
13
|
export interface LanguageOptions {
|
|
14
14
|
/**
|
|
15
15
|
* An array of extensions of files corresponding to the language. Each extension should include the leading dot (`.`).
|
|
@@ -26,6 +26,11 @@ interface LinterRegistration {
|
|
|
26
26
|
}
|
|
27
27
|
interface SymbolRegistrarRegistration {
|
|
28
28
|
registrar: SymbolRegistrar;
|
|
29
|
+
/**
|
|
30
|
+
* A checksum associated with this symbol registrar.
|
|
31
|
+
* If the cached checksum is equal to this provided checksum,
|
|
32
|
+
* the symbol registrar is not executed.
|
|
33
|
+
*/
|
|
29
34
|
checksum: string | undefined;
|
|
30
35
|
}
|
|
31
36
|
/**
|
|
@@ -58,6 +63,9 @@ export declare class MetaRegistry {
|
|
|
58
63
|
* @returns The language ID registered for the file extension, or `undefined`.
|
|
59
64
|
*/
|
|
60
65
|
getLanguageID(fileExtension: FileExtension): string | undefined;
|
|
66
|
+
hasBinder<N extends AstNode>(type: N['type']): boolean;
|
|
67
|
+
getBinder<N extends AstNode>(type: N['type']): Binder<N>;
|
|
68
|
+
registerBinder<N extends AstNode>(type: N['type'], binder: Binder<N>): void;
|
|
61
69
|
hasChecker<N extends AstNode>(type: N['type']): boolean;
|
|
62
70
|
getChecker<N extends AstNode>(type: N['type']): Checker<N>;
|
|
63
71
|
registerChecker<N extends AstNode>(type: N['type'], checker: Checker<N>): void;
|
|
@@ -101,6 +109,8 @@ export declare class MetaRegistry {
|
|
|
101
109
|
get symbolRegistrars(): Map<string, SymbolRegistrarRegistration>;
|
|
102
110
|
registerUriBinder(uriBinder: UriBinder): void;
|
|
103
111
|
get uriBinders(): Set<UriBinder>;
|
|
112
|
+
setUriSorter(uriSorter: UriSorterRegistration): void;
|
|
113
|
+
get uriSorter(): UriSorter;
|
|
104
114
|
}
|
|
105
115
|
export {};
|
|
106
116
|
//# sourceMappingURL=MetaRegistry.d.ts.map
|
|
@@ -1,40 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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");
|
|
1
|
+
import { Lazy } from '../common/index.js';
|
|
2
|
+
import { binder, checker, colorizer, completer, formatter, linter } from '../processor/index.js';
|
|
12
3
|
/* istanbul ignore next */
|
|
13
4
|
/**
|
|
14
5
|
* The meta registry of Spyglass. You can register new parsers, processors, and languages here.
|
|
15
6
|
*/
|
|
16
|
-
class MetaRegistry {
|
|
7
|
+
export class MetaRegistry {
|
|
8
|
+
/**
|
|
9
|
+
* A map from language IDs to language options.
|
|
10
|
+
*/
|
|
11
|
+
#languages = new Map();
|
|
12
|
+
#binders = new Map();
|
|
13
|
+
#checkers = new Map();
|
|
14
|
+
#colorizers = new Map();
|
|
15
|
+
#completers = new Map();
|
|
16
|
+
#dependencyProviders = new Map();
|
|
17
|
+
#formatters = new Map();
|
|
18
|
+
#inlayHintProviders = new Set();
|
|
19
|
+
#linters = new Map();
|
|
20
|
+
#parsers = new Map();
|
|
21
|
+
#signatureHelpProviders = new Set();
|
|
22
|
+
#symbolRegistrars = new Map();
|
|
23
|
+
#uriBinders = new Set();
|
|
24
|
+
#uriSorter = () => 0;
|
|
17
25
|
constructor() {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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);
|
|
26
|
+
binder.registerBinders(this);
|
|
27
|
+
checker.registerCheckers(this);
|
|
28
|
+
colorizer.registerColorizers(this);
|
|
29
|
+
completer.registerCompleters(this);
|
|
30
|
+
formatter.registerFormatters(this);
|
|
31
|
+
linter.registerLinters(this);
|
|
38
32
|
}
|
|
39
33
|
/**
|
|
40
34
|
* Registers a new language.
|
|
@@ -42,151 +36,165 @@ class MetaRegistry {
|
|
|
42
36
|
* @param options The language options for this language.
|
|
43
37
|
*/
|
|
44
38
|
registerLanguage(languageID, options) {
|
|
45
|
-
|
|
39
|
+
this.#languages.set(languageID, options);
|
|
46
40
|
}
|
|
47
41
|
/**
|
|
48
42
|
* An array of all registered language IDs.
|
|
49
43
|
*/
|
|
50
44
|
getLanguages() {
|
|
51
|
-
return Array.from(
|
|
45
|
+
return Array.from(this.#languages.keys());
|
|
52
46
|
}
|
|
53
47
|
isSupportedLanguage(language) {
|
|
54
|
-
return
|
|
48
|
+
return this.#languages.has(language);
|
|
55
49
|
}
|
|
56
50
|
/**
|
|
57
51
|
* An array of file extensions (including the leading dot (`.`)) that are supported.
|
|
58
52
|
*/
|
|
59
53
|
getSupportedFileExtensions() {
|
|
60
|
-
return [...
|
|
54
|
+
return [...this.#languages.values()].flatMap(v => v.extensions);
|
|
61
55
|
}
|
|
62
56
|
/**
|
|
63
57
|
* An array of characters that trigger a completion request.
|
|
64
58
|
*/
|
|
65
59
|
getTriggerCharacters() {
|
|
66
|
-
return Array.from(
|
|
60
|
+
return Array.from(this.#languages.values()).flatMap(v => v.triggerCharacters ?? []);
|
|
67
61
|
}
|
|
68
62
|
/**
|
|
69
63
|
* @param fileExtension The file extension including the leading dot. e.g. `".mcfunction"`.
|
|
70
64
|
* @returns The language ID registered for the file extension, or `undefined`.
|
|
71
65
|
*/
|
|
72
66
|
getLanguageID(fileExtension) {
|
|
73
|
-
for (const [languageID, { extensions }] of
|
|
67
|
+
for (const [languageID, { extensions }] of this.#languages) {
|
|
74
68
|
if (extensions.includes(fileExtension)) {
|
|
75
69
|
return languageID;
|
|
76
70
|
}
|
|
77
71
|
}
|
|
78
72
|
return undefined;
|
|
79
73
|
}
|
|
74
|
+
hasBinder(type) {
|
|
75
|
+
return this.#binders.has(type);
|
|
76
|
+
}
|
|
77
|
+
getBinder(type) {
|
|
78
|
+
return this.#binders.get(type) ?? binder.fallback;
|
|
79
|
+
}
|
|
80
|
+
registerBinder(type, binder) {
|
|
81
|
+
this.#binders.set(type, binder);
|
|
82
|
+
}
|
|
80
83
|
hasChecker(type) {
|
|
81
|
-
return
|
|
84
|
+
return this.#checkers.has(type);
|
|
82
85
|
}
|
|
83
86
|
getChecker(type) {
|
|
84
|
-
return
|
|
87
|
+
return this.#checkers.get(type) ?? checker.fallback;
|
|
85
88
|
}
|
|
86
89
|
registerChecker(type, checker) {
|
|
87
|
-
|
|
90
|
+
this.#checkers.set(type, checker);
|
|
88
91
|
}
|
|
89
92
|
hasColorizer(type) {
|
|
90
|
-
return
|
|
93
|
+
return this.#colorizers.has(type);
|
|
91
94
|
}
|
|
92
95
|
getColorizer(type) {
|
|
93
|
-
return
|
|
96
|
+
return this.#colorizers.get(type) ?? colorizer.fallback;
|
|
94
97
|
}
|
|
95
98
|
registerColorizer(type, colorizer) {
|
|
96
|
-
|
|
99
|
+
this.#colorizers.set(type, colorizer);
|
|
97
100
|
}
|
|
98
101
|
hasCompleter(type) {
|
|
99
|
-
return
|
|
102
|
+
return this.#completers.has(type);
|
|
100
103
|
}
|
|
101
104
|
getCompleter(type) {
|
|
102
|
-
return
|
|
105
|
+
return this.#completers.get(type) ?? completer.fallback;
|
|
103
106
|
}
|
|
104
107
|
registerCompleter(type, completer) {
|
|
105
|
-
|
|
108
|
+
this.#completers.set(type, completer);
|
|
106
109
|
}
|
|
107
110
|
shouldComplete(languageID, triggerCharacter) {
|
|
108
|
-
const language =
|
|
111
|
+
const language = this.#languages.get(languageID);
|
|
109
112
|
return !triggerCharacter || !!language?.triggerCharacters?.includes(triggerCharacter);
|
|
110
113
|
}
|
|
111
114
|
getCompleterForLanguageID(languageID) {
|
|
112
|
-
return
|
|
115
|
+
return this.#languages.get(languageID)?.completer ?? completer.fallback;
|
|
113
116
|
}
|
|
114
117
|
getDependencyProvider(key) {
|
|
115
|
-
return
|
|
118
|
+
return this.#dependencyProviders.get(key);
|
|
116
119
|
}
|
|
117
120
|
registerDependencyProvider(key, provider) {
|
|
118
|
-
|
|
121
|
+
this.#dependencyProviders.set(key, provider);
|
|
119
122
|
}
|
|
120
123
|
hasFormatter(type) {
|
|
121
|
-
return
|
|
124
|
+
return this.#formatters.has(type);
|
|
122
125
|
}
|
|
123
126
|
getFormatter(type) {
|
|
124
|
-
return
|
|
127
|
+
return this.#formatters.get(type) ?? formatter.fallback;
|
|
125
128
|
}
|
|
126
129
|
registerFormatter(type, formatter) {
|
|
127
|
-
|
|
130
|
+
this.#formatters.set(type, formatter);
|
|
128
131
|
}
|
|
129
132
|
registerInlayHintProvider(provider) {
|
|
130
|
-
|
|
133
|
+
this.#inlayHintProviders.add(provider);
|
|
131
134
|
}
|
|
132
135
|
get inlayHintProviders() {
|
|
133
|
-
return
|
|
136
|
+
return this.#inlayHintProviders;
|
|
134
137
|
}
|
|
135
138
|
getLinter(ruleName) {
|
|
136
|
-
return
|
|
139
|
+
return this.#linters.get(ruleName) ?? {
|
|
137
140
|
configValidator: () => false,
|
|
138
|
-
linter:
|
|
141
|
+
linter: linter.noop,
|
|
139
142
|
nodePredicate: () => false,
|
|
140
143
|
};
|
|
141
144
|
}
|
|
142
145
|
registerLinter(ruleName, options) {
|
|
143
|
-
|
|
146
|
+
this.#linters.set(ruleName, options);
|
|
144
147
|
}
|
|
145
148
|
hasParser(id) {
|
|
146
|
-
return
|
|
149
|
+
return this.#parsers.has(id);
|
|
147
150
|
}
|
|
148
151
|
getParser(id) {
|
|
149
|
-
const ans =
|
|
152
|
+
const ans = this.#parsers.get(id);
|
|
150
153
|
if (!ans) {
|
|
151
154
|
throw new Error(`There is no parser '${id}'`);
|
|
152
155
|
}
|
|
153
156
|
return ans;
|
|
154
157
|
}
|
|
155
158
|
getParserLazily(id) {
|
|
156
|
-
return
|
|
159
|
+
return Lazy.create(() => this.getParser(id));
|
|
157
160
|
}
|
|
158
161
|
registerParser(id, parser) {
|
|
159
|
-
|
|
162
|
+
this.#parsers.set(id, parser);
|
|
160
163
|
}
|
|
161
164
|
/**
|
|
162
165
|
* @returns The corresponding `Parser` for the language ID.
|
|
163
166
|
* @throws If there's no such language in the registry.
|
|
164
167
|
*/
|
|
165
168
|
getParserForLanguageId(languageID) {
|
|
166
|
-
if (
|
|
167
|
-
return
|
|
169
|
+
if (this.#languages.has(languageID)) {
|
|
170
|
+
return this.#languages.get(languageID).parser;
|
|
168
171
|
}
|
|
169
172
|
throw new Error(`There is no parser registered for language ID '${languageID}'`);
|
|
170
173
|
}
|
|
171
174
|
registerSignatureHelpProvider(provider) {
|
|
172
|
-
|
|
175
|
+
this.#signatureHelpProviders.add(provider);
|
|
173
176
|
}
|
|
174
177
|
get signatureHelpProviders() {
|
|
175
|
-
return
|
|
178
|
+
return this.#signatureHelpProviders;
|
|
176
179
|
}
|
|
177
180
|
registerSymbolRegistrar(id, registrar) {
|
|
178
|
-
|
|
181
|
+
this.#symbolRegistrars.set(id, registrar);
|
|
179
182
|
}
|
|
180
183
|
get symbolRegistrars() {
|
|
181
|
-
return
|
|
184
|
+
return this.#symbolRegistrars;
|
|
182
185
|
}
|
|
183
186
|
registerUriBinder(uriBinder) {
|
|
184
|
-
|
|
187
|
+
this.#uriBinders.add(uriBinder);
|
|
185
188
|
}
|
|
186
189
|
get uriBinders() {
|
|
187
|
-
return
|
|
190
|
+
return this.#uriBinders;
|
|
191
|
+
}
|
|
192
|
+
setUriSorter(uriSorter) {
|
|
193
|
+
const nextSorter = this.#uriSorter;
|
|
194
|
+
this.#uriSorter = (a, b) => uriSorter(a, b, nextSorter);
|
|
195
|
+
}
|
|
196
|
+
get uriSorter() {
|
|
197
|
+
return this.#uriSorter;
|
|
188
198
|
}
|
|
189
199
|
}
|
|
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
200
|
//# sourceMappingURL=MetaRegistry.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Logger } from '
|
|
1
|
+
import { Logger } from '../common/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* @example
|
|
4
4
|
* ```typescript
|
|
@@ -27,7 +27,8 @@ export declare class ProfilerFactory {
|
|
|
27
27
|
#private;
|
|
28
28
|
private readonly logger;
|
|
29
29
|
constructor(logger: Logger, enabledProfilers: string[]);
|
|
30
|
-
get(id: string): Profiler;
|
|
30
|
+
get(id: string, style: 'top-n', n: number): Profiler;
|
|
31
|
+
get(id: string, style?: 'total'): Profiler;
|
|
31
32
|
static noop(): ProfilerFactory;
|
|
32
33
|
}
|
|
33
34
|
//# sourceMappingURL=Profiler.d.ts.map
|
package/lib/service/Profiler.js
CHANGED
|
@@ -1,76 +1,112 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import { Dev, Logger } from '../common/index.js';
|
|
2
|
+
class TopNImpl {
|
|
3
|
+
id;
|
|
4
|
+
logger;
|
|
5
|
+
n;
|
|
6
|
+
#finalized = false;
|
|
7
|
+
#startTime;
|
|
8
|
+
#lastTime;
|
|
9
|
+
#taskCount = 0;
|
|
10
|
+
#topTasks = [];
|
|
11
|
+
#minTime = Infinity;
|
|
12
|
+
#maxTime = 0;
|
|
13
|
+
constructor(id, logger, n) {
|
|
14
|
+
this.id = id;
|
|
15
|
+
this.logger = logger;
|
|
16
|
+
this.n = n;
|
|
17
|
+
this.#startTime = this.#lastTime = performance.now();
|
|
18
|
+
}
|
|
19
|
+
task(name) {
|
|
20
|
+
if (this.#finalized) {
|
|
21
|
+
throw new Error('The profiler has already been finalized');
|
|
22
|
+
}
|
|
23
|
+
this.#taskCount++;
|
|
24
|
+
const time = performance.now();
|
|
25
|
+
const duration = time - this.#lastTime;
|
|
26
|
+
this.#lastTime = time;
|
|
27
|
+
this.#minTime = Math.min(this.#minTime, duration);
|
|
28
|
+
this.#maxTime = Math.max(this.#maxTime, duration);
|
|
29
|
+
this.#topTasks.push([name, duration]);
|
|
30
|
+
this.#topTasks.sort((a, b) => b[1] - a[1]);
|
|
31
|
+
if (this.#topTasks.length > this.n) {
|
|
32
|
+
this.#topTasks = this.#topTasks.slice(0, -1);
|
|
33
|
+
}
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
finalize() {
|
|
37
|
+
this.#finalized = true;
|
|
38
|
+
const longestTaskNameLength = this.#topTasks.reduce((length, [name]) => Math.max(length, name.length), 0);
|
|
39
|
+
const totalDuration = this.#lastTime - this.#startTime;
|
|
40
|
+
this.logger.info(`[Profiler: ${this.id}] == Summary ==`);
|
|
41
|
+
this.logger.info(`[Profiler: ${this.id}] Total tasks: ${this.#taskCount} done in ${totalDuration} ms`);
|
|
42
|
+
this.logger.info(`[Profiler: ${this.id}] Min/Avg/Max: ${this.#minTime} / ${totalDuration / this.#taskCount} / ${this.#maxTime} ms`);
|
|
43
|
+
this.logger.info(`[Profiler: ${this.id}] Top ${Math.min(this.n, this.#topTasks.length)} task(s):`);
|
|
44
|
+
for (const [name, time] of this.#topTasks) {
|
|
45
|
+
this.logger.info(`[Profiler: ${this.id}] ${name}${' '.repeat(longestTaskNameLength - name.length)} - ${time} ms (${time / totalDuration * 100}%)`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
18
49
|
const TotalTaskName = 'Total';
|
|
19
|
-
class
|
|
50
|
+
class TotalImpl {
|
|
51
|
+
id;
|
|
52
|
+
logger;
|
|
53
|
+
#finalized = false;
|
|
54
|
+
#startTime;
|
|
55
|
+
#lastTime;
|
|
56
|
+
#tasks = [];
|
|
57
|
+
#longestTaskNameLength = 0;
|
|
20
58
|
constructor(id, logger) {
|
|
21
59
|
this.id = id;
|
|
22
60
|
this.logger = logger;
|
|
23
|
-
|
|
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");
|
|
61
|
+
this.#startTime = this.#lastTime = performance.now();
|
|
29
62
|
}
|
|
30
63
|
task(name) {
|
|
31
|
-
if (
|
|
64
|
+
if (this.#finalized) {
|
|
32
65
|
throw new Error('The profiler is finalized.');
|
|
33
66
|
}
|
|
34
|
-
const time =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
this.
|
|
67
|
+
const time = performance.now();
|
|
68
|
+
const duration = time - this.#lastTime;
|
|
69
|
+
this.#lastTime = time;
|
|
70
|
+
this.#tasks.push([name, duration]);
|
|
71
|
+
this.#longestTaskNameLength = Math.max(this.#longestTaskNameLength, name.length);
|
|
72
|
+
this.logger.info(`[Profiler: ${this.id}] Done: ${name} in ${duration} ms`);
|
|
39
73
|
return this;
|
|
40
74
|
}
|
|
41
75
|
finalize() {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
76
|
+
this.#finalized = true;
|
|
77
|
+
this.#tasks.push([TotalTaskName, this.#lastTime - this.#startTime]);
|
|
78
|
+
this.#longestTaskNameLength = Math.max(this.#longestTaskNameLength, TotalTaskName.length);
|
|
45
79
|
this.logger.info(`[Profiler: ${this.id}] == Summary ==`);
|
|
46
|
-
for (const [name, time] of
|
|
47
|
-
this.logger.info(`[Profiler: ${this.id}] ${name}${' '.repeat(
|
|
80
|
+
for (const [name, time] of this.#tasks) {
|
|
81
|
+
this.logger.info(`[Profiler: ${this.id}] ${name}${' '.repeat(this.#longestTaskNameLength - name.length)} - ${time} ms`);
|
|
48
82
|
}
|
|
49
83
|
}
|
|
50
84
|
}
|
|
51
|
-
_ProfilerImpl_finalized = new WeakMap(), _ProfilerImpl_startTime = new WeakMap(), _ProfilerImpl_lastTime = new WeakMap(), _ProfilerImpl_tasks = new WeakMap(), _ProfilerImpl_longestTaskNameLength = new WeakMap();
|
|
52
85
|
class NoopImpl {
|
|
53
86
|
task() { return this; }
|
|
54
87
|
finalize() { }
|
|
55
88
|
}
|
|
56
|
-
class ProfilerFactory {
|
|
89
|
+
export class ProfilerFactory {
|
|
90
|
+
logger;
|
|
91
|
+
#enabledProfilers;
|
|
57
92
|
constructor(logger, enabledProfilers) {
|
|
58
93
|
this.logger = logger;
|
|
59
|
-
|
|
60
|
-
__classPrivateFieldSet(this, _ProfilerFactory_enabledProfilers, new Set(enabledProfilers), "f");
|
|
94
|
+
this.#enabledProfilers = new Set(enabledProfilers);
|
|
61
95
|
}
|
|
62
|
-
get(id) {
|
|
63
|
-
if (
|
|
64
|
-
|
|
96
|
+
get(id, style = 'total', n) {
|
|
97
|
+
if (this.#enabledProfilers.has(id)) {
|
|
98
|
+
switch (style) {
|
|
99
|
+
case 'top-n': return new TopNImpl(id, this.logger, n);
|
|
100
|
+
case 'total': return new TotalImpl(id, this.logger);
|
|
101
|
+
default: return Dev.assertNever(style);
|
|
102
|
+
}
|
|
65
103
|
}
|
|
66
104
|
else {
|
|
67
105
|
return new NoopImpl();
|
|
68
106
|
}
|
|
69
107
|
}
|
|
70
108
|
static noop() {
|
|
71
|
-
return new ProfilerFactory(
|
|
109
|
+
return new ProfilerFactory(Logger.noop(), []);
|
|
72
110
|
}
|
|
73
111
|
}
|
|
74
|
-
exports.ProfilerFactory = ProfilerFactory;
|
|
75
|
-
_ProfilerFactory_enabledProfilers = new WeakMap();
|
|
76
112
|
//# sourceMappingURL=Profiler.js.map
|