@spyglassmc/core 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -0
- package/lib/browser.d.ts +2 -0
- package/lib/browser.js +2 -0
- package/lib/common/TwoWayMap.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 +151 -0
- package/lib/common/externals/downloader.d.ts +31 -0
- package/lib/common/externals/downloader.js +32 -0
- package/lib/common/externals/index.d.ts +96 -0
- package/lib/common/externals/index.js +2 -0
- package/lib/common/index.d.ts +2 -1
- package/lib/common/index.js +2 -17
- package/lib/common/util.d.ts +15 -15
- package/lib/common/util.js +30 -77
- package/lib/index.d.ts +7 -7
- package/lib/index.js +7 -23
- package/lib/node/AstNode.d.ts +3 -3
- package/lib/node/AstNode.js +10 -16
- package/lib/node/BooleanNode.d.ts +2 -2
- package/lib/node/BooleanNode.js +4 -7
- package/lib/node/CommentNode.d.ts +1 -1
- package/lib/node/CommentNode.js +2 -5
- package/lib/node/ErrorNode.d.ts +1 -1
- package/lib/node/ErrorNode.js +2 -5
- package/lib/node/FileNode.d.ts +3 -3
- package/lib/node/FileNode.js +2 -5
- package/lib/node/FloatNode.d.ts +2 -2
- package/lib/node/FloatNode.js +4 -7
- package/lib/node/IntegerNode.d.ts +2 -2
- package/lib/node/IntegerNode.js +4 -7
- package/lib/node/ListNode.d.ts +2 -2
- package/lib/node/ListNode.js +2 -5
- package/lib/node/LiteralNode.d.ts +3 -3
- package/lib/node/LiteralNode.js +4 -7
- package/lib/node/LongNode.d.ts +2 -2
- package/lib/node/LongNode.js +4 -7
- package/lib/node/RecordNode.d.ts +2 -2
- package/lib/node/RecordNode.js +2 -5
- package/lib/node/ResourceLocationNode.d.ts +5 -5
- 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 +4 -4
- package/lib/node/StringNode.js +9 -12
- package/lib/node/SymbolNode.d.ts +3 -3
- 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 +14 -18
- package/lib/parser/string.d.ts +5 -5
- package/lib/parser/string.js +36 -42
- package/lib/parser/symbol.d.ts +3 -3
- package/lib/parser/symbol.js +3 -7
- package/lib/parser/util.d.ts +5 -5
- package/lib/parser/util.js +38 -56
- package/lib/processor/ColorInfoProvider.d.ts +1 -1
- package/lib/processor/ColorInfoProvider.js +6 -9
- package/lib/processor/InlayHintProvider.d.ts +2 -2
- package/lib/processor/InlayHintProvider.js +1 -2
- package/lib/processor/SignatureHelpProvider.d.ts +2 -2
- package/lib/processor/SignatureHelpProvider.js +1 -2
- package/lib/processor/checker/Checker.d.ts +2 -2
- package/lib/processor/checker/Checker.js +1 -5
- package/lib/processor/checker/builtin.d.ts +4 -4
- package/lib/processor/checker/builtin.js +19 -30
- package/lib/processor/checker/index.d.ts +2 -2
- package/lib/processor/checker/index.js +2 -31
- package/lib/processor/colorizer/Colorizer.d.ts +4 -4
- package/lib/processor/colorizer/Colorizer.js +8 -11
- package/lib/processor/colorizer/builtin.d.ts +3 -3
- package/lib/processor/colorizer/builtin.js +33 -46
- package/lib/processor/colorizer/index.d.ts +2 -2
- package/lib/processor/colorizer/index.js +2 -31
- package/lib/processor/completer/Completer.d.ts +4 -4
- package/lib/processor/completer/Completer.js +14 -33
- package/lib/processor/completer/builtin.d.ts +7 -7
- package/lib/processor/completer/builtin.js +46 -62
- package/lib/processor/completer/index.d.ts +2 -2
- package/lib/processor/completer/index.js +2 -31
- package/lib/processor/formatter/Formatter.d.ts +2 -2
- package/lib/processor/formatter/Formatter.js +2 -7
- package/lib/processor/formatter/builtin.d.ts +3 -3
- package/lib/processor/formatter/builtin.js +22 -36
- package/lib/processor/formatter/index.d.ts +2 -2
- package/lib/processor/formatter/index.js +2 -31
- package/lib/processor/index.d.ts +9 -9
- package/lib/processor/index.js +9 -25
- package/lib/processor/linter/Linter.d.ts +2 -2
- package/lib/processor/linter/Linter.js +1 -2
- package/lib/processor/linter/builtin/undeclaredSymbol.d.ts +2 -2
- package/lib/processor/linter/builtin/undeclaredSymbol.js +20 -24
- package/lib/processor/linter/builtin.d.ts +3 -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 +2 -2
- package/lib/processor/util.js +4 -9
- package/lib/service/CacheService.d.ts +6 -6
- package/lib/service/CacheService.js +32 -56
- package/lib/service/Config.d.ts +11 -12
- package/lib/service/Config.js +50 -45
- package/lib/service/Context.d.ts +13 -13
- package/lib/service/Context.js +29 -32
- package/lib/service/Dependency.js +2 -5
- package/lib/service/Downloader.d.ts +10 -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 +16 -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/Logger.js +2 -5
- package/lib/service/MetaRegistry.d.ts +12 -12
- package/lib/service/MetaRegistry.js +62 -73
- package/lib/service/Operations.js +3 -9
- package/lib/service/Profiler.d.ts +1 -1
- package/lib/service/Profiler.js +25 -41
- package/lib/service/Project.d.ts +47 -51
- package/lib/service/Project.js +199 -239
- 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/fileUtil.d.ts +15 -45
- package/lib/service/fileUtil.js +38 -143
- package/lib/service/index.d.ts +17 -17
- package/lib/service/index.js +17 -35
- 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 +2 -5
- 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 +3 -3
- package/lib/source/Source.js +28 -29
- package/lib/source/index.d.ts +8 -8
- package/lib/source/index.js +8 -24
- package/lib/symbol/Symbol.d.ts +2 -2
- package/lib/symbol/Symbol.js +49 -65
- package/lib/symbol/SymbolUtil.d.ts +22 -25
- package/lib/symbol/SymbolUtil.js +150 -151
- package/lib/symbol/UriBinder.d.ts +1 -1
- package/lib/symbol/UriBinder.js +1 -2
- package/lib/symbol/index.d.ts +3 -3
- package/lib/symbol/index.js +3 -19
- package/package.json +7 -4
|
@@ -1,58 +1,26 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/* istanbul ignore file */
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
-
if (mod && mod.__esModule) return mod;
|
|
21
|
-
var result = {};
|
|
22
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
-
__setModuleDefault(result, mod);
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
|
-
};
|
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.ArchiveUriSupporter = exports.FileUriSupporter = exports.FileServiceImpl = exports.FileService = void 0;
|
|
31
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
32
|
-
const decompress_1 = __importDefault(require("decompress"));
|
|
33
|
-
const fs_1 = __importStar(require("fs"));
|
|
34
|
-
const globby_1 = __importDefault(require("globby"));
|
|
35
|
-
const path_1 = __importDefault(require("path"));
|
|
36
|
-
const common_1 = require("../common");
|
|
37
|
-
const TwoWayMap_1 = require("../common/TwoWayMap");
|
|
38
|
-
const fileUtil_1 = require("./fileUtil");
|
|
39
|
-
const HashAlgorithm = 'sha1';
|
|
40
|
-
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;
|
|
41
6
|
(function (FileService) {
|
|
42
|
-
function create(cacheRoot) {
|
|
43
|
-
const virtualUrisRoot =
|
|
44
|
-
return new FileServiceImpl(virtualUrisRoot);
|
|
7
|
+
function create(externals, cacheRoot) {
|
|
8
|
+
const virtualUrisRoot = fileUtil.ensureEndingSlash(new Uri('virtual-uris/', cacheRoot).toString());
|
|
9
|
+
return new FileServiceImpl(externals, virtualUrisRoot);
|
|
45
10
|
}
|
|
46
11
|
FileService.create = create;
|
|
47
|
-
})(FileService
|
|
48
|
-
class FileServiceImpl {
|
|
49
|
-
|
|
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;
|
|
50
23
|
this.virtualUrisRoot = virtualUrisRoot;
|
|
51
|
-
this.supporters = new Map();
|
|
52
|
-
/**
|
|
53
|
-
* A two-way map from mapped physical URIs to virtual URIs.
|
|
54
|
-
*/
|
|
55
|
-
this.map = new TwoWayMap_1.TwoWayMap();
|
|
56
24
|
}
|
|
57
25
|
register(protocol, supporter, force = false) {
|
|
58
26
|
if (!force && this.supporters.has(protocol)) {
|
|
@@ -69,7 +37,7 @@ class FileServiceImpl {
|
|
|
69
37
|
* @returns The protocol if it's supported.
|
|
70
38
|
*/
|
|
71
39
|
getSupportedProtocol(uri) {
|
|
72
|
-
const protocol = new
|
|
40
|
+
const protocol = new Uri(uri).protocol;
|
|
73
41
|
if (!this.supporters.has(protocol)) {
|
|
74
42
|
throw new Error(`The protocol “${protocol}” is unsupported.`);
|
|
75
43
|
}
|
|
@@ -100,7 +68,7 @@ class FileServiceImpl {
|
|
|
100
68
|
}
|
|
101
69
|
}
|
|
102
70
|
async mapToDisk(virtualUri) {
|
|
103
|
-
if (
|
|
71
|
+
if (fileUtil.isFileUri(virtualUri)) {
|
|
104
72
|
return virtualUri;
|
|
105
73
|
}
|
|
106
74
|
if (!this.virtualUrisRoot) {
|
|
@@ -109,9 +77,9 @@ class FileServiceImpl {
|
|
|
109
77
|
try {
|
|
110
78
|
let mappedUri = this.map.getKey(virtualUri);
|
|
111
79
|
if (mappedUri === undefined) {
|
|
112
|
-
mappedUri = `${this.virtualUrisRoot}${
|
|
80
|
+
mappedUri = `${this.virtualUrisRoot}${await this.externals.crypto.getSha1(virtualUri)}/${fileUtil.basename(virtualUri)}`;
|
|
113
81
|
const buffer = await this.readFile(virtualUri);
|
|
114
|
-
await
|
|
82
|
+
await fileUtil.writeFile(this.externals, mappedUri, buffer, 0o444);
|
|
115
83
|
this.map.set(mappedUri, virtualUri);
|
|
116
84
|
}
|
|
117
85
|
return mappedUri;
|
|
@@ -128,18 +96,21 @@ class FileServiceImpl {
|
|
|
128
96
|
return this.map.get(mappedUri) ?? mappedUri;
|
|
129
97
|
}
|
|
130
98
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
99
|
+
export class FileUriSupporter {
|
|
100
|
+
externals;
|
|
101
|
+
roots;
|
|
102
|
+
files;
|
|
103
|
+
protocol = 'file:';
|
|
104
|
+
constructor(externals, roots, files) {
|
|
105
|
+
this.externals = externals;
|
|
134
106
|
this.roots = roots;
|
|
135
107
|
this.files = files;
|
|
136
|
-
this.protocol = 'file:';
|
|
137
108
|
}
|
|
138
109
|
async hash(uri) {
|
|
139
|
-
return hashFile(uri);
|
|
110
|
+
return hashFile(this.externals, uri);
|
|
140
111
|
}
|
|
141
112
|
readFile(uri) {
|
|
142
|
-
return
|
|
113
|
+
return this.externals.fs.readFile(uri);
|
|
143
114
|
}
|
|
144
115
|
*listFiles() {
|
|
145
116
|
for (const files of this.files.values()) {
|
|
@@ -152,54 +123,55 @@ class FileUriSupporter {
|
|
|
152
123
|
async mapToDisk(uri) {
|
|
153
124
|
return uri;
|
|
154
125
|
}
|
|
155
|
-
static
|
|
156
|
-
return fileUtil_1.fileUtil.fileUriToPath(root) + '**/*';
|
|
157
|
-
}
|
|
158
|
-
static async create(dependencies, logger) {
|
|
126
|
+
static async create(dependencies, externals, logger) {
|
|
159
127
|
const roots = [];
|
|
160
128
|
const files = new Map();
|
|
161
129
|
for (let { uri } of dependencies) {
|
|
162
130
|
try {
|
|
163
|
-
if (
|
|
164
|
-
uri =
|
|
131
|
+
if (fileUtil.isFileUri(uri) && (await externals.fs.stat(uri)).isDirectory()) {
|
|
132
|
+
uri = fileUtil.ensureEndingSlash(uri);
|
|
165
133
|
roots.push(uri);
|
|
166
|
-
files.set(uri,
|
|
134
|
+
files.set(uri, await externals.fs.getAllFiles(uri));
|
|
167
135
|
}
|
|
168
136
|
}
|
|
169
137
|
catch (e) {
|
|
170
138
|
logger.error(`[FileUriSupporter#create] Bad dependency “${uri}”`, e);
|
|
171
139
|
}
|
|
172
140
|
}
|
|
173
|
-
return new FileUriSupporter(roots, files);
|
|
141
|
+
return new FileUriSupporter(externals, roots, files);
|
|
174
142
|
}
|
|
175
143
|
}
|
|
176
|
-
exports.FileUriSupporter = FileUriSupporter;
|
|
177
144
|
// namespace ArchiveUri {
|
|
178
145
|
// export function is(uri: Uri): boolean {
|
|
179
146
|
// return uri.protocol === Protocol && uri.hostname === Hostname
|
|
180
147
|
// }
|
|
181
148
|
// }
|
|
182
|
-
class ArchiveUriSupporter {
|
|
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;
|
|
183
155
|
/**
|
|
184
156
|
* @param entries A map from archive URIs to unzipped entries.
|
|
185
157
|
*/
|
|
186
|
-
constructor(entries) {
|
|
158
|
+
constructor(externals, entries) {
|
|
159
|
+
this.externals = externals;
|
|
187
160
|
this.entries = entries;
|
|
188
|
-
this.protocol = ArchiveUriSupporter.Protocol;
|
|
189
161
|
}
|
|
190
162
|
async hash(uri) {
|
|
191
|
-
const { archiveUri, pathInArchive } = ArchiveUriSupporter.decodeUri(new
|
|
163
|
+
const { archiveUri, pathInArchive } = ArchiveUriSupporter.decodeUri(new Uri(uri));
|
|
192
164
|
if (!pathInArchive) {
|
|
193
165
|
// Hash the archive itself.
|
|
194
|
-
return hashFile(archiveUri);
|
|
166
|
+
return hashFile(this.externals, archiveUri);
|
|
195
167
|
}
|
|
196
168
|
else {
|
|
197
169
|
// Hash the corresponding file.
|
|
198
|
-
return
|
|
170
|
+
return this.externals.crypto.getSha1(this.getDataInArchive(archiveUri, pathInArchive));
|
|
199
171
|
}
|
|
200
172
|
}
|
|
201
173
|
async readFile(uri) {
|
|
202
|
-
const { archiveUri, pathInArchive } = ArchiveUriSupporter.decodeUri(new
|
|
174
|
+
const { archiveUri, pathInArchive } = ArchiveUriSupporter.decodeUri(new Uri(uri));
|
|
203
175
|
return this.getDataInArchive(archiveUri, pathInArchive);
|
|
204
176
|
}
|
|
205
177
|
/**
|
|
@@ -246,22 +218,22 @@ class ArchiveUriSupporter {
|
|
|
246
218
|
pathInArchive: uri.pathname.charAt(0) === '/' ? uri.pathname.slice(1) : uri.pathname,
|
|
247
219
|
};
|
|
248
220
|
}
|
|
249
|
-
static async create(dependencies, logger, checksums) {
|
|
221
|
+
static async create(dependencies, externals, logger, checksums) {
|
|
250
222
|
const entries = new Map();
|
|
251
223
|
for (const { uri, info } of dependencies) {
|
|
252
224
|
try {
|
|
253
|
-
if (uri.startsWith('file:') && ArchiveUriSupporter.SupportedArchiveExtnames.some(ext => uri.endsWith(ext)) && (await
|
|
225
|
+
if (uri.startsWith('file:') && ArchiveUriSupporter.SupportedArchiveExtnames.some(ext => uri.endsWith(ext)) && (await externals.fs.stat(uri)).isFile()) {
|
|
254
226
|
const rootUri = ArchiveUriSupporter.getUri(uri);
|
|
255
227
|
const cachedChecksum = checksums[rootUri];
|
|
256
228
|
if (cachedChecksum !== undefined) {
|
|
257
|
-
const checksum = await hashFile(uri);
|
|
229
|
+
const checksum = await hashFile(externals, uri);
|
|
258
230
|
if (cachedChecksum === checksum) {
|
|
259
231
|
// The dependency has not changed since last cache.
|
|
260
232
|
logger.info(`[SpyglassUriSupporter#create] Skipped decompressing “${uri}” thanks to cache ${checksum}`);
|
|
261
233
|
continue;
|
|
262
234
|
}
|
|
263
235
|
}
|
|
264
|
-
const files = await (
|
|
236
|
+
const files = await externals.archive.decompressBall(await externals.fs.readFile(uri), { stripLevel: typeof info?.startDepth === 'number' ? info.startDepth : 0 });
|
|
265
237
|
entries.set(uri, new Map(files.map(f => [f.path.replace(/\\/g, '/'), f])));
|
|
266
238
|
}
|
|
267
239
|
}
|
|
@@ -269,19 +241,10 @@ class ArchiveUriSupporter {
|
|
|
269
241
|
logger.error(`[SpyglassUriSupporter#create] Bad dependency “${uri}”`, e);
|
|
270
242
|
}
|
|
271
243
|
}
|
|
272
|
-
return new ArchiveUriSupporter(entries);
|
|
244
|
+
return new ArchiveUriSupporter(externals, entries);
|
|
273
245
|
}
|
|
274
246
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
ArchiveUriSupporter.SupportedArchiveExtnames = ['.tar', '.tar.bz2', '.tar.gz', '.zip'];
|
|
278
|
-
async function hashFile(uri) {
|
|
279
|
-
return new Promise((resolve, reject) => {
|
|
280
|
-
const hash = crypto_1.default.createHash(HashAlgorithm);
|
|
281
|
-
fs_1.default.createReadStream(new common_1.Uri(uri))
|
|
282
|
-
.on('data', chunk => hash.update(chunk))
|
|
283
|
-
.on('end', () => resolve(hash.digest('hex')))
|
|
284
|
-
.on('error', reject);
|
|
285
|
-
});
|
|
247
|
+
async function hashFile(externals, uri) {
|
|
248
|
+
return externals.crypto.getSha1(await externals.fs.readFile(uri));
|
|
286
249
|
}
|
|
287
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
|
package/lib/service/Logger.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Logger = void 0;
|
|
4
|
-
var Logger;
|
|
1
|
+
export var Logger;
|
|
5
2
|
(function (Logger) {
|
|
6
3
|
/* istanbul ignore next */
|
|
7
4
|
/**
|
|
@@ -20,7 +17,7 @@ var Logger;
|
|
|
20
17
|
return new NoopLogger();
|
|
21
18
|
}
|
|
22
19
|
Logger.noop = noop;
|
|
23
|
-
})(Logger
|
|
20
|
+
})(Logger || (Logger = {}));
|
|
24
21
|
class NoopLogger {
|
|
25
22
|
error() { }
|
|
26
23
|
info() { }
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { Lazy } from '../common';
|
|
2
|
-
import type { AstNode } from '../node';
|
|
3
|
-
import type { Parser } from '../parser';
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import type { Linter } from '../processor/linter/Linter';
|
|
7
|
-
import type { SignatureHelpProvider } from '../processor/SignatureHelpProvider';
|
|
8
|
-
import type { UriBinder } from '../symbol';
|
|
9
|
-
import type { DependencyKey, DependencyProvider } from './Dependency';
|
|
10
|
-
import type { FileExtension } from './fileUtil';
|
|
11
|
-
import type { Logger } from './Logger';
|
|
12
|
-
import type { SymbolRegistrar } from './SymbolRegistrar';
|
|
1
|
+
import { Lazy } from '../common/index.js';
|
|
2
|
+
import type { AstNode } from '../node/index.js';
|
|
3
|
+
import type { Parser } from '../parser/index.js';
|
|
4
|
+
import type { Formatter } from '../processor/formatter/index.js';
|
|
5
|
+
import type { Checker, Colorizer, Completer, InlayHintProvider } from '../processor/index.js';
|
|
6
|
+
import type { Linter } from '../processor/linter/Linter.js';
|
|
7
|
+
import type { SignatureHelpProvider } from '../processor/SignatureHelpProvider.js';
|
|
8
|
+
import type { UriBinder } from '../symbol/index.js';
|
|
9
|
+
import type { DependencyKey, DependencyProvider } from './Dependency.js';
|
|
10
|
+
import type { FileExtension } from './fileUtil.js';
|
|
11
|
+
import type { Logger } from './Logger.js';
|
|
12
|
+
import type { SymbolRegistrar } from './SymbolRegistrar.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 (`.`).
|
|
@@ -1,40 +1,31 @@
|
|
|
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 { 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
|
+
#checkers = new Map();
|
|
13
|
+
#colorizers = new Map();
|
|
14
|
+
#completers = new Map();
|
|
15
|
+
#dependencyProviders = new Map();
|
|
16
|
+
#formatters = new Map();
|
|
17
|
+
#inlayHintProviders = new Set();
|
|
18
|
+
#linters = new Map();
|
|
19
|
+
#parsers = new Map();
|
|
20
|
+
#signatureHelpProviders = new Set();
|
|
21
|
+
#symbolRegistrars = new Map();
|
|
22
|
+
#uriBinders = new Set();
|
|
17
23
|
constructor() {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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);
|
|
24
|
+
checker.registerCheckers(this);
|
|
25
|
+
colorizer.registerColorizers(this);
|
|
26
|
+
completer.registerCompleters(this);
|
|
27
|
+
formatter.registerFormatters(this);
|
|
28
|
+
linter.registerLinters(this);
|
|
38
29
|
}
|
|
39
30
|
/**
|
|
40
31
|
* Registers a new language.
|
|
@@ -42,35 +33,35 @@ class MetaRegistry {
|
|
|
42
33
|
* @param options The language options for this language.
|
|
43
34
|
*/
|
|
44
35
|
registerLanguage(languageID, options) {
|
|
45
|
-
|
|
36
|
+
this.#languages.set(languageID, options);
|
|
46
37
|
}
|
|
47
38
|
/**
|
|
48
39
|
* An array of all registered language IDs.
|
|
49
40
|
*/
|
|
50
41
|
getLanguages() {
|
|
51
|
-
return Array.from(
|
|
42
|
+
return Array.from(this.#languages.keys());
|
|
52
43
|
}
|
|
53
44
|
isSupportedLanguage(language) {
|
|
54
|
-
return
|
|
45
|
+
return this.#languages.has(language);
|
|
55
46
|
}
|
|
56
47
|
/**
|
|
57
48
|
* An array of file extensions (including the leading dot (`.`)) that are supported.
|
|
58
49
|
*/
|
|
59
50
|
getSupportedFileExtensions() {
|
|
60
|
-
return [...
|
|
51
|
+
return [...this.#languages.values()].flatMap(v => v.extensions);
|
|
61
52
|
}
|
|
62
53
|
/**
|
|
63
54
|
* An array of characters that trigger a completion request.
|
|
64
55
|
*/
|
|
65
56
|
getTriggerCharacters() {
|
|
66
|
-
return Array.from(
|
|
57
|
+
return Array.from(this.#languages.values()).flatMap(v => v.triggerCharacters ?? []);
|
|
67
58
|
}
|
|
68
59
|
/**
|
|
69
60
|
* @param fileExtension The file extension including the leading dot. e.g. `".mcfunction"`.
|
|
70
61
|
* @returns The language ID registered for the file extension, or `undefined`.
|
|
71
62
|
*/
|
|
72
63
|
getLanguageID(fileExtension) {
|
|
73
|
-
for (const [languageID, { extensions }] of
|
|
64
|
+
for (const [languageID, { extensions }] of this.#languages) {
|
|
74
65
|
if (extensions.includes(fileExtension)) {
|
|
75
66
|
return languageID;
|
|
76
67
|
}
|
|
@@ -78,115 +69,113 @@ class MetaRegistry {
|
|
|
78
69
|
return undefined;
|
|
79
70
|
}
|
|
80
71
|
hasChecker(type) {
|
|
81
|
-
return
|
|
72
|
+
return this.#checkers.has(type);
|
|
82
73
|
}
|
|
83
74
|
getChecker(type) {
|
|
84
|
-
return
|
|
75
|
+
return this.#checkers.get(type) ?? checker.fallback;
|
|
85
76
|
}
|
|
86
77
|
registerChecker(type, checker) {
|
|
87
|
-
|
|
78
|
+
this.#checkers.set(type, checker);
|
|
88
79
|
}
|
|
89
80
|
hasColorizer(type) {
|
|
90
|
-
return
|
|
81
|
+
return this.#colorizers.has(type);
|
|
91
82
|
}
|
|
92
83
|
getColorizer(type) {
|
|
93
|
-
return
|
|
84
|
+
return this.#colorizers.get(type) ?? colorizer.fallback;
|
|
94
85
|
}
|
|
95
86
|
registerColorizer(type, colorizer) {
|
|
96
|
-
|
|
87
|
+
this.#colorizers.set(type, colorizer);
|
|
97
88
|
}
|
|
98
89
|
hasCompleter(type) {
|
|
99
|
-
return
|
|
90
|
+
return this.#completers.has(type);
|
|
100
91
|
}
|
|
101
92
|
getCompleter(type) {
|
|
102
|
-
return
|
|
93
|
+
return this.#completers.get(type) ?? completer.fallback;
|
|
103
94
|
}
|
|
104
95
|
registerCompleter(type, completer) {
|
|
105
|
-
|
|
96
|
+
this.#completers.set(type, completer);
|
|
106
97
|
}
|
|
107
98
|
shouldComplete(languageID, triggerCharacter) {
|
|
108
|
-
const language =
|
|
99
|
+
const language = this.#languages.get(languageID);
|
|
109
100
|
return !triggerCharacter || !!language?.triggerCharacters?.includes(triggerCharacter);
|
|
110
101
|
}
|
|
111
102
|
getCompleterForLanguageID(languageID) {
|
|
112
|
-
return
|
|
103
|
+
return this.#languages.get(languageID)?.completer ?? completer.fallback;
|
|
113
104
|
}
|
|
114
105
|
getDependencyProvider(key) {
|
|
115
|
-
return
|
|
106
|
+
return this.#dependencyProviders.get(key);
|
|
116
107
|
}
|
|
117
108
|
registerDependencyProvider(key, provider) {
|
|
118
|
-
|
|
109
|
+
this.#dependencyProviders.set(key, provider);
|
|
119
110
|
}
|
|
120
111
|
hasFormatter(type) {
|
|
121
|
-
return
|
|
112
|
+
return this.#formatters.has(type);
|
|
122
113
|
}
|
|
123
114
|
getFormatter(type) {
|
|
124
|
-
return
|
|
115
|
+
return this.#formatters.get(type) ?? formatter.fallback;
|
|
125
116
|
}
|
|
126
117
|
registerFormatter(type, formatter) {
|
|
127
|
-
|
|
118
|
+
this.#formatters.set(type, formatter);
|
|
128
119
|
}
|
|
129
120
|
registerInlayHintProvider(provider) {
|
|
130
|
-
|
|
121
|
+
this.#inlayHintProviders.add(provider);
|
|
131
122
|
}
|
|
132
123
|
get inlayHintProviders() {
|
|
133
|
-
return
|
|
124
|
+
return this.#inlayHintProviders;
|
|
134
125
|
}
|
|
135
126
|
getLinter(ruleName) {
|
|
136
|
-
return
|
|
127
|
+
return this.#linters.get(ruleName) ?? {
|
|
137
128
|
configValidator: () => false,
|
|
138
|
-
linter:
|
|
129
|
+
linter: linter.noop,
|
|
139
130
|
nodePredicate: () => false,
|
|
140
131
|
};
|
|
141
132
|
}
|
|
142
133
|
registerLinter(ruleName, options) {
|
|
143
|
-
|
|
134
|
+
this.#linters.set(ruleName, options);
|
|
144
135
|
}
|
|
145
136
|
hasParser(id) {
|
|
146
|
-
return
|
|
137
|
+
return this.#parsers.has(id);
|
|
147
138
|
}
|
|
148
139
|
getParser(id) {
|
|
149
|
-
const ans =
|
|
140
|
+
const ans = this.#parsers.get(id);
|
|
150
141
|
if (!ans) {
|
|
151
142
|
throw new Error(`There is no parser '${id}'`);
|
|
152
143
|
}
|
|
153
144
|
return ans;
|
|
154
145
|
}
|
|
155
146
|
getParserLazily(id) {
|
|
156
|
-
return
|
|
147
|
+
return Lazy.create(() => this.getParser(id));
|
|
157
148
|
}
|
|
158
149
|
registerParser(id, parser) {
|
|
159
|
-
|
|
150
|
+
this.#parsers.set(id, parser);
|
|
160
151
|
}
|
|
161
152
|
/**
|
|
162
153
|
* @returns The corresponding `Parser` for the language ID.
|
|
163
154
|
* @throws If there's no such language in the registry.
|
|
164
155
|
*/
|
|
165
156
|
getParserForLanguageId(languageID) {
|
|
166
|
-
if (
|
|
167
|
-
return
|
|
157
|
+
if (this.#languages.has(languageID)) {
|
|
158
|
+
return this.#languages.get(languageID).parser;
|
|
168
159
|
}
|
|
169
160
|
throw new Error(`There is no parser registered for language ID '${languageID}'`);
|
|
170
161
|
}
|
|
171
162
|
registerSignatureHelpProvider(provider) {
|
|
172
|
-
|
|
163
|
+
this.#signatureHelpProviders.add(provider);
|
|
173
164
|
}
|
|
174
165
|
get signatureHelpProviders() {
|
|
175
|
-
return
|
|
166
|
+
return this.#signatureHelpProviders;
|
|
176
167
|
}
|
|
177
168
|
registerSymbolRegistrar(id, registrar) {
|
|
178
|
-
|
|
169
|
+
this.#symbolRegistrars.set(id, registrar);
|
|
179
170
|
}
|
|
180
171
|
get symbolRegistrars() {
|
|
181
|
-
return
|
|
172
|
+
return this.#symbolRegistrars;
|
|
182
173
|
}
|
|
183
174
|
registerUriBinder(uriBinder) {
|
|
184
|
-
|
|
175
|
+
this.#uriBinders.add(uriBinder);
|
|
185
176
|
}
|
|
186
177
|
get uriBinders() {
|
|
187
|
-
return
|
|
178
|
+
return this.#uriBinders;
|
|
188
179
|
}
|
|
189
180
|
}
|
|
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
181
|
//# sourceMappingURL=MetaRegistry.js.map
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class Operations {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.undoOps = [];
|
|
7
|
-
this.redoOps = [];
|
|
8
|
-
}
|
|
1
|
+
export class Operations {
|
|
2
|
+
undoOps = [];
|
|
3
|
+
redoOps = [];
|
|
9
4
|
set(obj, key, value) {
|
|
10
5
|
const oldValue = obj[key];
|
|
11
6
|
const op = () => { obj[key] = value; };
|
|
@@ -22,5 +17,4 @@ class Operations {
|
|
|
22
17
|
this.redoOps.forEach(f => f());
|
|
23
18
|
}
|
|
24
19
|
}
|
|
25
|
-
exports.Operations = Operations;
|
|
26
20
|
//# sourceMappingURL=Operations.js.map
|