typescript 7.1.0-dev.20260923.1 → 7.1.0-dev.20260925.1

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 (39) hide show
  1. package/dist/api/async/api.d.ts +79 -6
  2. package/dist/api/async/api.d.ts.map +1 -1
  3. package/dist/api/async/api.js +200 -29
  4. package/dist/api/async/api.js.map +1 -1
  5. package/dist/api/async/client.d.ts +1 -0
  6. package/dist/api/async/client.d.ts.map +1 -1
  7. package/dist/api/async/client.js +7 -0
  8. package/dist/api/async/client.js.map +1 -1
  9. package/dist/api/node/node.d.ts +1 -1
  10. package/dist/api/node/node.d.ts.map +1 -1
  11. package/dist/api/node/node.infrastructure.d.ts +1 -0
  12. package/dist/api/node/node.infrastructure.d.ts.map +1 -1
  13. package/dist/api/node/node.infrastructure.js +11 -1
  14. package/dist/api/node/node.infrastructure.js.map +1 -1
  15. package/dist/api/node/node.js +1 -1
  16. package/dist/api/node/node.js.map +1 -1
  17. package/dist/api/node/protocol.d.ts +5 -2
  18. package/dist/api/node/protocol.d.ts.map +1 -1
  19. package/dist/api/node/protocol.js +5 -2
  20. package/dist/api/node/protocol.js.map +1 -1
  21. package/dist/api/proto.generated.d.ts +47 -3
  22. package/dist/api/proto.generated.d.ts.map +1 -1
  23. package/dist/api/sourceFileCache.d.ts +15 -6
  24. package/dist/api/sourceFileCache.d.ts.map +1 -1
  25. package/dist/api/sourceFileCache.js +59 -27
  26. package/dist/api/sourceFileCache.js.map +1 -1
  27. package/dist/api/sync/api.d.ts +95 -8
  28. package/dist/api/sync/api.d.ts.map +1 -1
  29. package/dist/api/sync/api.js +288 -56
  30. package/dist/api/sync/api.js.map +1 -1
  31. package/dist/api/sync/client.d.ts +1 -0
  32. package/dist/api/sync/client.d.ts.map +1 -1
  33. package/dist/api/sync/client.js +4 -0
  34. package/dist/api/sync/client.js.map +1 -1
  35. package/dist/api/syncChannel.d.ts +1 -0
  36. package/dist/api/syncChannel.d.ts.map +1 -1
  37. package/dist/api/syncChannel.js +3 -0
  38. package/dist/api/syncChannel.js.map +1 -1
  39. package/package.json +9 -9
@@ -21,7 +21,7 @@ import { TypePredicateKind } from "#enums/typePredicateKind";
21
21
  import { ModifierFlags, unescapeLeadingUnderscores, } from "../../ast/index.js";
22
22
  import { assertNever } from "../../internal/utils.js";
23
23
  import { encodeNode, uint8ArrayToBase64, } from "../node/encoder.js";
24
- import { decodeNode, getNodeId, parseNodeHandle, readParseOptionsKey, readSourceFileHash, RemoteSourceFile, } from "../node/node.js";
24
+ import { decodeNode, getNodeId, parseNodeHandle, readParseOptionsKey, readSourceFileHash, readSourceFileLease, RemoteSourceFile, } from "../node/node.js";
25
25
  import { Wtf8Decoder } from "../node/wtf8.js";
26
26
  import { createGetCanonicalFileName, toPath, } from "../path.js";
27
27
  import { resolveFileName, toCreateSnapshotRequest, } from "../proto.js";
@@ -30,6 +30,22 @@ import { Client, } from "./client.js";
30
30
  export { formatDiagnostics, formatDiagnosticsWithColorAndContext } from "../diagnosticFormatter.js";
31
31
  export { documentURIToFileName, fileNameToDocumentURI } from "../path.js";
32
32
  export { CheckFlags, CompletionItemKind, DiagnosticCategory, ElementFlags, EmitOnly, IndexKind, JsxEmit, ModifierFlags, ModuleKind, ModuleResolutionKind, NodeBuilderFlags, ObjectFlags, ScriptKind, SignatureFlags, SignatureKind, SymbolFlags, TypeFlags, TypeFormatFlags, TypePredicateKind };
33
+ let nextModuleResolutionCallbackId = 0;
34
+ function registerModuleResolutionCallback(client, callback, getSnapshot) {
35
+ const name = `resolveModuleName/${++nextModuleResolutionCallbackId}`;
36
+ const dispose = client.registerCallback(name, params => {
37
+ const { moduleName, containingDirectory, resolutionMode, snapshot: snapshotId, inProgressSnapshot } = params;
38
+ let snapshot = snapshotId === undefined ? undefined : getSnapshot(snapshotId);
39
+ if (snapshotId !== undefined && snapshot === undefined) {
40
+ throw new Error(`Snapshot ${snapshotId} is inactive`);
41
+ }
42
+ if (inProgressSnapshot !== undefined) {
43
+ snapshot = -inProgressSnapshot;
44
+ }
45
+ return callback(moduleName, containingDirectory, resolutionMode, { snapshot });
46
+ });
47
+ return { name, dispose };
48
+ }
33
49
  export { all, defer } from "./generatorSupport.js";
34
50
  import { sourceFileResponseToUint8Array } from "../node/encoder.js";
35
51
  import { executeRequestGenerators, } from "./generatorSupport.js";
@@ -42,7 +58,8 @@ export class API {
42
58
  getCanonicalFileNameWorker;
43
59
  initialized = false;
44
60
  initializing;
45
- activeSnapshots = new Set();
61
+ activeSnapshots = new Map();
62
+ activeSourceFileLeases = new Map();
46
63
  printer;
47
64
  internal;
48
65
  constructor(options = {}) {
@@ -169,6 +186,10 @@ export class API {
169
186
  return yield* apiRequest("parseJsonConfigFileContent", { json, ...options });
170
187
  });
171
188
  }
189
+ /**
190
+ * Create and retain a source file independently of a program.
191
+ * Dispose the returned lease when the source file no longer needs to remain available remotely.
192
+ */
172
193
  get createSourceFile() {
173
194
  const owner = this;
174
195
  return cacheGeneratorMethod(owner, "createSourceFile", function (fileName, sourceText, options = {}) {
@@ -177,16 +198,20 @@ export class API {
177
198
  if (!data) {
178
199
  throw new Error("createSourceFile returned no source file");
179
200
  }
180
- return new RemoteSourceFile(data, owner.decoder, owner.client.getTimingCollector());
201
+ return owner.retainSourceFileResponse(data);
181
202
  }, function* (fileName, sourceText, options = {}) {
182
203
  yield* owner.ensureInitialized.gen();
183
204
  const data = sourceFileResponseToUint8Array(yield* apiRequest("createSourceFile", { fileName, sourceText, options }));
184
205
  if (!data) {
185
206
  throw new Error("createSourceFile returned no source file");
186
207
  }
187
- return new RemoteSourceFile(data, owner.decoder, owner.client.getTimingCollector());
208
+ return owner.retainSourceFileResponse(data);
188
209
  });
189
210
  }
211
+ /**
212
+ * Read, create, and retain a source file independently of a program.
213
+ * Dispose the returned lease when the source file no longer needs to remain available remotely.
214
+ */
190
215
  get createSourceFileFromFile() {
191
216
  const owner = this;
192
217
  return cacheGeneratorMethod(owner, "createSourceFileFromFile", function (file, options = {}) {
@@ -195,16 +220,37 @@ export class API {
195
220
  if (!data) {
196
221
  throw new Error("createSourceFileFromFile returned no source file");
197
222
  }
198
- return new RemoteSourceFile(data, owner.decoder, owner.client.getTimingCollector());
223
+ return owner.retainSourceFileResponse(data);
199
224
  }, function* (file, options = {}) {
200
225
  yield* owner.ensureInitialized.gen();
201
226
  const data = sourceFileResponseToUint8Array(yield* apiRequest("createSourceFileFromFile", { fileName: resolveFileName(file), options }));
202
227
  if (!data) {
203
228
  throw new Error("createSourceFileFromFile returned no source file");
204
229
  }
205
- return new RemoteSourceFile(data, owner.decoder, owner.client.getTimingCollector());
230
+ return owner.retainSourceFileResponse(data);
206
231
  });
207
232
  }
233
+ retainSourceFileResponse(data) {
234
+ const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
235
+ const lease = readSourceFileLease(view);
236
+ try {
237
+ const decoded = new RemoteSourceFile(data, this.decoder, this.client.getTimingCollector());
238
+ const sourceFile = this.sourceFileCache.setForLease(decoded.path, decoded, readParseOptionsKey(view), readSourceFileHash(view), lease);
239
+ const retained = new RetainedSourceFile(sourceFile, lease, this.client, () => {
240
+ this.activeSourceFileLeases.delete(lease);
241
+ this.sourceFileCache.releaseLease(lease);
242
+ });
243
+ this.activeSourceFileLeases.set(lease, retained);
244
+ return retained;
245
+ }
246
+ catch (error) {
247
+ try {
248
+ this.client.apiRequest("releaseSourceFile", { lease });
249
+ }
250
+ catch { }
251
+ throw error;
252
+ }
253
+ }
208
254
  get transpileModule() {
209
255
  const owner = this;
210
256
  return cacheGeneratorMethod(owner, "transpileModule", function (input, options = {}) {
@@ -249,24 +295,24 @@ export class API {
249
295
  const owner = this;
250
296
  function createSnapshot(params) {
251
297
  owner.ensureInitialized();
252
- const requestParams = toCreateSnapshotRequest(params);
298
+ const requestParams = toCreateSnapshotRequest(owner.prepareCreateSnapshotParams(params));
253
299
  const data = owner.client.apiRequest("createSnapshot", requestParams);
254
300
  const snapshot = new Snapshot(data, owner.client, owner.sourceFileCache, owner.toPath, owner, () => {
255
- owner.activeSnapshots.delete(snapshot);
301
+ owner.activeSnapshots.delete(snapshot.id);
256
302
  owner.sourceFileCache.releaseSnapshot(snapshot.id);
257
303
  }, owner.createSnapshotUpdater(() => snapshot), undefined);
258
- owner.activeSnapshots.add(snapshot);
304
+ owner.activeSnapshots.set(snapshot.id, snapshot);
259
305
  return snapshot;
260
306
  }
261
307
  function* gen(params) {
262
308
  yield* owner.ensureInitialized.gen();
263
- const requestParams = toCreateSnapshotRequest(params);
309
+ const requestParams = toCreateSnapshotRequest(owner.prepareCreateSnapshotParams(params));
264
310
  const data = yield* apiRequest("createSnapshot", requestParams);
265
311
  const snapshot = new Snapshot(data, owner.client, owner.sourceFileCache, owner.toPath, owner, () => {
266
- owner.activeSnapshots.delete(snapshot);
312
+ owner.activeSnapshots.delete(snapshot.id);
267
313
  owner.sourceFileCache.releaseSnapshot(snapshot.id);
268
314
  }, owner.createSnapshotUpdater(() => snapshot), undefined);
269
- owner.activeSnapshots.add(snapshot);
315
+ owner.activeSnapshots.set(snapshot.id, snapshot);
270
316
  return snapshot;
271
317
  }
272
318
  return cacheGeneratorMethod(owner, "createSnapshot", createSnapshot, gen);
@@ -275,12 +321,12 @@ export class API {
275
321
  const owner = this;
276
322
  return cacheGeneratorMethod(owner, "updateSnapshot", function (baseSnapshot, params) {
277
323
  owner.ensureInitialized();
278
- if (!owner.activeSnapshots.has(baseSnapshot) || baseSnapshot.isDisposed()) {
324
+ if (owner.activeSnapshots.get(baseSnapshot.id) !== baseSnapshot || baseSnapshot.isDisposed()) {
279
325
  throw new Error("Cannot update an inactive snapshot");
280
326
  }
281
327
  const data = owner.client.apiRequest("updateSnapshot", {
282
328
  snapshot: baseSnapshot.id,
283
- changes: toCreateSnapshotRequest(params),
329
+ changes: toCreateSnapshotRequest(owner.prepareCreateSnapshotParams(params)),
284
330
  });
285
331
  if (data.snapshot === baseSnapshot.id) {
286
332
  owner.client.apiRequest("release", { snapshot: data.snapshot });
@@ -288,19 +334,19 @@ export class API {
288
334
  }
289
335
  owner.sourceFileCache.retainForSnapshot(data.snapshot, baseSnapshot.id, data.changes);
290
336
  const snapshot = new Snapshot(data, owner.client, owner.sourceFileCache, owner.toPath, owner, () => {
291
- owner.activeSnapshots.delete(snapshot);
337
+ owner.activeSnapshots.delete(snapshot.id);
292
338
  owner.sourceFileCache.releaseSnapshot(snapshot.id);
293
339
  }, owner.createSnapshotUpdater(() => snapshot), baseSnapshot);
294
- owner.activeSnapshots.add(snapshot);
340
+ owner.activeSnapshots.set(snapshot.id, snapshot);
295
341
  return snapshot;
296
342
  }, function* (baseSnapshot, params) {
297
343
  yield* owner.ensureInitialized.gen();
298
- if (!owner.activeSnapshots.has(baseSnapshot) || baseSnapshot.isDisposed()) {
344
+ if (owner.activeSnapshots.get(baseSnapshot.id) !== baseSnapshot || baseSnapshot.isDisposed()) {
299
345
  throw new Error("Cannot update an inactive snapshot");
300
346
  }
301
347
  const data = yield* apiRequest("updateSnapshot", {
302
348
  snapshot: baseSnapshot.id,
303
- changes: toCreateSnapshotRequest(params),
349
+ changes: toCreateSnapshotRequest(owner.prepareCreateSnapshotParams(params)),
304
350
  });
305
351
  if (data.snapshot === baseSnapshot.id) {
306
352
  yield* apiRequest("release", { snapshot: data.snapshot });
@@ -308,13 +354,38 @@ export class API {
308
354
  }
309
355
  owner.sourceFileCache.retainForSnapshot(data.snapshot, baseSnapshot.id, data.changes);
310
356
  const snapshot = new Snapshot(data, owner.client, owner.sourceFileCache, owner.toPath, owner, () => {
311
- owner.activeSnapshots.delete(snapshot);
357
+ owner.activeSnapshots.delete(snapshot.id);
312
358
  owner.sourceFileCache.releaseSnapshot(snapshot.id);
313
359
  }, owner.createSnapshotUpdater(() => snapshot), baseSnapshot);
314
- owner.activeSnapshots.add(snapshot);
360
+ owner.activeSnapshots.set(snapshot.id, snapshot);
315
361
  return snapshot;
316
362
  });
317
363
  }
364
+ prepareCreateSnapshotParams(params) {
365
+ if (!params)
366
+ return undefined;
367
+ const prepareOptions = (options) => {
368
+ if (!options)
369
+ return undefined;
370
+ const { moduleResolver, ...rest } = options;
371
+ moduleResolver?.ensureNotDisposed();
372
+ return {
373
+ ...rest,
374
+ moduleResolver: moduleResolver?.id,
375
+ };
376
+ };
377
+ return {
378
+ ...params,
379
+ createPrograms: params.createPrograms?.map(program => ({ ...program, options: prepareOptions(program.options) })),
380
+ reconfigurePrograms: params.reconfigurePrograms?.map(program => ({ ...program, options: prepareOptions(program.options) })),
381
+ };
382
+ }
383
+ prepareLanguageServerSnapshotChanges(changes) {
384
+ if (!changes)
385
+ return undefined;
386
+ const prepared = this.prepareCreateSnapshotParams(changes);
387
+ return prepared;
388
+ }
318
389
  createSnapshotUpdater(getSnapshot) {
319
390
  const update = ((params) => this.updateSnapshot(getSnapshot(), params));
320
391
  const owner = this;
@@ -333,42 +404,42 @@ export class API {
333
404
  owner.ensureInitialized();
334
405
  const changes = args[0];
335
406
  const baseSnapshot = args[1];
336
- if (baseSnapshot && (!owner.activeSnapshots.has(baseSnapshot) || baseSnapshot.isDisposed())) {
407
+ if (baseSnapshot && (owner.activeSnapshots.get(baseSnapshot.id) !== baseSnapshot || baseSnapshot.isDisposed())) {
337
408
  throw new Error("Cannot use an inactive snapshot as a response base");
338
409
  }
339
410
  const data = owner.client.apiRequest("getCurrentLanguageServerSnapshot", {
340
411
  baseSnapshot: baseSnapshot?.id,
341
- changes,
412
+ changes: owner.prepareLanguageServerSnapshotChanges(changes),
342
413
  });
343
414
  if (baseSnapshot) {
344
415
  owner.sourceFileCache.retainForSnapshot(data.snapshot, baseSnapshot.id, data.changes);
345
416
  }
346
417
  const snapshot = new Snapshot(data, owner.client, owner.sourceFileCache, owner.toPath, owner, () => {
347
- owner.activeSnapshots.delete(snapshot);
418
+ owner.activeSnapshots.delete(snapshot.id);
348
419
  owner.sourceFileCache.releaseSnapshot(snapshot.id);
349
420
  }, owner.createSnapshotUpdater(() => snapshot), baseSnapshot);
350
- owner.activeSnapshots.add(snapshot);
421
+ owner.activeSnapshots.set(snapshot.id, snapshot);
351
422
  return snapshot;
352
423
  }
353
424
  function* gen(...args) {
354
425
  yield* owner.ensureInitialized.gen();
355
426
  const changes = args[0];
356
427
  const baseSnapshot = args[1];
357
- if (baseSnapshot && (!owner.activeSnapshots.has(baseSnapshot) || baseSnapshot.isDisposed())) {
428
+ if (baseSnapshot && (owner.activeSnapshots.get(baseSnapshot.id) !== baseSnapshot || baseSnapshot.isDisposed())) {
358
429
  throw new Error("Cannot use an inactive snapshot as a response base");
359
430
  }
360
431
  const data = yield* apiRequest("getCurrentLanguageServerSnapshot", {
361
432
  baseSnapshot: baseSnapshot?.id,
362
- changes,
433
+ changes: owner.prepareLanguageServerSnapshotChanges(changes),
363
434
  });
364
435
  if (baseSnapshot) {
365
436
  owner.sourceFileCache.retainForSnapshot(data.snapshot, baseSnapshot.id, data.changes);
366
437
  }
367
438
  const snapshot = new Snapshot(data, owner.client, owner.sourceFileCache, owner.toPath, owner, () => {
368
- owner.activeSnapshots.delete(snapshot);
439
+ owner.activeSnapshots.delete(snapshot.id);
369
440
  owner.sourceFileCache.releaseSnapshot(snapshot.id);
370
441
  }, owner.createSnapshotUpdater(() => snapshot), baseSnapshot);
371
- owner.activeSnapshots.add(snapshot);
442
+ owner.activeSnapshots.set(snapshot.id, snapshot);
372
443
  return snapshot;
373
444
  }
374
445
  return cacheGeneratorMethod(owner, "getCurrentLanguageServerSnapshot", getCurrentLanguageServerSnapshot, gen);
@@ -379,26 +450,76 @@ export class API {
379
450
  get close() {
380
451
  const owner = this;
381
452
  return cacheGeneratorMethod(owner, "close", function () {
382
- // Dispose all active snapshots
383
453
  try {
384
- for (const snapshot of [...owner.activeSnapshots]) {
385
- snapshot.dispose();
454
+ for (const retained of [...owner.activeSourceFileLeases.values()]) {
455
+ retained.dispose();
386
456
  }
387
- owner.sourceFileCache.clear();
388
457
  }
389
458
  finally {
390
- owner.client.close(); // always close the underlying connection
459
+ try {
460
+ for (const snapshot of [...owner.activeSnapshots.values()]) {
461
+ snapshot.dispose();
462
+ }
463
+ owner.sourceFileCache.clear();
464
+ }
465
+ finally {
466
+ owner.client.close(); // always close the underlying connection
467
+ }
391
468
  }
392
469
  }, function* () {
393
- // Dispose all active snapshots
394
470
  try {
395
- for (const snapshot of [...owner.activeSnapshots]) {
396
- yield* snapshot.dispose.gen();
471
+ for (const retained of [...owner.activeSourceFileLeases.values()]) {
472
+ yield* retained.dispose.gen();
397
473
  }
398
- owner.sourceFileCache.clear();
399
474
  }
400
475
  finally {
401
- owner.client.close(); // always close the underlying connection
476
+ try {
477
+ for (const snapshot of [...owner.activeSnapshots.values()]) {
478
+ yield* snapshot.dispose.gen();
479
+ }
480
+ owner.sourceFileCache.clear();
481
+ }
482
+ finally {
483
+ owner.client.close(); // always close the underlying connection
484
+ }
485
+ }
486
+ });
487
+ }
488
+ get createModuleResolver() {
489
+ const owner = this;
490
+ return cacheGeneratorMethod(owner, "createModuleResolver", function (compilerOptions, options) {
491
+ owner.ensureInitialized();
492
+ const callback = options?.resolveModuleName
493
+ ? registerModuleResolutionCallback(owner.client, options.resolveModuleName, id => owner.activeSnapshots.get(id))
494
+ : undefined;
495
+ try {
496
+ const id = owner.client.apiRequest("createModuleResolver", {
497
+ compilerOptions,
498
+ moduleResolutions: options?.moduleResolutions,
499
+ resolveModuleNameCallback: callback?.name,
500
+ });
501
+ return new ModuleResolver(id, owner.client, callback?.dispose);
502
+ }
503
+ catch (error) {
504
+ callback?.dispose();
505
+ throw error;
506
+ }
507
+ }, function* (compilerOptions, options) {
508
+ yield* owner.ensureInitialized.gen();
509
+ const callback = options?.resolveModuleName
510
+ ? registerModuleResolutionCallback(owner.client, options.resolveModuleName, id => owner.activeSnapshots.get(id))
511
+ : undefined;
512
+ try {
513
+ const id = yield* apiRequest("createModuleResolver", {
514
+ compilerOptions,
515
+ moduleResolutions: options?.moduleResolutions,
516
+ resolveModuleNameCallback: callback?.name,
517
+ });
518
+ return new ModuleResolver(id, owner.client, callback?.dispose);
519
+ }
520
+ catch (error) {
521
+ callback?.dispose();
522
+ throw error;
402
523
  }
403
524
  });
404
525
  }
@@ -409,7 +530,7 @@ export class API {
409
530
  const owner = this;
410
531
  return cacheGeneratorMethod(owner, "runWithTemporaryFileUpdate", function (baseSnapshot, file, newText, cb) {
411
532
  owner.ensureInitialized();
412
- if (!owner.activeSnapshots.has(baseSnapshot) || baseSnapshot.isDisposed()) {
533
+ if (owner.activeSnapshots.get(baseSnapshot.id) !== baseSnapshot || baseSnapshot.isDisposed()) {
413
534
  throw new Error("Cannot run a temporary file update on an inactive snapshot");
414
535
  }
415
536
  const snapshot = baseSnapshot.update({
@@ -427,7 +548,7 @@ export class API {
427
548
  }
428
549
  }, function* (baseSnapshot, file, newText, cb) {
429
550
  yield* owner.ensureInitialized.gen();
430
- if (!owner.activeSnapshots.has(baseSnapshot) || baseSnapshot.isDisposed()) {
551
+ if (owner.activeSnapshots.get(baseSnapshot.id) !== baseSnapshot || baseSnapshot.isDisposed()) {
431
552
  throw new Error("Cannot run a temporary file update on an inactive snapshot");
432
553
  }
433
554
  const snapshot = yield* baseSnapshot.update.gen({
@@ -503,6 +624,56 @@ export class API {
503
624
  });
504
625
  }
505
626
  }
627
+ /** An independently retained source file and its disposable remote-lifetime lease. */
628
+ export class RetainedSourceFile {
629
+ sourceFile;
630
+ lease;
631
+ client;
632
+ onDispose;
633
+ disposed = false;
634
+ disposePromise;
635
+ constructor(sourceFile, lease, client, onDispose) {
636
+ this.sourceFile = sourceFile;
637
+ this.lease = lease;
638
+ this.client = client;
639
+ this.onDispose = onDispose;
640
+ }
641
+ [globalThis.Symbol.dispose]() {
642
+ this.dispose();
643
+ }
644
+ get dispose() {
645
+ const owner = this;
646
+ return cacheGeneratorMethod(owner, "dispose", function () {
647
+ return owner.disposePromise ??= owner.disposeWorker();
648
+ }, function* () {
649
+ return owner.disposePromise ??= yield* owner.disposeWorker.gen();
650
+ });
651
+ }
652
+ get disposeWorker() {
653
+ const owner = this;
654
+ return cacheGeneratorMethod(owner, "disposeWorker", function () {
655
+ if (owner.disposed)
656
+ return;
657
+ owner.disposed = true;
658
+ try {
659
+ owner.client.apiRequest("releaseSourceFile", { lease: owner.lease });
660
+ }
661
+ finally {
662
+ owner.onDispose();
663
+ }
664
+ }, function* () {
665
+ if (owner.disposed)
666
+ return;
667
+ owner.disposed = true;
668
+ try {
669
+ yield* apiRequest("releaseSourceFile", { lease: owner.lease });
670
+ }
671
+ finally {
672
+ owner.onDispose();
673
+ }
674
+ });
675
+ }
676
+ }
506
677
  export class InternalAPI {
507
678
  client;
508
679
  ensureInitialized;
@@ -701,6 +872,71 @@ export class Snapshot {
701
872
  return project;
702
873
  }
703
874
  }
875
+ export class ModuleResolver {
876
+ id;
877
+ client;
878
+ disposeCallback;
879
+ disposed = false;
880
+ constructor(id, client, disposeCallback) {
881
+ this.id = id;
882
+ this.client = client;
883
+ this.disposeCallback = disposeCallback;
884
+ }
885
+ get resolveModuleName() {
886
+ const owner = this;
887
+ return cacheGeneratorMethod(owner, "resolveModuleName", function (moduleName, containingDirectory, resolutionMode, options) {
888
+ owner.ensureNotDisposed();
889
+ if (options?.snapshot instanceof Snapshot && options.snapshot.isDisposed()) {
890
+ throw new Error("Snapshot is disposed");
891
+ }
892
+ return owner.client.apiRequest("resolveModuleName", {
893
+ snapshot: options?.snapshot instanceof Snapshot ? options.snapshot.id : undefined,
894
+ inProgressSnapshot: typeof options?.snapshot === "number" ? -options.snapshot : undefined,
895
+ resolver: owner.id,
896
+ moduleName,
897
+ containingDirectory,
898
+ resolutionMode,
899
+ });
900
+ }, function* (moduleName, containingDirectory, resolutionMode, options) {
901
+ owner.ensureNotDisposed();
902
+ if (options?.snapshot instanceof Snapshot && options.snapshot.isDisposed()) {
903
+ throw new Error("Snapshot is disposed");
904
+ }
905
+ return yield* apiRequest("resolveModuleName", {
906
+ snapshot: options?.snapshot instanceof Snapshot ? options.snapshot.id : undefined,
907
+ inProgressSnapshot: typeof options?.snapshot === "number" ? -options.snapshot : undefined,
908
+ resolver: owner.id,
909
+ moduleName,
910
+ containingDirectory,
911
+ resolutionMode,
912
+ });
913
+ });
914
+ }
915
+ [globalThis.Symbol.dispose]() {
916
+ return this.dispose();
917
+ }
918
+ get dispose() {
919
+ const owner = this;
920
+ return cacheGeneratorMethod(owner, "dispose", function () {
921
+ if (owner.disposed)
922
+ return;
923
+ owner.client.apiRequest("releaseModuleResolver", { resolver: owner.id });
924
+ owner.disposed = true;
925
+ owner.disposeCallback?.();
926
+ }, function* () {
927
+ if (owner.disposed)
928
+ return;
929
+ yield* apiRequest("releaseModuleResolver", { resolver: owner.id });
930
+ owner.disposed = true;
931
+ owner.disposeCallback?.();
932
+ });
933
+ }
934
+ /** @internal */
935
+ ensureNotDisposed() {
936
+ if (this.disposed)
937
+ throw new Error("ModuleResolver is disposed");
938
+ }
939
+ }
704
940
  class SnapshotObjectRegistry {
705
941
  symbols = new Map();
706
942
  client;
@@ -3196,21 +3432,9 @@ export class Checker {
3196
3432
  get getIndexTypeOfType() {
3197
3433
  const owner = this;
3198
3434
  return cacheGeneratorMethod(owner, "getIndexTypeOfType", function (type, kind) {
3199
- const data = owner.client.apiRequest("getIndexTypeOfTypeByKind", {
3200
- snapshot: owner.snapshotId,
3201
- project: owner.project.id,
3202
- type: type.id,
3203
- kind,
3204
- });
3205
- return data ? owner.objectRegistry.getOrCreateType(data) : undefined;
3435
+ return kind === IndexKind.String ? type.getStringIndexType() : type.getNumberIndexType();
3206
3436
  }, function* (type, kind) {
3207
- const data = yield* apiRequest("getIndexTypeOfTypeByKind", {
3208
- snapshot: owner.snapshotId,
3209
- project: owner.project.id,
3210
- type: type.id,
3211
- kind,
3212
- });
3213
- return data ? owner.objectRegistry.getOrCreateType(data) : undefined;
3437
+ return kind === IndexKind.String ? (yield* type.getStringIndexType.gen()) : (yield* type.getNumberIndexType.gen());
3214
3438
  });
3215
3439
  }
3216
3440
  get getTypeOfPropertyOfType() {
@@ -3973,6 +4197,7 @@ class TypeObject {
3973
4197
  constructSignatures;
3974
4198
  indexInfos;
3975
4199
  baseTypes;
4200
+ types;
3976
4201
  stringIndexType;
3977
4202
  numberIndexType;
3978
4203
  constructor(data, objectRegistry) {
@@ -4069,6 +4294,7 @@ class TypeObject {
4069
4294
  this.constructSignatures = false;
4070
4295
  this.indexInfos = false;
4071
4296
  this.baseTypes = false;
4297
+ this.types = false;
4072
4298
  this.stringIndexType = false;
4073
4299
  this.numberIndexType = false;
4074
4300
  }
@@ -4283,7 +4509,10 @@ class TypeObject {
4283
4509
  if (!(owner.flags & (TypeFlags.UnionOrIntersection | TypeFlags.TemplateLiteral))) {
4284
4510
  return undefined;
4285
4511
  }
4286
- return owner.objectRegistry.fetchTypes(owner, "getTypesOfType");
4512
+ if (owner.types === false) {
4513
+ owner.types = owner.objectRegistry.fetchTypes(owner, "getTypesOfType");
4514
+ }
4515
+ return owner.types;
4287
4516
  }, function* () {
4288
4517
  // Only union, intersection, and template literal types have constituent
4289
4518
  // types; any other kind has none, so return undefined rather than sending
@@ -4291,7 +4520,10 @@ class TypeObject {
4291
4520
  if (!(owner.flags & (TypeFlags.UnionOrIntersection | TypeFlags.TemplateLiteral))) {
4292
4521
  return undefined;
4293
4522
  }
4294
- return yield* owner.objectRegistry.fetchTypes.gen(owner, "getTypesOfType");
4523
+ if (owner.types === false) {
4524
+ owner.types = yield* owner.objectRegistry.fetchTypes.gen(owner, "getTypesOfType");
4525
+ }
4526
+ return owner.types;
4295
4527
  });
4296
4528
  }
4297
4529
  get getTypeParameters() {