@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,47 +1,26 @@
1
- "use strict";
2
1
  /* istanbul ignore file */
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
6
- }) : (function(o, m, k, k2) {
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
- let instance;
37
- function create() {
38
- return instance ?? (instance = new FileServiceImpl());
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 = exports.FileService || (exports.FileService = {}));
42
- class FileServiceImpl {
43
- constructor() {
44
- this.supporters = new Map();
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 common_1.Uri(uri).protocol;
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
- exports.FileServiceImpl = FileServiceImpl;
93
- class FileUriSupporter {
94
- constructor(roots, files) {
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 fs_1.promises.readFile(new common_1.Uri(uri));
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
- static rootUriToGlob(root) {
114
- return fileUtil_1.fileUtil.fileUriToPath(root) + '**/*';
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 (fileUtil_1.fileUtil.isFileUri(uri) && (await fs_1.promises.stat(new common_1.Uri(uri))).isDirectory()) {
122
- uri = fileUtil_1.fileUtil.ensureEndingSlash(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, (await (0, globby_1.default)(this.rootUriToGlob(uri), { absolute: true, dot: true })).map(fileUtil_1.fileUtil.pathToFileUri));
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
- exports.FileUriSupporter = FileUriSupporter;
135
- class SpyglassUriSupporter {
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 } = common_1.SpyglassUri.Archive.decode(new common_1.Uri(uri));
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 (0, common_1.getSha1)(await this.getDataInArchive(archiveUri, pathInArchive));
170
+ return this.externals.crypto.getSha1(this.getDataInArchive(archiveUri, pathInArchive));
152
171
  }
153
172
  }
154
173
  async readFile(uri) {
155
- const { archiveUri, pathInArchive } = common_1.SpyglassUri.Archive.decode(new common_1.Uri(uri));
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
- async getDataInArchive(archiveUri, pathInArchive) {
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 common_1.SpyglassUri.Archive.get(archiveUri, file.path);
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 common_1.SpyglassUri.Archive.get(archiveUri);
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:') && SpyglassUriSupporter.SupportedArchiveExtnames.some(ext => uri.endsWith(ext)) && (await fs_1.promises.stat(new common_1.Uri(uri))).isFile()) {
192
- const rootUri = common_1.SpyglassUri.Archive.get(uri);
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 (0, decompress_1.default)(fileUtil_1.fileUtil.fileUriToPath(uri), { strip: typeof info?.startDepth === 'number' ? info.startDepth : 0 });
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 SpyglassUriSupporter(entries);
244
+ return new ArchiveUriSupporter(externals, entries);
211
245
  }
212
246
  }
213
- exports.SpyglassUriSupporter = SpyglassUriSupporter;
214
- SpyglassUriSupporter.SupportedArchiveExtnames = ['.tar', '.tar.bz2', '.tar.gz', '.zip'];
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
@@ -1,5 +1,5 @@
1
- import type { RangeLike } from '../source';
2
- import { Range } from '../source';
1
+ import type { RangeLike } from '../source/index.js';
2
+ import { Range } from '../source/index.js';
3
3
  export interface Hover {
4
4
  range: Range;
5
5
  markdown: string;
@@ -1,16 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
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: source_1.Range.get(range),
7
+ range: Range.get(range),
11
8
  markdown,
12
9
  };
13
10
  }
14
11
  Hover.create = create;
15
- })(Hover = exports.Hover || (exports.Hover = {}));
12
+ })(Hover || (Hover = {}));
16
13
  //# sourceMappingURL=Hover.js.map
@@ -1,15 +1,15 @@
1
- import { Lazy } from '../common';
2
- import type { AstNode } from '../node';
3
- import type { Parser } from '../parser';
4
- import type { Checker, Colorizer, Completer, InlayHintProvider } from '../processor';
5
- import type { Formatter } from '../processor/formatter';
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 type { Logger } from '../common/index.js';
2
+ import { Lazy } from '../common/index.js';
3
+ import type { AstNode } from '../node/index.js';
4
+ import type { Parser } from '../parser/index.js';
5
+ import type { Formatter } from '../processor/formatter/index.js';
6
+ import type { Binder, Checker, Colorizer, Completer, InlayHintProvider } from '../processor/index.js';
7
+ import type { Linter } from '../processor/linter/Linter.js';
8
+ import type { SignatureHelpProvider } from '../processor/SignatureHelpProvider.js';
9
+ import type { DependencyKey, DependencyProvider } from './Dependency.js';
10
+ import type { FileExtension } from './fileUtil.js';
11
+ import type { SymbolRegistrar } from './SymbolRegistrar.js';
12
+ import type { UriBinder, UriSorter, UriSorterRegistration } from './UriProcessor.js';
13
13
  export interface LanguageOptions {
14
14
  /**
15
15
  * An array of extensions of files corresponding to the language. Each extension should include the leading dot (`.`).
@@ -58,6 +58,9 @@ export declare class MetaRegistry {
58
58
  * @returns The language ID registered for the file extension, or `undefined`.
59
59
  */
60
60
  getLanguageID(fileExtension: FileExtension): string | undefined;
61
+ hasBinder<N extends AstNode>(type: N['type']): boolean;
62
+ getBinder<N extends AstNode>(type: N['type']): Binder<N>;
63
+ registerBinder<N extends AstNode>(type: N['type'], binder: Binder<N>): void;
61
64
  hasChecker<N extends AstNode>(type: N['type']): boolean;
62
65
  getChecker<N extends AstNode>(type: N['type']): Checker<N>;
63
66
  registerChecker<N extends AstNode>(type: N['type'], checker: Checker<N>): void;
@@ -101,6 +104,8 @@ export declare class MetaRegistry {
101
104
  get symbolRegistrars(): Map<string, SymbolRegistrarRegistration>;
102
105
  registerUriBinder(uriBinder: UriBinder): void;
103
106
  get uriBinders(): Set<UriBinder>;
107
+ setUriSorter(uriSorter: UriSorterRegistration): void;
108
+ get uriSorter(): UriSorter;
104
109
  }
105
110
  export {};
106
111
  //# sourceMappingURL=MetaRegistry.d.ts.map
@@ -1,40 +1,34 @@
1
- "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 _MetaRegistry_languages, _MetaRegistry_checkers, _MetaRegistry_colorizers, _MetaRegistry_completers, _MetaRegistry_dependencyProviders, _MetaRegistry_formatters, _MetaRegistry_inlayHintProviders, _MetaRegistry_linters, _MetaRegistry_parsers, _MetaRegistry_signatureHelpProviders, _MetaRegistry_symbolRegistrars, _MetaRegistry_uriBinders;
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.MetaRegistry = void 0;
10
- const common_1 = require("../common");
11
- const processor_1 = require("../processor");
1
+ import { Lazy } from '../common/index.js';
2
+ import { binder, checker, colorizer, completer, formatter, linter } from '../processor/index.js';
12
3
  /* istanbul ignore next */
13
4
  /**
14
5
  * The meta registry of Spyglass. You can register new parsers, processors, and languages here.
15
6
  */
16
- class MetaRegistry {
7
+ export class MetaRegistry {
8
+ /**
9
+ * A map from language IDs to language options.
10
+ */
11
+ #languages = new Map();
12
+ #binders = new Map();
13
+ #checkers = new Map();
14
+ #colorizers = new Map();
15
+ #completers = new Map();
16
+ #dependencyProviders = new Map();
17
+ #formatters = new Map();
18
+ #inlayHintProviders = new Set();
19
+ #linters = new Map();
20
+ #parsers = new Map();
21
+ #signatureHelpProviders = new Set();
22
+ #symbolRegistrars = new Map();
23
+ #uriBinders = new Set();
24
+ #uriSorter = () => 0;
17
25
  constructor() {
18
- /**
19
- * A map from language IDs to language options.
20
- */
21
- _MetaRegistry_languages.set(this, new Map());
22
- _MetaRegistry_checkers.set(this, new Map());
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);
26
+ binder.registerBinders(this);
27
+ checker.registerCheckers(this);
28
+ colorizer.registerColorizers(this);
29
+ completer.registerCompleters(this);
30
+ formatter.registerFormatters(this);
31
+ linter.registerLinters(this);
38
32
  }
39
33
  /**
40
34
  * Registers a new language.
@@ -42,151 +36,165 @@ class MetaRegistry {
42
36
  * @param options The language options for this language.
43
37
  */
44
38
  registerLanguage(languageID, options) {
45
- __classPrivateFieldGet(this, _MetaRegistry_languages, "f").set(languageID, options);
39
+ this.#languages.set(languageID, options);
46
40
  }
47
41
  /**
48
42
  * An array of all registered language IDs.
49
43
  */
50
44
  getLanguages() {
51
- return Array.from(__classPrivateFieldGet(this, _MetaRegistry_languages, "f").keys());
45
+ return Array.from(this.#languages.keys());
52
46
  }
53
47
  isSupportedLanguage(language) {
54
- return __classPrivateFieldGet(this, _MetaRegistry_languages, "f").has(language);
48
+ return this.#languages.has(language);
55
49
  }
56
50
  /**
57
51
  * An array of file extensions (including the leading dot (`.`)) that are supported.
58
52
  */
59
53
  getSupportedFileExtensions() {
60
- return [...__classPrivateFieldGet(this, _MetaRegistry_languages, "f").values()].flatMap(v => v.extensions);
54
+ return [...this.#languages.values()].flatMap(v => v.extensions);
61
55
  }
62
56
  /**
63
57
  * An array of characters that trigger a completion request.
64
58
  */
65
59
  getTriggerCharacters() {
66
- return Array.from(__classPrivateFieldGet(this, _MetaRegistry_languages, "f").values()).flatMap(v => v.triggerCharacters ?? []);
60
+ return Array.from(this.#languages.values()).flatMap(v => v.triggerCharacters ?? []);
67
61
  }
68
62
  /**
69
63
  * @param fileExtension The file extension including the leading dot. e.g. `".mcfunction"`.
70
64
  * @returns The language ID registered for the file extension, or `undefined`.
71
65
  */
72
66
  getLanguageID(fileExtension) {
73
- for (const [languageID, { extensions }] of __classPrivateFieldGet(this, _MetaRegistry_languages, "f")) {
67
+ for (const [languageID, { extensions }] of this.#languages) {
74
68
  if (extensions.includes(fileExtension)) {
75
69
  return languageID;
76
70
  }
77
71
  }
78
72
  return undefined;
79
73
  }
74
+ hasBinder(type) {
75
+ return this.#binders.has(type);
76
+ }
77
+ getBinder(type) {
78
+ return this.#binders.get(type) ?? binder.fallback;
79
+ }
80
+ registerBinder(type, binder) {
81
+ this.#binders.set(type, binder);
82
+ }
80
83
  hasChecker(type) {
81
- return __classPrivateFieldGet(this, _MetaRegistry_checkers, "f").has(type);
84
+ return this.#checkers.has(type);
82
85
  }
83
86
  getChecker(type) {
84
- return __classPrivateFieldGet(this, _MetaRegistry_checkers, "f").get(type) ?? processor_1.checker.fallback;
87
+ return this.#checkers.get(type) ?? checker.fallback;
85
88
  }
86
89
  registerChecker(type, checker) {
87
- __classPrivateFieldGet(this, _MetaRegistry_checkers, "f").set(type, checker);
90
+ this.#checkers.set(type, checker);
88
91
  }
89
92
  hasColorizer(type) {
90
- return __classPrivateFieldGet(this, _MetaRegistry_colorizers, "f").has(type);
93
+ return this.#colorizers.has(type);
91
94
  }
92
95
  getColorizer(type) {
93
- return __classPrivateFieldGet(this, _MetaRegistry_colorizers, "f").get(type) ?? processor_1.colorizer.fallback;
96
+ return this.#colorizers.get(type) ?? colorizer.fallback;
94
97
  }
95
98
  registerColorizer(type, colorizer) {
96
- __classPrivateFieldGet(this, _MetaRegistry_colorizers, "f").set(type, colorizer);
99
+ this.#colorizers.set(type, colorizer);
97
100
  }
98
101
  hasCompleter(type) {
99
- return __classPrivateFieldGet(this, _MetaRegistry_completers, "f").has(type);
102
+ return this.#completers.has(type);
100
103
  }
101
104
  getCompleter(type) {
102
- return __classPrivateFieldGet(this, _MetaRegistry_completers, "f").get(type) ?? processor_1.completer.fallback;
105
+ return this.#completers.get(type) ?? completer.fallback;
103
106
  }
104
107
  registerCompleter(type, completer) {
105
- __classPrivateFieldGet(this, _MetaRegistry_completers, "f").set(type, completer);
108
+ this.#completers.set(type, completer);
106
109
  }
107
110
  shouldComplete(languageID, triggerCharacter) {
108
- const language = __classPrivateFieldGet(this, _MetaRegistry_languages, "f").get(languageID);
111
+ const language = this.#languages.get(languageID);
109
112
  return !triggerCharacter || !!language?.triggerCharacters?.includes(triggerCharacter);
110
113
  }
111
114
  getCompleterForLanguageID(languageID) {
112
- return __classPrivateFieldGet(this, _MetaRegistry_languages, "f").get(languageID)?.completer ?? processor_1.completer.fallback;
115
+ return this.#languages.get(languageID)?.completer ?? completer.fallback;
113
116
  }
114
117
  getDependencyProvider(key) {
115
- return __classPrivateFieldGet(this, _MetaRegistry_dependencyProviders, "f").get(key);
118
+ return this.#dependencyProviders.get(key);
116
119
  }
117
120
  registerDependencyProvider(key, provider) {
118
- __classPrivateFieldGet(this, _MetaRegistry_dependencyProviders, "f").set(key, provider);
121
+ this.#dependencyProviders.set(key, provider);
119
122
  }
120
123
  hasFormatter(type) {
121
- return __classPrivateFieldGet(this, _MetaRegistry_formatters, "f").has(type);
124
+ return this.#formatters.has(type);
122
125
  }
123
126
  getFormatter(type) {
124
- return __classPrivateFieldGet(this, _MetaRegistry_formatters, "f").get(type) ?? processor_1.formatter.fallback;
127
+ return this.#formatters.get(type) ?? formatter.fallback;
125
128
  }
126
129
  registerFormatter(type, formatter) {
127
- __classPrivateFieldGet(this, _MetaRegistry_formatters, "f").set(type, formatter);
130
+ this.#formatters.set(type, formatter);
128
131
  }
129
132
  registerInlayHintProvider(provider) {
130
- __classPrivateFieldGet(this, _MetaRegistry_inlayHintProviders, "f").add(provider);
133
+ this.#inlayHintProviders.add(provider);
131
134
  }
132
135
  get inlayHintProviders() {
133
- return __classPrivateFieldGet(this, _MetaRegistry_inlayHintProviders, "f");
136
+ return this.#inlayHintProviders;
134
137
  }
135
138
  getLinter(ruleName) {
136
- return __classPrivateFieldGet(this, _MetaRegistry_linters, "f").get(ruleName) ?? {
139
+ return this.#linters.get(ruleName) ?? {
137
140
  configValidator: () => false,
138
- linter: processor_1.linter.noop,
141
+ linter: linter.noop,
139
142
  nodePredicate: () => false,
140
143
  };
141
144
  }
142
145
  registerLinter(ruleName, options) {
143
- __classPrivateFieldGet(this, _MetaRegistry_linters, "f").set(ruleName, options);
146
+ this.#linters.set(ruleName, options);
144
147
  }
145
148
  hasParser(id) {
146
- return __classPrivateFieldGet(this, _MetaRegistry_parsers, "f").has(id);
149
+ return this.#parsers.has(id);
147
150
  }
148
151
  getParser(id) {
149
- const ans = __classPrivateFieldGet(this, _MetaRegistry_parsers, "f").get(id);
152
+ const ans = this.#parsers.get(id);
150
153
  if (!ans) {
151
154
  throw new Error(`There is no parser '${id}'`);
152
155
  }
153
156
  return ans;
154
157
  }
155
158
  getParserLazily(id) {
156
- return common_1.Lazy.create(() => this.getParser(id));
159
+ return Lazy.create(() => this.getParser(id));
157
160
  }
158
161
  registerParser(id, parser) {
159
- __classPrivateFieldGet(this, _MetaRegistry_parsers, "f").set(id, parser);
162
+ this.#parsers.set(id, parser);
160
163
  }
161
164
  /**
162
165
  * @returns The corresponding `Parser` for the language ID.
163
166
  * @throws If there's no such language in the registry.
164
167
  */
165
168
  getParserForLanguageId(languageID) {
166
- if (__classPrivateFieldGet(this, _MetaRegistry_languages, "f").has(languageID)) {
167
- return __classPrivateFieldGet(this, _MetaRegistry_languages, "f").get(languageID).parser;
169
+ if (this.#languages.has(languageID)) {
170
+ return this.#languages.get(languageID).parser;
168
171
  }
169
172
  throw new Error(`There is no parser registered for language ID '${languageID}'`);
170
173
  }
171
174
  registerSignatureHelpProvider(provider) {
172
- __classPrivateFieldGet(this, _MetaRegistry_signatureHelpProviders, "f").add(provider);
175
+ this.#signatureHelpProviders.add(provider);
173
176
  }
174
177
  get signatureHelpProviders() {
175
- return __classPrivateFieldGet(this, _MetaRegistry_signatureHelpProviders, "f");
178
+ return this.#signatureHelpProviders;
176
179
  }
177
180
  registerSymbolRegistrar(id, registrar) {
178
- __classPrivateFieldGet(this, _MetaRegistry_symbolRegistrars, "f").set(id, registrar);
181
+ this.#symbolRegistrars.set(id, registrar);
179
182
  }
180
183
  get symbolRegistrars() {
181
- return __classPrivateFieldGet(this, _MetaRegistry_symbolRegistrars, "f");
184
+ return this.#symbolRegistrars;
182
185
  }
183
186
  registerUriBinder(uriBinder) {
184
- __classPrivateFieldGet(this, _MetaRegistry_uriBinders, "f").add(uriBinder);
187
+ this.#uriBinders.add(uriBinder);
185
188
  }
186
189
  get uriBinders() {
187
- return __classPrivateFieldGet(this, _MetaRegistry_uriBinders, "f");
190
+ return this.#uriBinders;
191
+ }
192
+ setUriSorter(uriSorter) {
193
+ const nextSorter = this.#uriSorter;
194
+ this.#uriSorter = (a, b) => uriSorter(a, b, nextSorter);
195
+ }
196
+ get uriSorter() {
197
+ return this.#uriSorter;
188
198
  }
189
199
  }
190
- exports.MetaRegistry = MetaRegistry;
191
- _MetaRegistry_languages = new WeakMap(), _MetaRegistry_checkers = new WeakMap(), _MetaRegistry_colorizers = new WeakMap(), _MetaRegistry_completers = new WeakMap(), _MetaRegistry_dependencyProviders = new WeakMap(), _MetaRegistry_formatters = new WeakMap(), _MetaRegistry_inlayHintProviders = new WeakMap(), _MetaRegistry_linters = new WeakMap(), _MetaRegistry_parsers = new WeakMap(), _MetaRegistry_signatureHelpProviders = new WeakMap(), _MetaRegistry_symbolRegistrars = new WeakMap(), _MetaRegistry_uriBinders = new WeakMap();
192
200
  //# sourceMappingURL=MetaRegistry.js.map
@@ -1,4 +1,4 @@
1
- import { Logger } from './Logger';
1
+ import { Logger } from '../common/index.js';
2
2
  /**
3
3
  * @example
4
4
  * ```typescript
@@ -27,7 +27,8 @@ export declare class ProfilerFactory {
27
27
  #private;
28
28
  private readonly logger;
29
29
  constructor(logger: Logger, enabledProfilers: string[]);
30
- get(id: string): Profiler;
30
+ get(id: string, style: 'top-n', n: number): Profiler;
31
+ get(id: string, style?: 'total'): Profiler;
31
32
  static noop(): ProfilerFactory;
32
33
  }
33
34
  //# sourceMappingURL=Profiler.d.ts.map