@spyglassmc/core 0.1.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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.d.ts +21 -0
- package/lib/common/TwoWayMap.js +69 -0
- package/lib/common/externals/BrowserExternals.d.ts +3 -0
- package/lib/common/externals/BrowserExternals.js +191 -0
- package/lib/common/externals/NodeJsExternals.d.ts +3 -0
- package/lib/common/externals/NodeJsExternals.js +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 -13
- package/lib/common/util.d.ts +50 -39
- package/lib/common/util.js +73 -122
- package/lib/index.d.ts +7 -7
- package/lib/index.js +7 -19
- 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 +5 -5
- package/lib/node/LiteralNode.js +5 -8
- 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 +8 -10
- package/lib/node/ResourceLocationNode.js +9 -12
- package/lib/node/Sequence.d.ts +4 -3
- package/lib/node/Sequence.js +4 -6
- package/lib/node/StringNode.d.ts +5 -5
- package/lib/node/StringNode.js +9 -12
- package/lib/node/SymbolNode.d.ts +5 -5
- package/lib/node/SymbolNode.js +5 -8
- package/lib/node/index.d.ts +15 -15
- package/lib/node/index.js +15 -27
- package/lib/nodejs.d.ts +2 -0
- package/lib/nodejs.js +2 -0
- package/lib/parser/Parser.d.ts +3 -3
- package/lib/parser/Parser.js +1 -4
- package/lib/parser/boolean.d.ts +2 -2
- package/lib/parser/boolean.js +3 -6
- package/lib/parser/comment.d.ts +2 -2
- package/lib/parser/comment.js +5 -9
- package/lib/parser/empty.d.ts +1 -1
- package/lib/parser/empty.js +1 -5
- package/lib/parser/error.d.ts +2 -2
- package/lib/parser/error.js +5 -9
- package/lib/parser/file.d.ts +3 -3
- package/lib/parser/file.js +9 -13
- package/lib/parser/float.d.ts +4 -4
- package/lib/parser/float.js +12 -16
- package/lib/parser/index.d.ts +16 -16
- package/lib/parser/index.js +16 -34
- package/lib/parser/integer.d.ts +4 -4
- package/lib/parser/integer.js +10 -14
- package/lib/parser/list.d.ts +2 -2
- package/lib/parser/list.js +15 -19
- package/lib/parser/literal.d.ts +2 -2
- package/lib/parser/literal.js +5 -9
- package/lib/parser/long.d.ts +4 -4
- package/lib/parser/long.js +10 -14
- package/lib/parser/record.d.ts +3 -3
- package/lib/parser/record.js +20 -24
- package/lib/parser/resourceLocation.d.ts +2 -2
- package/lib/parser/resourceLocation.js +12 -24
- package/lib/parser/string.d.ts +7 -7
- package/lib/parser/string.js +40 -44
- package/lib/parser/symbol.d.ts +3 -3
- package/lib/parser/symbol.js +4 -14
- package/lib/parser/util.d.ts +30 -12
- package/lib/parser/util.js +78 -65
- 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 -27
- 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 +33 -46
- package/lib/processor/colorizer/index.d.ts +2 -2
- package/lib/processor/colorizer/index.js +2 -27
- package/lib/processor/completer/Completer.d.ts +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 +59 -75
- package/lib/processor/completer/index.d.ts +2 -2
- package/lib/processor/completer/index.js +2 -27
- 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 -27
- package/lib/processor/index.d.ts +10 -9
- package/lib/processor/index.js +10 -21
- 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 +23 -27
- 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 -27
- package/lib/processor/util.d.ts +4 -14
- package/lib/processor/util.js +1 -16
- package/lib/service/CacheService.d.ts +8 -6
- package/lib/service/CacheService.js +35 -56
- package/lib/service/Config.d.ts +17 -16
- package/lib/service/Config.js +56 -51
- package/lib/service/Context.d.ts +24 -21
- package/lib/service/Context.js +40 -36
- package/lib/service/Dependency.js +2 -5
- package/lib/service/Downloader.d.ts +9 -39
- package/lib/service/Downloader.js +37 -106
- package/lib/service/ErrorReporter.d.ts +2 -2
- package/lib/service/ErrorReporter.js +11 -15
- package/lib/service/FileService.d.ts +40 -14
- package/lib/service/FileService.js +107 -81
- package/lib/service/Hover.d.ts +2 -2
- package/lib/service/Hover.js +4 -7
- package/lib/service/MetaRegistry.d.ts +17 -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 +101 -73
- package/lib/service/Project.js +438 -367
- package/lib/service/Service.d.ts +19 -29
- package/lib/service/Service.js +57 -53
- package/lib/service/SymbolLocations.d.ts +3 -3
- package/lib/service/SymbolLocations.js +4 -7
- package/lib/service/SymbolRegistrar.d.ts +1 -1
- package/lib/service/SymbolRegistrar.js +1 -2
- package/lib/service/UriProcessor.d.ts +5 -0
- package/lib/service/UriProcessor.js +2 -0
- package/lib/service/fileUtil.d.ts +21 -41
- package/lib/service/fileUtil.js +59 -129
- package/lib/service/index.d.ts +16 -17
- package/lib/service/index.js +16 -31
- package/lib/source/IndexMap.d.ts +1 -1
- package/lib/source/IndexMap.js +7 -10
- package/lib/source/LanguageError.d.ts +2 -2
- package/lib/source/LanguageError.js +3 -6
- package/lib/source/Location.d.ts +3 -3
- package/lib/source/Location.js +6 -9
- package/lib/source/Offset.d.ts +1 -1
- package/lib/source/Offset.js +4 -7
- package/lib/source/Position.js +2 -5
- package/lib/source/PositionRange.d.ts +2 -2
- package/lib/source/PositionRange.js +14 -17
- package/lib/source/Range.d.ts +1 -1
- package/lib/source/Range.js +7 -10
- package/lib/source/Source.d.ts +9 -4
- package/lib/source/Source.js +58 -31
- package/lib/source/index.d.ts +8 -8
- package/lib/source/index.js +8 -20
- package/lib/symbol/Symbol.d.ts +15 -14
- package/lib/symbol/Symbol.js +53 -68
- package/lib/symbol/SymbolUtil.d.ts +30 -39
- package/lib/symbol/SymbolUtil.js +189 -168
- package/lib/symbol/index.d.ts +2 -3
- package/lib/symbol/index.js +2 -15
- 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,47 +1,26 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* istanbul ignore file */
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (k2 === undefined) k2 = k;
|
|
8
|
-
o[k2] = m[k];
|
|
9
|
-
}));
|
|
10
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
11
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
12
|
-
}) : function(o, v) {
|
|
13
|
-
o["default"] = v;
|
|
14
|
-
});
|
|
15
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
16
|
-
if (mod && mod.__esModule) return mod;
|
|
17
|
-
var result = {};
|
|
18
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
19
|
-
__setModuleDefault(result, mod);
|
|
20
|
-
return result;
|
|
21
|
-
};
|
|
22
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
23
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.SpyglassUriSupporter = exports.FileUriSupporter = exports.FileServiceImpl = exports.FileService = void 0;
|
|
27
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
28
|
-
const decompress_1 = __importDefault(require("decompress"));
|
|
29
|
-
const fs_1 = __importStar(require("fs"));
|
|
30
|
-
const globby_1 = __importDefault(require("globby"));
|
|
31
|
-
const common_1 = require("../common");
|
|
32
|
-
const fileUtil_1 = require("./fileUtil");
|
|
33
|
-
const HashAlgorithm = 'sha1';
|
|
34
|
-
var FileService;
|
|
2
|
+
import { Uri } from '../common/index.js';
|
|
3
|
+
import { TwoWayMap } from '../common/TwoWayMap.js';
|
|
4
|
+
import { fileUtil } from './fileUtil.js';
|
|
5
|
+
export var FileService;
|
|
35
6
|
(function (FileService) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return
|
|
7
|
+
function create(externals, cacheRoot) {
|
|
8
|
+
const virtualUrisRoot = fileUtil.ensureEndingSlash(new Uri('virtual-uris/', cacheRoot).toString());
|
|
9
|
+
return new FileServiceImpl(externals, virtualUrisRoot);
|
|
39
10
|
}
|
|
40
11
|
FileService.create = create;
|
|
41
|
-
})(FileService
|
|
42
|
-
class FileServiceImpl {
|
|
43
|
-
|
|
44
|
-
|
|
12
|
+
})(FileService || (FileService = {}));
|
|
13
|
+
export class FileServiceImpl {
|
|
14
|
+
externals;
|
|
15
|
+
virtualUrisRoot;
|
|
16
|
+
supporters = new Map();
|
|
17
|
+
/**
|
|
18
|
+
* A two-way map from mapped physical URIs to virtual URIs.
|
|
19
|
+
*/
|
|
20
|
+
map = new TwoWayMap();
|
|
21
|
+
constructor(externals, virtualUrisRoot) {
|
|
22
|
+
this.externals = externals;
|
|
23
|
+
this.virtualUrisRoot = virtualUrisRoot;
|
|
45
24
|
}
|
|
46
25
|
register(protocol, supporter, force = false) {
|
|
47
26
|
if (!force && this.supporters.has(protocol)) {
|
|
@@ -58,7 +37,7 @@ class FileServiceImpl {
|
|
|
58
37
|
* @returns The protocol if it's supported.
|
|
59
38
|
*/
|
|
60
39
|
getSupportedProtocol(uri) {
|
|
61
|
-
const protocol = new
|
|
40
|
+
const protocol = new Uri(uri).protocol;
|
|
62
41
|
if (!this.supporters.has(protocol)) {
|
|
63
42
|
throw new Error(`The protocol “${protocol}” is unsupported.`);
|
|
64
43
|
}
|
|
@@ -88,19 +67,50 @@ class FileServiceImpl {
|
|
|
88
67
|
yield* supporter.listRoots();
|
|
89
68
|
}
|
|
90
69
|
}
|
|
70
|
+
async mapToDisk(virtualUri) {
|
|
71
|
+
if (fileUtil.isFileUri(virtualUri)) {
|
|
72
|
+
return virtualUri;
|
|
73
|
+
}
|
|
74
|
+
if (!this.virtualUrisRoot) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
let mappedUri = this.map.getKey(virtualUri);
|
|
79
|
+
if (mappedUri === undefined) {
|
|
80
|
+
mappedUri = `${this.virtualUrisRoot}${await this.externals.crypto.getSha1(virtualUri)}/${fileUtil.basename(virtualUri)}`;
|
|
81
|
+
const buffer = await this.readFile(virtualUri);
|
|
82
|
+
await fileUtil.writeFile(this.externals, mappedUri, buffer, 0o444);
|
|
83
|
+
this.map.set(mappedUri, virtualUri);
|
|
84
|
+
}
|
|
85
|
+
return mappedUri;
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
// Ignored.
|
|
89
|
+
}
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
mapFromDisk(mappedUri) {
|
|
93
|
+
if (!this.virtualUrisRoot) {
|
|
94
|
+
return mappedUri;
|
|
95
|
+
}
|
|
96
|
+
return this.map.get(mappedUri) ?? mappedUri;
|
|
97
|
+
}
|
|
91
98
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
99
|
+
export class FileUriSupporter {
|
|
100
|
+
externals;
|
|
101
|
+
roots;
|
|
102
|
+
files;
|
|
103
|
+
protocol = 'file:';
|
|
104
|
+
constructor(externals, roots, files) {
|
|
105
|
+
this.externals = externals;
|
|
95
106
|
this.roots = roots;
|
|
96
107
|
this.files = files;
|
|
97
|
-
this.protocol = 'file:';
|
|
98
108
|
}
|
|
99
109
|
async hash(uri) {
|
|
100
|
-
return hashFile(uri);
|
|
110
|
+
return hashFile(this.externals, uri);
|
|
101
111
|
}
|
|
102
112
|
readFile(uri) {
|
|
103
|
-
return
|
|
113
|
+
return this.externals.fs.readFile(uri);
|
|
104
114
|
}
|
|
105
115
|
*listFiles() {
|
|
106
116
|
for (const files of this.files.values()) {
|
|
@@ -110,55 +120,64 @@ class FileUriSupporter {
|
|
|
110
120
|
listRoots() {
|
|
111
121
|
return this.roots;
|
|
112
122
|
}
|
|
113
|
-
|
|
114
|
-
return
|
|
123
|
+
async mapToDisk(uri) {
|
|
124
|
+
return uri;
|
|
115
125
|
}
|
|
116
|
-
static async create(dependencies, logger) {
|
|
126
|
+
static async create(dependencies, externals, logger) {
|
|
117
127
|
const roots = [];
|
|
118
128
|
const files = new Map();
|
|
119
129
|
for (let { uri } of dependencies) {
|
|
120
130
|
try {
|
|
121
|
-
if (
|
|
122
|
-
uri =
|
|
131
|
+
if (fileUtil.isFileUri(uri) && (await externals.fs.stat(uri)).isDirectory()) {
|
|
132
|
+
uri = fileUtil.ensureEndingSlash(uri);
|
|
123
133
|
roots.push(uri);
|
|
124
|
-
files.set(uri,
|
|
134
|
+
files.set(uri, await externals.fs.getAllFiles(uri));
|
|
125
135
|
}
|
|
126
136
|
}
|
|
127
137
|
catch (e) {
|
|
128
138
|
logger.error(`[FileUriSupporter#create] Bad dependency “${uri}”`, e);
|
|
129
139
|
}
|
|
130
140
|
}
|
|
131
|
-
return new FileUriSupporter(roots, files);
|
|
141
|
+
return new FileUriSupporter(externals, roots, files);
|
|
132
142
|
}
|
|
133
143
|
}
|
|
134
|
-
|
|
135
|
-
|
|
144
|
+
// namespace ArchiveUri {
|
|
145
|
+
// export function is(uri: Uri): boolean {
|
|
146
|
+
// return uri.protocol === Protocol && uri.hostname === Hostname
|
|
147
|
+
// }
|
|
148
|
+
// }
|
|
149
|
+
export class ArchiveUriSupporter {
|
|
150
|
+
externals;
|
|
151
|
+
entries;
|
|
152
|
+
static Protocol = 'archive:';
|
|
153
|
+
static SupportedArchiveExtnames = ['.tar', '.tar.bz2', '.tar.gz', '.zip'];
|
|
154
|
+
protocol = ArchiveUriSupporter.Protocol;
|
|
136
155
|
/**
|
|
137
156
|
* @param entries A map from archive URIs to unzipped entries.
|
|
138
157
|
*/
|
|
139
|
-
constructor(entries) {
|
|
158
|
+
constructor(externals, entries) {
|
|
159
|
+
this.externals = externals;
|
|
140
160
|
this.entries = entries;
|
|
141
|
-
this.protocol = common_1.SpyglassUri.Protocol;
|
|
142
161
|
}
|
|
143
162
|
async hash(uri) {
|
|
144
|
-
const { archiveUri, pathInArchive } =
|
|
163
|
+
const { archiveUri, pathInArchive } = ArchiveUriSupporter.decodeUri(new Uri(uri));
|
|
145
164
|
if (!pathInArchive) {
|
|
146
165
|
// Hash the archive itself.
|
|
147
|
-
return hashFile(archiveUri);
|
|
166
|
+
return hashFile(this.externals, archiveUri);
|
|
148
167
|
}
|
|
149
168
|
else {
|
|
150
169
|
// Hash the corresponding file.
|
|
151
|
-
return
|
|
170
|
+
return this.externals.crypto.getSha1(this.getDataInArchive(archiveUri, pathInArchive));
|
|
152
171
|
}
|
|
153
172
|
}
|
|
154
173
|
async readFile(uri) {
|
|
155
|
-
const { archiveUri, pathInArchive } =
|
|
174
|
+
const { archiveUri, pathInArchive } = ArchiveUriSupporter.decodeUri(new Uri(uri));
|
|
156
175
|
return this.getDataInArchive(archiveUri, pathInArchive);
|
|
157
176
|
}
|
|
158
177
|
/**
|
|
159
178
|
* @throws
|
|
160
179
|
*/
|
|
161
|
-
|
|
180
|
+
getDataInArchive(archiveUri, pathInArchive) {
|
|
162
181
|
const entries = this.entries.get(archiveUri);
|
|
163
182
|
if (!entries) {
|
|
164
183
|
throw new Error(`Archive “${archiveUri}” has not been loaded into the memory`);
|
|
@@ -175,31 +194,46 @@ class SpyglassUriSupporter {
|
|
|
175
194
|
*listFiles() {
|
|
176
195
|
for (const [archiveUri, files] of this.entries.entries()) {
|
|
177
196
|
for (const file of files.values()) {
|
|
178
|
-
yield
|
|
197
|
+
yield ArchiveUriSupporter.getUri(archiveUri, file.path);
|
|
179
198
|
}
|
|
180
199
|
}
|
|
181
200
|
}
|
|
182
201
|
*listRoots() {
|
|
183
202
|
for (const archiveUri of this.entries.keys()) {
|
|
184
|
-
yield
|
|
203
|
+
yield ArchiveUriSupporter.getUri(archiveUri);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
static getUri(archiveUri, pathInArchive = '') {
|
|
207
|
+
return `${ArchiveUriSupporter.Protocol}//${encodeURIComponent(archiveUri)}/${pathInArchive.replace(/\\/g, '/')}`;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* @throws When `uri` has the wrong protocol or hostname.
|
|
211
|
+
*/
|
|
212
|
+
static decodeUri(uri) {
|
|
213
|
+
if (uri.protocol !== ArchiveUriSupporter.Protocol) {
|
|
214
|
+
throw new Error(`Expected protocol “${ArchiveUriSupporter.Protocol}” in “${uri}”`);
|
|
185
215
|
}
|
|
216
|
+
return {
|
|
217
|
+
archiveUri: decodeURIComponent(uri.hostname),
|
|
218
|
+
pathInArchive: uri.pathname.charAt(0) === '/' ? uri.pathname.slice(1) : uri.pathname,
|
|
219
|
+
};
|
|
186
220
|
}
|
|
187
|
-
static async create(dependencies, logger, checksums) {
|
|
221
|
+
static async create(dependencies, externals, logger, checksums) {
|
|
188
222
|
const entries = new Map();
|
|
189
223
|
for (const { uri, info } of dependencies) {
|
|
190
224
|
try {
|
|
191
|
-
if (uri.startsWith('file:') &&
|
|
192
|
-
const rootUri =
|
|
225
|
+
if (uri.startsWith('file:') && ArchiveUriSupporter.SupportedArchiveExtnames.some(ext => uri.endsWith(ext)) && (await externals.fs.stat(uri)).isFile()) {
|
|
226
|
+
const rootUri = ArchiveUriSupporter.getUri(uri);
|
|
193
227
|
const cachedChecksum = checksums[rootUri];
|
|
194
228
|
if (cachedChecksum !== undefined) {
|
|
195
|
-
const checksum = await hashFile(uri);
|
|
229
|
+
const checksum = await hashFile(externals, uri);
|
|
196
230
|
if (cachedChecksum === checksum) {
|
|
197
231
|
// The dependency has not changed since last cache.
|
|
198
232
|
logger.info(`[SpyglassUriSupporter#create] Skipped decompressing “${uri}” thanks to cache ${checksum}`);
|
|
199
233
|
continue;
|
|
200
234
|
}
|
|
201
235
|
}
|
|
202
|
-
const files = await (
|
|
236
|
+
const files = await externals.archive.decompressBall(await externals.fs.readFile(uri), { stripLevel: typeof info?.startDepth === 'number' ? info.startDepth : 0 });
|
|
203
237
|
entries.set(uri, new Map(files.map(f => [f.path.replace(/\\/g, '/'), f])));
|
|
204
238
|
}
|
|
205
239
|
}
|
|
@@ -207,18 +241,10 @@ class SpyglassUriSupporter {
|
|
|
207
241
|
logger.error(`[SpyglassUriSupporter#create] Bad dependency “${uri}”`, e);
|
|
208
242
|
}
|
|
209
243
|
}
|
|
210
|
-
return new
|
|
244
|
+
return new ArchiveUriSupporter(externals, entries);
|
|
211
245
|
}
|
|
212
246
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
async function hashFile(uri) {
|
|
216
|
-
return new Promise((resolve, reject) => {
|
|
217
|
-
const hash = crypto_1.default.createHash(HashAlgorithm);
|
|
218
|
-
fs_1.default.createReadStream(new common_1.Uri(uri))
|
|
219
|
-
.on('data', chunk => hash.update(chunk))
|
|
220
|
-
.on('end', () => resolve(hash.digest('hex')))
|
|
221
|
-
.on('error', reject);
|
|
222
|
-
});
|
|
247
|
+
async function hashFile(externals, uri) {
|
|
248
|
+
return externals.crypto.getSha1(await externals.fs.readFile(uri));
|
|
223
249
|
}
|
|
224
250
|
//# sourceMappingURL=FileService.js.map
|
package/lib/service/Hover.d.ts
CHANGED
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 (`.`).
|
|
@@ -58,6 +58,9 @@ export declare class MetaRegistry {
|
|
|
58
58
|
* @returns The language ID registered for the file extension, or `undefined`.
|
|
59
59
|
*/
|
|
60
60
|
getLanguageID(fileExtension: FileExtension): string | undefined;
|
|
61
|
+
hasBinder<N extends AstNode>(type: N['type']): boolean;
|
|
62
|
+
getBinder<N extends AstNode>(type: N['type']): Binder<N>;
|
|
63
|
+
registerBinder<N extends AstNode>(type: N['type'], binder: Binder<N>): void;
|
|
61
64
|
hasChecker<N extends AstNode>(type: N['type']): boolean;
|
|
62
65
|
getChecker<N extends AstNode>(type: N['type']): Checker<N>;
|
|
63
66
|
registerChecker<N extends AstNode>(type: N['type'], checker: Checker<N>): void;
|
|
@@ -101,6 +104,8 @@ export declare class MetaRegistry {
|
|
|
101
104
|
get symbolRegistrars(): Map<string, SymbolRegistrarRegistration>;
|
|
102
105
|
registerUriBinder(uriBinder: UriBinder): void;
|
|
103
106
|
get uriBinders(): Set<UriBinder>;
|
|
107
|
+
setUriSorter(uriSorter: UriSorterRegistration): void;
|
|
108
|
+
get uriSorter(): UriSorter;
|
|
104
109
|
}
|
|
105
110
|
export {};
|
|
106
111
|
//# 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
|