@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.
Files changed (206) hide show
  1. package/README.md +7 -0
  2. package/lib/browser.d.ts +2 -0
  3. package/lib/browser.js +2 -0
  4. package/lib/common/Dev.d.ts +11 -0
  5. package/lib/common/Dev.js +90 -0
  6. package/lib/{service → common}/Logger.d.ts +0 -0
  7. package/lib/{service → common}/Logger.js +2 -5
  8. package/lib/common/Operations.d.ts +12 -0
  9. package/lib/common/Operations.js +33 -0
  10. package/lib/common/ReadonlyProxy.d.ts +9 -0
  11. package/lib/common/ReadonlyProxy.js +23 -0
  12. package/lib/common/StateProxy.d.ts +35 -0
  13. package/lib/common/StateProxy.js +69 -0
  14. package/lib/common/TwoWayMap.d.ts +21 -0
  15. package/lib/common/TwoWayMap.js +69 -0
  16. package/lib/common/externals/BrowserExternals.d.ts +3 -0
  17. package/lib/common/externals/BrowserExternals.js +191 -0
  18. package/lib/common/externals/NodeJsExternals.d.ts +3 -0
  19. package/lib/common/externals/NodeJsExternals.js +152 -0
  20. package/lib/common/externals/downloader.d.ts +31 -0
  21. package/lib/common/externals/downloader.js +32 -0
  22. package/lib/common/externals/index.d.ts +96 -0
  23. package/lib/common/externals/index.js +2 -0
  24. package/lib/common/index.d.ts +8 -1
  25. package/lib/common/index.js +8 -13
  26. package/lib/common/util.d.ts +50 -39
  27. package/lib/common/util.js +73 -122
  28. package/lib/index.d.ts +7 -7
  29. package/lib/index.js +7 -19
  30. package/lib/node/AstNode.d.ts +12 -11
  31. package/lib/node/AstNode.js +10 -16
  32. package/lib/node/BooleanNode.d.ts +2 -2
  33. package/lib/node/BooleanNode.js +4 -7
  34. package/lib/node/CommentNode.d.ts +6 -5
  35. package/lib/node/CommentNode.js +4 -9
  36. package/lib/node/ErrorNode.d.ts +1 -1
  37. package/lib/node/ErrorNode.js +2 -5
  38. package/lib/node/FileNode.d.ts +8 -4
  39. package/lib/node/FileNode.js +3 -6
  40. package/lib/node/FloatNode.d.ts +3 -3
  41. package/lib/node/FloatNode.js +4 -7
  42. package/lib/node/IntegerNode.d.ts +3 -3
  43. package/lib/node/IntegerNode.js +4 -7
  44. package/lib/node/ListNode.d.ts +2 -2
  45. package/lib/node/ListNode.js +2 -5
  46. package/lib/node/LiteralNode.d.ts +5 -5
  47. package/lib/node/LiteralNode.js +5 -8
  48. package/lib/node/LongNode.d.ts +3 -3
  49. package/lib/node/LongNode.js +4 -7
  50. package/lib/node/RecordNode.d.ts +2 -2
  51. package/lib/node/RecordNode.js +2 -5
  52. package/lib/node/ResourceLocationNode.d.ts +8 -10
  53. package/lib/node/ResourceLocationNode.js +9 -12
  54. package/lib/node/Sequence.d.ts +4 -3
  55. package/lib/node/Sequence.js +4 -6
  56. package/lib/node/StringNode.d.ts +5 -5
  57. package/lib/node/StringNode.js +9 -12
  58. package/lib/node/SymbolNode.d.ts +5 -5
  59. package/lib/node/SymbolNode.js +5 -8
  60. package/lib/node/index.d.ts +15 -15
  61. package/lib/node/index.js +15 -27
  62. package/lib/nodejs.d.ts +2 -0
  63. package/lib/nodejs.js +2 -0
  64. package/lib/parser/Parser.d.ts +3 -3
  65. package/lib/parser/Parser.js +1 -4
  66. package/lib/parser/boolean.d.ts +2 -2
  67. package/lib/parser/boolean.js +3 -6
  68. package/lib/parser/comment.d.ts +2 -2
  69. package/lib/parser/comment.js +5 -9
  70. package/lib/parser/empty.d.ts +1 -1
  71. package/lib/parser/empty.js +1 -5
  72. package/lib/parser/error.d.ts +2 -2
  73. package/lib/parser/error.js +5 -9
  74. package/lib/parser/file.d.ts +3 -3
  75. package/lib/parser/file.js +9 -13
  76. package/lib/parser/float.d.ts +4 -4
  77. package/lib/parser/float.js +12 -16
  78. package/lib/parser/index.d.ts +16 -16
  79. package/lib/parser/index.js +16 -34
  80. package/lib/parser/integer.d.ts +4 -4
  81. package/lib/parser/integer.js +10 -14
  82. package/lib/parser/list.d.ts +2 -2
  83. package/lib/parser/list.js +15 -19
  84. package/lib/parser/literal.d.ts +2 -2
  85. package/lib/parser/literal.js +5 -9
  86. package/lib/parser/long.d.ts +4 -4
  87. package/lib/parser/long.js +10 -14
  88. package/lib/parser/record.d.ts +3 -3
  89. package/lib/parser/record.js +20 -24
  90. package/lib/parser/resourceLocation.d.ts +2 -2
  91. package/lib/parser/resourceLocation.js +12 -24
  92. package/lib/parser/string.d.ts +7 -7
  93. package/lib/parser/string.js +40 -44
  94. package/lib/parser/symbol.d.ts +3 -3
  95. package/lib/parser/symbol.js +4 -14
  96. package/lib/parser/util.d.ts +30 -12
  97. package/lib/parser/util.js +78 -65
  98. package/lib/processor/ColorInfoProvider.d.ts +1 -1
  99. package/lib/processor/ColorInfoProvider.js +6 -9
  100. package/lib/processor/InlayHintProvider.d.ts +4 -3
  101. package/lib/processor/InlayHintProvider.js +1 -2
  102. package/lib/processor/SignatureHelpProvider.d.ts +4 -3
  103. package/lib/processor/SignatureHelpProvider.js +1 -2
  104. package/lib/processor/binder/Binder.d.ts +26 -0
  105. package/lib/processor/binder/Binder.js +18 -0
  106. package/lib/processor/binder/builtin.d.ts +27 -0
  107. package/lib/processor/binder/builtin.js +116 -0
  108. package/lib/processor/binder/index.d.ts +3 -0
  109. package/lib/processor/binder/index.js +3 -0
  110. package/lib/processor/checker/Checker.d.ts +2 -2
  111. package/lib/processor/checker/Checker.js +1 -5
  112. package/lib/processor/checker/builtin.d.ts +4 -4
  113. package/lib/processor/checker/builtin.js +22 -33
  114. package/lib/processor/checker/index.d.ts +2 -2
  115. package/lib/processor/checker/index.js +2 -27
  116. package/lib/processor/colorizer/Colorizer.d.ts +6 -5
  117. package/lib/processor/colorizer/Colorizer.js +8 -11
  118. package/lib/processor/colorizer/builtin.d.ts +3 -3
  119. package/lib/processor/colorizer/builtin.js +33 -46
  120. package/lib/processor/colorizer/index.d.ts +2 -2
  121. package/lib/processor/colorizer/index.js +2 -27
  122. package/lib/processor/completer/Completer.d.ts +6 -5
  123. package/lib/processor/completer/Completer.js +14 -33
  124. package/lib/processor/completer/builtin.d.ts +10 -9
  125. package/lib/processor/completer/builtin.js +59 -75
  126. package/lib/processor/completer/index.d.ts +2 -2
  127. package/lib/processor/completer/index.js +2 -27
  128. package/lib/processor/formatter/Formatter.d.ts +4 -3
  129. package/lib/processor/formatter/Formatter.js +2 -7
  130. package/lib/processor/formatter/builtin.d.ts +3 -3
  131. package/lib/processor/formatter/builtin.js +22 -36
  132. package/lib/processor/formatter/index.d.ts +2 -2
  133. package/lib/processor/formatter/index.js +2 -27
  134. package/lib/processor/index.d.ts +10 -9
  135. package/lib/processor/index.js +10 -21
  136. package/lib/processor/linter/Linter.d.ts +4 -3
  137. package/lib/processor/linter/Linter.js +1 -2
  138. package/lib/processor/linter/builtin/undeclaredSymbol.d.ts +2 -2
  139. package/lib/processor/linter/builtin/undeclaredSymbol.js +23 -27
  140. package/lib/processor/linter/builtin.d.ts +4 -3
  141. package/lib/processor/linter/builtin.js +19 -26
  142. package/lib/processor/linter/index.d.ts +2 -2
  143. package/lib/processor/linter/index.js +2 -27
  144. package/lib/processor/util.d.ts +4 -14
  145. package/lib/processor/util.js +1 -16
  146. package/lib/service/CacheService.d.ts +8 -6
  147. package/lib/service/CacheService.js +35 -56
  148. package/lib/service/Config.d.ts +17 -16
  149. package/lib/service/Config.js +56 -51
  150. package/lib/service/Context.d.ts +24 -21
  151. package/lib/service/Context.js +40 -36
  152. package/lib/service/Dependency.js +2 -5
  153. package/lib/service/Downloader.d.ts +9 -39
  154. package/lib/service/Downloader.js +37 -106
  155. package/lib/service/ErrorReporter.d.ts +2 -2
  156. package/lib/service/ErrorReporter.js +11 -15
  157. package/lib/service/FileService.d.ts +40 -14
  158. package/lib/service/FileService.js +107 -81
  159. package/lib/service/Hover.d.ts +2 -2
  160. package/lib/service/Hover.js +4 -7
  161. package/lib/service/MetaRegistry.d.ts +17 -12
  162. package/lib/service/MetaRegistry.js +81 -73
  163. package/lib/service/Profiler.d.ts +3 -2
  164. package/lib/service/Profiler.js +81 -45
  165. package/lib/service/Project.d.ts +101 -73
  166. package/lib/service/Project.js +438 -367
  167. package/lib/service/Service.d.ts +19 -29
  168. package/lib/service/Service.js +57 -53
  169. package/lib/service/SymbolLocations.d.ts +3 -3
  170. package/lib/service/SymbolLocations.js +4 -7
  171. package/lib/service/SymbolRegistrar.d.ts +1 -1
  172. package/lib/service/SymbolRegistrar.js +1 -2
  173. package/lib/service/UriProcessor.d.ts +5 -0
  174. package/lib/service/UriProcessor.js +2 -0
  175. package/lib/service/fileUtil.d.ts +21 -41
  176. package/lib/service/fileUtil.js +59 -129
  177. package/lib/service/index.d.ts +16 -17
  178. package/lib/service/index.js +16 -31
  179. package/lib/source/IndexMap.d.ts +1 -1
  180. package/lib/source/IndexMap.js +7 -10
  181. package/lib/source/LanguageError.d.ts +2 -2
  182. package/lib/source/LanguageError.js +3 -6
  183. package/lib/source/Location.d.ts +3 -3
  184. package/lib/source/Location.js +6 -9
  185. package/lib/source/Offset.d.ts +1 -1
  186. package/lib/source/Offset.js +4 -7
  187. package/lib/source/Position.js +2 -5
  188. package/lib/source/PositionRange.d.ts +2 -2
  189. package/lib/source/PositionRange.js +14 -17
  190. package/lib/source/Range.d.ts +1 -1
  191. package/lib/source/Range.js +7 -10
  192. package/lib/source/Source.d.ts +9 -4
  193. package/lib/source/Source.js +58 -31
  194. package/lib/source/index.d.ts +8 -8
  195. package/lib/source/index.js +8 -20
  196. package/lib/symbol/Symbol.d.ts +15 -14
  197. package/lib/symbol/Symbol.js +53 -68
  198. package/lib/symbol/SymbolUtil.d.ts +30 -39
  199. package/lib/symbol/SymbolUtil.js +189 -168
  200. package/lib/symbol/index.d.ts +2 -3
  201. package/lib/symbol/index.js +2 -15
  202. package/package.json +7 -4
  203. package/lib/service/Operations.d.ts +0 -8
  204. package/lib/service/Operations.js +0 -26
  205. package/lib/symbol/UriBinder.d.ts +0 -3
  206. package/lib/symbol/UriBinder.js +0 -3
@@ -1,64 +1,44 @@
1
- "use strict";
2
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
- };
7
- var __importDefault = (this && this.__importDefault) || function (mod) {
8
- return (mod && mod.__esModule) ? mod : { "default": mod };
9
- };
10
- var _Downloader_memoryCache;
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.LowLevelDownloader = exports.Downloader = exports.RemoteUriString = void 0;
13
- const follow_redirects_1 = require("follow-redirects");
14
- const fs_1 = require("fs");
15
- const path_1 = __importDefault(require("path"));
16
- const perf_hooks_1 = require("perf_hooks");
17
- const common_1 = require("../common");
18
- const fileUtil_1 = require("./fileUtil");
19
- var RemoteUriString;
20
- (function (RemoteUriString) {
21
- function getProtocol(uri) {
22
- return uri.slice(0, uri.indexOf(':') + 1);
23
- }
24
- RemoteUriString.getProtocol = getProtocol;
25
- })(RemoteUriString = exports.RemoteUriString || (exports.RemoteUriString = {}));
26
- class Downloader {
27
- constructor(cacheRoot, logger, lld = LowLevelDownloader.create()) {
1
+ import { bufferToString, Uri } from '../common/index.js';
2
+ import { fileUtil } from './fileUtil.js';
3
+ export class Downloader {
4
+ cacheRoot;
5
+ externals;
6
+ logger;
7
+ #memoryCache = new Map();
8
+ constructor(cacheRoot, externals, logger) {
28
9
  this.cacheRoot = cacheRoot;
10
+ this.externals = externals;
29
11
  this.logger = logger;
30
- this.lld = lld;
31
- _Downloader_memoryCache.set(this, new Map());
32
12
  }
33
13
  async download(job, out = {}) {
34
14
  const { id, cache, uri, options, transformer, ttl } = job;
35
- if (ttl && __classPrivateFieldGet(this, _Downloader_memoryCache, "f").has(uri)) {
36
- const { buffer, time } = __classPrivateFieldGet(this, _Downloader_memoryCache, "f").get(uri);
37
- if (time <= perf_hooks_1.performance.now() + ttl) {
15
+ if (ttl && this.#memoryCache.has(uri)) {
16
+ const { buffer, time } = this.#memoryCache.get(uri);
17
+ if (time <= performance.now() + ttl) {
38
18
  this.logger.info(`[Downloader] [${id}] Skipped thanks to valid cache in memory`);
39
19
  return await transformer(buffer);
40
20
  }
41
21
  else {
42
- __classPrivateFieldGet(this, _Downloader_memoryCache, "f").delete(uri);
22
+ this.#memoryCache.delete(uri);
43
23
  }
44
24
  }
45
25
  let checksum;
46
- let cachePath;
47
- let cacheChecksumPath;
26
+ let cacheUri;
27
+ let cacheChecksumUri;
48
28
  if (cache) {
49
29
  const { checksumJob, checksumExtension } = cache;
50
- out.cachePath = cachePath = path_1.default.join(this.cacheRoot, 'downloader', id);
51
- cacheChecksumPath = path_1.default.join(this.cacheRoot, 'downloader', id + checksumExtension);
30
+ out.cacheUri = cacheUri = new Uri(`downloader/${id}`, this.cacheRoot).toString();
31
+ cacheChecksumUri = new Uri(`downloader/${id}${checksumExtension}`, this.cacheRoot).toString();
52
32
  try {
53
33
  out.checksum = checksum = await this.download({ ...checksumJob, id: id + checksumExtension });
54
34
  try {
55
- const cacheChecksum = (0, common_1.bufferToString)(await fileUtil_1.fileUtil.readFile(fileUtil_1.fileUtil.pathToFileUri(cacheChecksumPath)))
35
+ const cacheChecksum = bufferToString(await fileUtil.readFile(this.externals, cacheChecksumUri))
56
36
  .slice(0, -1); // Remove ending newline
57
37
  if (checksum === cacheChecksum) {
58
38
  try {
59
- const cachedBuffer = await fileUtil_1.fileUtil.readFile(fileUtil_1.fileUtil.pathToFileUri(cachePath));
39
+ const cachedBuffer = await fileUtil.readFile(this.externals, cacheUri);
60
40
  if (ttl) {
61
- __classPrivateFieldGet(this, _Downloader_memoryCache, "f").set(uri, { buffer: cachedBuffer, time: perf_hooks_1.performance.now() });
41
+ this.#memoryCache.set(uri, { buffer: cachedBuffer, time: performance.now() });
62
42
  }
63
43
  const deserializer = cache.deserializer ?? (b => b);
64
44
  const ans = await transformer(deserializer(cachedBuffer));
@@ -66,23 +46,23 @@ class Downloader {
66
46
  return ans;
67
47
  }
68
48
  catch (e) {
69
- this.logger.error(`[Downloader] [${id}] Loading cached file “${cachePath}”`, e);
70
- if ((0, common_1.isEnoent)(e)) {
49
+ this.logger.error(`[Downloader] [${id}] Loading cached file “${cacheUri}”`, e);
50
+ if (this.externals.error.isKind(e, 'ENOENT')) {
71
51
  // Cache checksum exists, but cached file doesn't.
72
52
  // Remove the invalid cache checksum.
73
53
  try {
74
- await fs_1.promises.unlink(cacheChecksumPath);
54
+ await this.externals.fs.unlink(cacheChecksumUri);
75
55
  }
76
56
  catch (e) {
77
- this.logger.error(`[Downloader] [${id}] Removing invalid cache checksum “${cacheChecksumPath}”`, e);
57
+ this.logger.error(`[Downloader] [${id}] Removing invalid cache checksum “${cacheChecksumUri}”`, e);
78
58
  }
79
59
  }
80
60
  }
81
61
  }
82
62
  }
83
63
  catch (e) {
84
- if (!(0, common_1.isEnoent)(e)) {
85
- this.logger.error(`[Downloader] [${id}] Loading cache checksum “${cacheChecksumPath}”`, e);
64
+ if (!this.externals.error.isKind(e, 'ENOENT')) {
65
+ this.logger.error(`[Downloader] [${id}] Loading cache checksum “${cacheChecksumUri}”`, e);
86
66
  }
87
67
  }
88
68
  }
@@ -91,25 +71,25 @@ class Downloader {
91
71
  }
92
72
  }
93
73
  try {
94
- const buffer = await this.lld.get(uri, options);
74
+ const buffer = await this.externals.downloader.get(uri, options);
95
75
  if (ttl) {
96
- __classPrivateFieldGet(this, _Downloader_memoryCache, "f").set(uri, { buffer, time: perf_hooks_1.performance.now() });
76
+ this.#memoryCache.set(uri, { buffer, time: performance.now() });
97
77
  }
98
- if (cache && cachePath && cacheChecksumPath) {
78
+ if (cache && cacheUri && cacheChecksumUri) {
99
79
  if (checksum) {
100
80
  try {
101
- await fileUtil_1.fileUtil.writeFile(fileUtil_1.fileUtil.pathToFileUri(cacheChecksumPath), `${checksum}\n`);
81
+ await fileUtil.writeFile(this.externals, cacheChecksumUri, `${checksum}\n`);
102
82
  }
103
83
  catch (e) {
104
- this.logger.error(`[Downloader] [${id}] Saving cache checksum “${cacheChecksumPath}”`, e);
84
+ this.logger.error(`[Downloader] [${id}] Saving cache checksum “${cacheChecksumUri}”`, e);
105
85
  }
106
86
  }
107
87
  try {
108
88
  const serializer = cache.serializer ?? (b => b);
109
- await fileUtil_1.fileUtil.writeFile(fileUtil_1.fileUtil.pathToFileUri(cachePath), serializer(buffer));
89
+ await fileUtil.writeFile(this.externals, cacheUri, serializer(buffer));
110
90
  }
111
91
  catch (e) {
112
- this.logger.error(`[Downloader] [${id}] Caching file “${cachePath}”`, e);
92
+ this.logger.error(`[Downloader] [${id}] Caching file “${cacheUri}”`, e);
113
93
  }
114
94
  }
115
95
  this.logger.info(`[Downloader] [${id}] Downloaded from “${uri}”`);
@@ -117,69 +97,20 @@ class Downloader {
117
97
  }
118
98
  catch (e) {
119
99
  this.logger.error(`[Downloader] [${id}] Downloading “${uri}”`, e);
120
- if (cache && cachePath) {
100
+ if (cache && cacheUri) {
121
101
  try {
122
- const cachedBuffer = await fileUtil_1.fileUtil.readFile(fileUtil_1.fileUtil.pathToFileUri(cachePath));
102
+ const cachedBuffer = await fileUtil.readFile(this.externals, cacheUri);
123
103
  const deserializer = cache.deserializer ?? (b => b);
124
104
  const ans = await transformer(deserializer(cachedBuffer));
125
- this.logger.warn(`[Downloader] [${id}] Fell back to cached file “${cachePath}”`);
105
+ this.logger.warn(`[Downloader] [${id}] Fell back to cached file “${cacheUri}”`);
126
106
  return ans;
127
107
  }
128
108
  catch (e) {
129
- this.logger.error(`[Downloader] [${id}] Fallback: loading cached file “${cachePath}”`, e);
109
+ this.logger.error(`[Downloader] [${id}] Fallback: loading cached file “${cacheUri}”`, e);
130
110
  }
131
111
  }
132
112
  }
133
113
  return undefined;
134
114
  }
135
115
  }
136
- exports.Downloader = Downloader;
137
- _Downloader_memoryCache = new WeakMap();
138
- var LowLevelDownloader;
139
- (function (LowLevelDownloader) {
140
- function create() {
141
- return new LowLevelDownloaderImpl();
142
- }
143
- LowLevelDownloader.create = create;
144
- function mock(options) {
145
- return new LowLevelDownloaderMock(options);
146
- }
147
- LowLevelDownloader.mock = mock;
148
- })(LowLevelDownloader = exports.LowLevelDownloader || (exports.LowLevelDownloader = {}));
149
- class LowLevelDownloaderImpl {
150
- get(uri, options = {}) {
151
- const protocol = RemoteUriString.getProtocol(uri);
152
- return new Promise((resolve, reject) => {
153
- const backend = protocol === 'http:' ? follow_redirects_1.http : follow_redirects_1.https;
154
- backend.get(uri, options, (res) => {
155
- if (res.statusCode !== 200) {
156
- reject(new Error(`Status code ${res.statusCode}: ${res.statusMessage}`));
157
- }
158
- else {
159
- resolve((0, common_1.promisifyAsyncIterable)(res, chunks => Buffer.concat(chunks)));
160
- }
161
- });
162
- });
163
- }
164
- }
165
- class LowLevelDownloaderMock {
166
- constructor(options) {
167
- this.options = options;
168
- }
169
- async get(uri) {
170
- if (!this.options.fixtures[uri]) {
171
- throw new Error(`404 not found: ${uri}`);
172
- }
173
- const fixture = this.options.fixtures[uri];
174
- if (Buffer.isBuffer(fixture)) {
175
- return fixture;
176
- }
177
- else if (typeof fixture === 'string') {
178
- return Buffer.from(fixture, 'utf-8');
179
- }
180
- else {
181
- return Buffer.from(JSON.stringify(fixture), 'utf-8');
182
- }
183
- }
184
- }
185
116
  //# sourceMappingURL=Downloader.js.map
@@ -1,5 +1,5 @@
1
- import type { LanguageErrorInfo, RangeLike } from '../source';
2
- import { ErrorSeverity, LanguageError } from '../source';
1
+ import type { LanguageErrorInfo, RangeLike } from '../source/index.js';
2
+ import { ErrorSeverity, LanguageError } from '../source/index.js';
3
3
  export declare class ErrorReporter {
4
4
  errors: LanguageError[];
5
5
  constructor();
@@ -1,17 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LinterErrorReporter = exports.ErrorReporter = void 0;
4
- const locales_1 = require("@spyglassmc/locales");
5
- const source_1 = require("../source");
6
- class ErrorReporter {
7
- constructor() {
8
- this.errors = [];
9
- }
1
+ import { localize } from '@spyglassmc/locales';
2
+ import { LanguageError, Range } from '../source/index.js';
3
+ export class ErrorReporter {
4
+ errors = [];
5
+ constructor() { }
10
6
  /**
11
7
  * Reports a new error.
12
8
  */
13
- report(message, range, severity = 3 /* Error */, info) {
14
- this.errors.push(source_1.LanguageError.create(message, source_1.Range.get(range), severity, info));
9
+ report(message, range, severity = 3 /* ErrorSeverity.Error */, info) {
10
+ this.errors.push(LanguageError.create(message, Range.get(range), severity, info));
15
11
  }
16
12
  /**
17
13
  * @returns All reported errors, and then clears the error stack.
@@ -29,15 +25,16 @@ class ErrorReporter {
29
25
  this.errors.push(...reporter.errors);
30
26
  }
31
27
  }
32
- exports.ErrorReporter = ErrorReporter;
33
- class LinterErrorReporter extends ErrorReporter {
28
+ export class LinterErrorReporter extends ErrorReporter {
29
+ ruleName;
30
+ ruleSeverity;
34
31
  constructor(ruleName, ruleSeverity) {
35
32
  super();
36
33
  this.ruleName = ruleName;
37
34
  this.ruleSeverity = ruleSeverity;
38
35
  }
39
36
  lint(message, range, info, severityOverride) {
40
- return this.report((0, locales_1.localize)('linter.diagnostic-message-wrapper', message, this.ruleName), range, severityOverride ?? this.ruleSeverity, info);
37
+ return this.report(localize('linter.diagnostic-message-wrapper', message, this.ruleName), range, severityOverride ?? this.ruleSeverity, info);
41
38
  }
42
39
  static fromErrorReporter(reporter, ruleName, ruleSeverity) {
43
40
  const ans = new LinterErrorReporter(ruleName, ruleSeverity);
@@ -45,5 +42,4 @@ class LinterErrorReporter extends ErrorReporter {
45
42
  return ans;
46
43
  }
47
44
  }
48
- exports.LinterErrorReporter = LinterErrorReporter;
49
45
  //# sourceMappingURL=ErrorReporter.js.map
@@ -1,7 +1,6 @@
1
- /// <reference types="node" />
2
- import type { Dependency } from './Dependency';
3
- import type { RootUriString } from './fileUtil';
4
- import type { Logger } from './Logger';
1
+ import type { Externals, Logger } from '../common/index.js';
2
+ import type { Dependency } from './Dependency.js';
3
+ import type { RootUriString } from './fileUtil.js';
5
4
  export interface UriProtocolSupporter {
6
5
  /**
7
6
  * @throws
@@ -16,7 +15,7 @@ export interface UriProtocolSupporter {
16
15
  * @returns The content of the file at `uri`.
17
16
  * @throws If the URI doesn't exist in the file system.
18
17
  */
19
- readFile(uri: string): Promise<Buffer>;
18
+ readFile(uri: string): Promise<Uint8Array>;
20
19
  listFiles(): Iterable<string>;
21
20
  /**
22
21
  * Each URI in this array must end with a slash (`/`).
@@ -37,12 +36,29 @@ export interface FileService extends UriProtocolSupporter {
37
36
  * Unregister the supported associated with `protocol`. Nothing happens if the `protocol` isn't supported.
38
37
  */
39
38
  unregister(protocol: Protocol): void;
39
+ /**
40
+ * Map the item at `uri` to physical disk.
41
+ *
42
+ * @returns The `file:` URI of the mapped file, or `undefined` if it cannot be mapped.
43
+ */
44
+ mapToDisk(uri: string): Promise<string | undefined>;
45
+ /**
46
+ * Map the item at `uri` from physical disk back to a (virtual) URI used by Spyglass internally.
47
+ */
48
+ mapFromDisk(uri: string): string;
40
49
  }
41
50
  export declare namespace FileService {
42
- function create(): FileService;
51
+ function create(externals: Externals, cacheRoot: RootUriString): FileService;
43
52
  }
44
53
  export declare class FileServiceImpl implements FileService {
54
+ private readonly externals;
55
+ private readonly virtualUrisRoot?;
45
56
  private readonly supporters;
57
+ /**
58
+ * A two-way map from mapped physical URIs to virtual URIs.
59
+ */
60
+ private readonly map;
61
+ constructor(externals: Externals, virtualUrisRoot?: `${string}/` | undefined);
46
62
  register(protocol: Protocol, supporter: UriProtocolSupporter, force?: boolean): void;
47
63
  unregister(protocol: Protocol): void;
48
64
  /**
@@ -58,39 +74,49 @@ export declare class FileServiceImpl implements FileService {
58
74
  /**
59
75
  * @throws
60
76
  */
61
- readFile(uri: string): Promise<Buffer>;
77
+ readFile(uri: string): Promise<Uint8Array>;
62
78
  listFiles(): Generator<string, void, undefined>;
63
79
  listRoots(): Generator<`${string}/`, void, undefined>;
80
+ mapToDisk(virtualUri: string): Promise<string | undefined>;
81
+ mapFromDisk(mappedUri: string): string;
64
82
  }
65
83
  export declare class FileUriSupporter implements UriProtocolSupporter {
84
+ private readonly externals;
66
85
  private readonly roots;
67
86
  private readonly files;
68
87
  readonly protocol = "file:";
69
88
  private constructor();
70
89
  hash(uri: string): Promise<string>;
71
- readFile(uri: string): Promise<Buffer>;
90
+ readFile(uri: string): Promise<Uint8Array>;
72
91
  listFiles(): Generator<string, void, undefined>;
73
92
  listRoots(): `${string}/`[];
74
- private static rootUriToGlob;
75
- static create(dependencies: readonly Dependency[], logger: Logger): Promise<FileUriSupporter>;
93
+ mapToDisk(uri: string): Promise<string | undefined>;
94
+ static create(dependencies: readonly Dependency[], externals: Externals, logger: Logger): Promise<FileUriSupporter>;
76
95
  }
77
- export declare class SpyglassUriSupporter implements UriProtocolSupporter {
96
+ export declare class ArchiveUriSupporter implements UriProtocolSupporter {
97
+ private readonly externals;
78
98
  private readonly entries;
79
- readonly protocol = "spyglassmc:";
99
+ static readonly Protocol = "archive:";
80
100
  private static readonly SupportedArchiveExtnames;
101
+ readonly protocol = "archive:";
81
102
  /**
82
103
  * @param entries A map from archive URIs to unzipped entries.
83
104
  */
84
105
  private constructor();
85
106
  hash(uri: string): Promise<string>;
86
- readFile(uri: string): Promise<Buffer>;
107
+ readFile(uri: string): Promise<Uint8Array>;
87
108
  /**
88
109
  * @throws
89
110
  */
90
111
  private getDataInArchive;
91
112
  listFiles(): Generator<string, void, unknown>;
92
113
  listRoots(): Generator<`${string}/`, void, unknown>;
93
- static create(dependencies: readonly Dependency[], logger: Logger, checksums: Record<RootUriString, string>): Promise<SpyglassUriSupporter>;
114
+ private static getUri;
115
+ /**
116
+ * @throws When `uri` has the wrong protocol or hostname.
117
+ */
118
+ private static decodeUri;
119
+ static create(dependencies: readonly Dependency[], externals: Externals, logger: Logger, checksums: Record<RootUriString, string>): Promise<ArchiveUriSupporter>;
94
120
  }
95
121
  export {};
96
122
  //# sourceMappingURL=FileService.d.ts.map