@spyglassmc/core 0.1.0 → 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.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 +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 -13
- package/lib/common/util.d.ts +17 -34
- package/lib/common/util.js +32 -113
- package/lib/index.d.ts +7 -7
- package/lib/index.js +7 -19
- 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 +4 -4
- package/lib/node/LiteralNode.js +5 -8
- 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 +6 -8
- 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 +4 -4
- 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 +14 -18
- 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 +3 -7
- package/lib/parser/util.d.ts +30 -12
- package/lib/parser/util.js +78 -63
- 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 +5 -4
- package/lib/processor/checker/builtin.js +26 -28
- package/lib/processor/checker/index.d.ts +2 -2
- package/lib/processor/checker/index.js +2 -27
- 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 -27
- 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 +58 -74
- package/lib/processor/completer/index.d.ts +2 -2
- package/lib/processor/completer/index.js +2 -27
- 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 -27
- package/lib/processor/index.d.ts +9 -9
- package/lib/processor/index.js +9 -21
- 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 +23 -27
- package/lib/processor/linter/builtin.d.ts +3 -3
- package/lib/processor/linter/builtin.js +19 -31
- package/lib/processor/linter/index.d.ts +2 -2
- package/lib/processor/linter/index.js +2 -27
- 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 +38 -48
- package/lib/service/Config.d.ts +17 -16
- package/lib/service/Config.js +56 -51
- package/lib/service/Context.d.ts +14 -14
- package/lib/service/Context.js +30 -32
- package/lib/service/Dependency.js +2 -5
- package/lib/service/Downloader.d.ts +10 -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 +41 -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/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 +50 -51
- package/lib/service/Project.js +240 -238
- 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/fileUtil.d.ts +21 -41
- package/lib/service/fileUtil.js +59 -129
- package/lib/service/index.d.ts +17 -17
- package/lib/service/index.js +17 -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 +12 -4
- package/lib/source/Source.js +84 -29
- package/lib/source/index.d.ts +8 -8
- package/lib/source/index.js +8 -20
- package/lib/symbol/Symbol.d.ts +15 -15
- package/lib/symbol/Symbol.js +53 -68
- package/lib/symbol/SymbolUtil.d.ts +23 -33
- package/lib/symbol/SymbolUtil.js +162 -163
- 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 -15
- package/package.json +7 -4
- package/lib/common/Heap.d.ts +0 -1
- package/lib/common/Heap.js +0 -2
- package/lib/node/TableNode.d.ts +0 -17
- package/lib/node/TableNode.js +0 -11
- package/lib/parser/table.d.ts +0 -22
- package/lib/parser/table.js +0 -97
- package/lib/service/CommandExecutor.d.ts +0 -3
- package/lib/service/CommandExecutor.js +0 -7
|
@@ -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
|
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
|