typescript 5.4.0-dev.20231114 → 5.4.0-dev.20231116

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/tsserver.js CHANGED
@@ -2330,7 +2330,7 @@ module.exports = __toCommonJS(server_exports);
2330
2330
 
2331
2331
  // src/compiler/corePublic.ts
2332
2332
  var versionMajorMinor = "5.4";
2333
- var version = `${versionMajorMinor}.0-dev.20231114`;
2333
+ var version = `${versionMajorMinor}.0-dev.20231116`;
2334
2334
  var Comparison = /* @__PURE__ */ ((Comparison3) => {
2335
2335
  Comparison3[Comparison3["LessThan"] = -1] = "LessThan";
2336
2336
  Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo";
@@ -8041,6 +8041,7 @@ function createSystemWatchFunctions({
8041
8041
  useNonPollingWatchers,
8042
8042
  tscWatchDirectory,
8043
8043
  inodeWatching,
8044
+ fsWatchWithTimestamp,
8044
8045
  sysLog: sysLog2
8045
8046
  }) {
8046
8047
  const pollingWatches = /* @__PURE__ */ new Map();
@@ -8279,7 +8280,7 @@ function createSystemWatchFunctions({
8279
8280
  return watchPresentFileSystemEntryWithFsWatchFile();
8280
8281
  }
8281
8282
  try {
8282
- const presentWatcher = fsWatchWorker(
8283
+ const presentWatcher = (!fsWatchWithTimestamp ? fsWatchWorker : fsWatchWorkerHandlingTimestamp)(
8283
8284
  fileOrDirectory,
8284
8285
  recursive,
8285
8286
  inodeWatching ? callbackChangingToMissingFileSystemEntry : callback
@@ -8342,6 +8343,18 @@ function createSystemWatchFunctions({
8342
8343
  );
8343
8344
  }
8344
8345
  }
8346
+ function fsWatchWorkerHandlingTimestamp(fileOrDirectory, recursive, callback) {
8347
+ let modifiedTime = getModifiedTime3(fileOrDirectory) || missingFileModifiedTime;
8348
+ return fsWatchWorker(fileOrDirectory, recursive, (eventName, relativeFileName, currentModifiedTime) => {
8349
+ if (eventName === "change") {
8350
+ currentModifiedTime || (currentModifiedTime = getModifiedTime3(fileOrDirectory) || missingFileModifiedTime);
8351
+ if (currentModifiedTime.getTime() === modifiedTime.getTime())
8352
+ return;
8353
+ }
8354
+ modifiedTime = currentModifiedTime || getModifiedTime3(fileOrDirectory) || missingFileModifiedTime;
8355
+ callback(eventName, relativeFileName, modifiedTime);
8356
+ });
8357
+ }
8345
8358
  }
8346
8359
  function patchWriteFileEnsuringDirectory(sys2) {
8347
8360
  const originalWriteFile = sys2.writeFile;
@@ -8370,12 +8383,13 @@ var sys = (() => {
8370
8383
  let activeSession;
8371
8384
  let profilePath = "./profile.cpuprofile";
8372
8385
  const Buffer2 = require("buffer").Buffer;
8373
- const isLinuxOrMacOs = process.platform === "linux" || process.platform === "darwin";
8386
+ const isMacOs = process.platform === "darwin";
8387
+ const isLinuxOrMacOs = process.platform === "linux" || isMacOs;
8374
8388
  const platform = _os.platform();
8375
8389
  const useCaseSensitiveFileNames2 = isFileSystemCaseSensitive();
8376
8390
  const fsRealpath = !!_fs.realpathSync.native ? process.platform === "win32" ? fsRealPathHandlingLongPath : _fs.realpathSync.native : _fs.realpathSync;
8377
8391
  const executingFilePath = __filename.endsWith("sys.js") ? _path.join(_path.dirname(__dirname), "__fake__.js") : __filename;
8378
- const fsSupportsRecursiveFsWatch = process.platform === "win32" || process.platform === "darwin";
8392
+ const fsSupportsRecursiveFsWatch = process.platform === "win32" || isMacOs;
8379
8393
  const getCurrentDirectory = memoize(() => process.cwd());
8380
8394
  const { watchFile: watchFile2, watchDirectory } = createSystemWatchFunctions({
8381
8395
  pollingWatchFileWorker: fsWatchFileWorker,
@@ -8395,6 +8409,7 @@ var sys = (() => {
8395
8409
  useNonPollingWatchers: !!process.env.TSC_NONPOLLING_WATCHER,
8396
8410
  tscWatchDirectory: process.env.TSC_WATCHDIRECTORY,
8397
8411
  inodeWatching: isLinuxOrMacOs,
8412
+ fsWatchWithTimestamp: isMacOs,
8398
8413
  sysLog
8399
8414
  });
8400
8415
  const nodeSystem = {
@@ -10199,6 +10214,7 @@ var Diagnostics = {
10199
10214
  Type_0_is_generic_and_can_only_be_indexed_for_reading: diag(2862, 1 /* Error */, "Type_0_is_generic_and_can_only_be_indexed_for_reading_2862", "Type '{0}' is generic and can only be indexed for reading."),
10200
10215
  A_class_cannot_extend_a_primitive_type_like_0_Classes_can_only_extend_constructable_values: diag(2863, 1 /* Error */, "A_class_cannot_extend_a_primitive_type_like_0_Classes_can_only_extend_constructable_values_2863", "A class cannot extend a primitive type like '{0}'. Classes can only extend constructable values."),
10201
10216
  A_class_cannot_implement_a_primitive_type_like_0_It_can_only_implement_other_named_object_types: diag(2864, 1 /* Error */, "A_class_cannot_implement_a_primitive_type_like_0_It_can_only_implement_other_named_object_types_2864", "A class cannot implement a primitive type like '{0}'. It can only implement other named object types."),
10217
+ Import_0_conflicts_with_local_value_so_must_be_declared_with_a_type_only_import_when_isolatedModules_is_enabled: diag(2865, 1 /* Error */, "Import_0_conflicts_with_local_value_so_must_be_declared_with_a_type_only_import_when_isolatedModules_2865", "Import '{0}' conflicts with local value, so must be declared with a type-only import when 'isolatedModules' is enabled."),
10202
10218
  Import_declaration_0_is_using_private_name_1: diag(4e3, 1 /* Error */, "Import_declaration_0_is_using_private_name_1_4000", "Import declaration '{0}' is using private name '{1}'."),
10203
10219
  Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: diag(4002, 1 /* Error */, "Type_parameter_0_of_exported_class_has_or_is_using_private_name_1_4002", "Type parameter '{0}' of exported class has or is using private name '{1}'."),
10204
10220
  Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: diag(4004, 1 /* Error */, "Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1_4004", "Type parameter '{0}' of exported interface has or is using private name '{1}'."),
@@ -14643,7 +14659,7 @@ function isPropertyAccessOrQualifiedName(node) {
14643
14659
  return kind === 211 /* PropertyAccessExpression */ || kind === 166 /* QualifiedName */;
14644
14660
  }
14645
14661
  function isCallLikeOrFunctionLikeExpression(node) {
14646
- return isCallLikeExpression(node) || isFunctionLike(node);
14662
+ return isCallLikeExpression(node) || isFunctionExpressionOrArrowFunction(node);
14647
14663
  }
14648
14664
  function isCallLikeExpression(node) {
14649
14665
  switch (node.kind) {
@@ -23035,10 +23051,8 @@ function createNodeFactory(flags, baseFactory2) {
23035
23051
  return update(updated, original);
23036
23052
  }
23037
23053
  function createNumericLiteral(value, numericLiteralFlags = 0 /* None */) {
23038
- const text = typeof value === "number" ? value + "" : value;
23039
- Debug.assert(text.charCodeAt(0) !== 45 /* minus */, "Negative numbers should be created in combination with createPrefixUnaryExpression");
23040
23054
  const node = createBaseDeclaration(9 /* NumericLiteral */);
23041
- node.text = text;
23055
+ node.text = typeof value === "number" ? value + "" : value;
23042
23056
  node.numericLiteralFlags = numericLiteralFlags;
23043
23057
  if (numericLiteralFlags & 384 /* BinaryOrOctalSpecifier */)
23044
23058
  node.transformFlags |= 1024 /* ContainsES2015 */;
@@ -48400,7 +48414,7 @@ function createTypeChecker(host) {
48400
48414
  const nodeLinks2 = getNodeLinks(node);
48401
48415
  cachedResolvedSignatures.push([nodeLinks2, nodeLinks2.resolvedSignature]);
48402
48416
  nodeLinks2.resolvedSignature = void 0;
48403
- if (isFunctionLike(node)) {
48417
+ if (isFunctionExpressionOrArrowFunction(node)) {
48404
48418
  const symbolLinks2 = getSymbolLinks(getSymbolOfDeclaration(node));
48405
48419
  const type = symbolLinks2.type;
48406
48420
  cachedTypes2.push([symbolLinks2, type]);
@@ -52962,6 +52976,8 @@ function createTypeChecker(host) {
52962
52976
  context.symbolDepth.set(id, depth + 1);
52963
52977
  }
52964
52978
  context.visitedTypes.add(typeId);
52979
+ const prevTrackedSymbols = context.trackedSymbols;
52980
+ context.trackedSymbols = void 0;
52965
52981
  const startLength = context.approximateLength;
52966
52982
  const result = transform2(type2);
52967
52983
  const addedLength = context.approximateLength - startLength;
@@ -52977,6 +52993,7 @@ function createTypeChecker(host) {
52977
52993
  if (id) {
52978
52994
  context.symbolDepth.set(id, depth);
52979
52995
  }
52996
+ context.trackedSymbols = prevTrackedSymbols;
52980
52997
  return result;
52981
52998
  function deepCloneOrReuseNode(node) {
52982
52999
  if (!nodeIsSynthesized(node) && getParseTreeNode(node) === node) {
@@ -53279,7 +53296,7 @@ function createTypeChecker(host) {
53279
53296
  context.approximateLength += symbolName(propertySymbol).length + 1;
53280
53297
  if (propertySymbol.flags & 98304 /* Accessor */) {
53281
53298
  const writeType = getWriteTypeOfSymbol(propertySymbol);
53282
- if (propertyType !== writeType) {
53299
+ if (propertyType !== writeType && !isErrorType(propertyType) && !isErrorType(writeType)) {
53283
53300
  const getterDeclaration = getDeclarationOfKind(propertySymbol, 177 /* GetAccessor */);
53284
53301
  const getterSignature = getSignatureFromDeclaration(getterDeclaration);
53285
53302
  typeElements.push(
@@ -54228,7 +54245,7 @@ function createTypeChecker(host) {
54228
54245
  return factory.createStringLiteral(name, !!singleQuote);
54229
54246
  }
54230
54247
  if (isNumericLiteralName(name) && startsWith(name, "-")) {
54231
- return factory.createComputedPropertyName(factory.createPrefixUnaryExpression(41 /* MinusToken */, factory.createNumericLiteral(Math.abs(+name))));
54248
+ return factory.createComputedPropertyName(factory.createNumericLiteral(+name));
54232
54249
  }
54233
54250
  return createPropertyNameNodeForIdentifierOrLiteral(name, getEmitScriptTarget(compilerOptions), singleQuote, stringNamed, isMethod);
54234
54251
  }
@@ -80111,14 +80128,9 @@ function createTypeChecker(host) {
80111
80128
  case 15 /* NoSubstitutionTemplateLiteral */:
80112
80129
  case 11 /* StringLiteral */:
80113
80130
  return hasSkipDirectInferenceFlag(node) ? blockedStringType : getFreshTypeOfLiteralType(getStringLiteralType(node.text));
80114
- case 9 /* NumericLiteral */: {
80131
+ case 9 /* NumericLiteral */:
80115
80132
  checkGrammarNumericLiteral(node);
80116
- const value = +node.text;
80117
- if (!isFinite(value)) {
80118
- return numberType;
80119
- }
80120
- return getFreshTypeOfLiteralType(getNumberLiteralType(value));
80121
- }
80133
+ return getFreshTypeOfLiteralType(getNumberLiteralType(+node.text));
80122
80134
  case 10 /* BigIntLiteral */:
80123
80135
  checkGrammarBigIntLiteral(node);
80124
80136
  return getFreshTypeOfLiteralType(getBigIntLiteralType({
@@ -85023,6 +85035,16 @@ function createTypeChecker(host) {
85023
85035
  if (targetFlags & excludedMeanings) {
85024
85036
  const message = node.kind === 281 /* ExportSpecifier */ ? Diagnostics.Export_declaration_conflicts_with_exported_declaration_of_0 : Diagnostics.Import_declaration_conflicts_with_local_declaration_of_0;
85025
85037
  error2(node, message, symbolToString(symbol));
85038
+ } else if (node.kind !== 281 /* ExportSpecifier */) {
85039
+ const appearsValueyToTranspiler = compilerOptions.isolatedModules && !findAncestor(node, isTypeOnlyImportOrExportDeclaration);
85040
+ if (appearsValueyToTranspiler && symbol.flags & (111551 /* Value */ | 1048576 /* ExportValue */)) {
85041
+ error2(
85042
+ node,
85043
+ Diagnostics.Import_0_conflicts_with_local_value_so_must_be_declared_with_a_type_only_import_when_isolatedModules_is_enabled,
85044
+ symbolToString(symbol),
85045
+ isolatedModulesLikeFlagName
85046
+ );
85047
+ }
85026
85048
  }
85027
85049
  if (getIsolatedModules(compilerOptions) && !isTypeOnlyImportOrExportDeclaration(node) && !(node.flags & 33554432 /* Ambient */)) {
85028
85050
  const typeOnlyAlias = getTypeOnlyAliasDeclaration(symbol);
@@ -87119,7 +87141,7 @@ function createTypeChecker(host) {
87119
87141
  if (enumResult)
87120
87142
  return enumResult;
87121
87143
  const literalValue = type.value;
87122
- return typeof literalValue === "object" ? factory.createBigIntLiteral(literalValue) : typeof literalValue === "string" ? factory.createStringLiteral(literalValue) : literalValue < 0 ? factory.createPrefixUnaryExpression(41 /* MinusToken */, factory.createNumericLiteral(Math.abs(literalValue))) : factory.createNumericLiteral(literalValue);
87144
+ return typeof literalValue === "object" ? factory.createBigIntLiteral(literalValue) : typeof literalValue === "number" ? factory.createNumericLiteral(literalValue) : factory.createStringLiteral(literalValue);
87123
87145
  }
87124
87146
  function createLiteralConstValue(node, tracker) {
87125
87147
  const type = getTypeOfSymbol(getSymbolOfDeclaration(node));
@@ -93719,7 +93741,7 @@ function transformTypeScript(context) {
93719
93741
  function transformEnumMemberDeclarationValue(member) {
93720
93742
  const value = resolver.getConstantValue(member);
93721
93743
  if (value !== void 0) {
93722
- return typeof value === "string" ? factory2.createStringLiteral(value) : value < 0 ? factory2.createPrefixUnaryExpression(41 /* MinusToken */, factory2.createNumericLiteral(Math.abs(value))) : factory2.createNumericLiteral(value);
93744
+ return typeof value === "string" ? factory2.createStringLiteral(value) : factory2.createNumericLiteral(value);
93723
93745
  } else {
93724
93746
  enableSubstitutionForNonQualifiedEnumMembers();
93725
93747
  if (member.initializer) {
@@ -108039,7 +108061,7 @@ function transformGenerators(context) {
108039
108061
  if (labelExpressions === void 0) {
108040
108062
  labelExpressions = [];
108041
108063
  }
108042
- const expression = factory2.createNumericLiteral(Number.MAX_SAFE_INTEGER);
108064
+ const expression = factory2.createNumericLiteral(-1);
108043
108065
  if (labelExpressions[label] === void 0) {
108044
108066
  labelExpressions[label] = [expression];
108045
108067
  } else {
@@ -113914,8 +113936,7 @@ function transformDeclarations(context) {
113914
113936
  if (shouldStripInternal(m))
113915
113937
  return;
113916
113938
  const constValue = resolver.getConstantValue(m);
113917
- const newInitializer = constValue === void 0 ? void 0 : typeof constValue === "string" ? factory2.createStringLiteral(constValue) : constValue < 0 ? factory2.createPrefixUnaryExpression(41 /* MinusToken */, factory2.createNumericLiteral(Math.abs(constValue))) : factory2.createNumericLiteral(constValue);
113918
- return preserveJsDoc(factory2.updateEnumMember(m, m.name, newInitializer), m);
113939
+ return preserveJsDoc(factory2.updateEnumMember(m, m.name, constValue !== void 0 ? typeof constValue === "string" ? factory2.createStringLiteral(constValue) : factory2.createNumericLiteral(constValue) : void 0), m);
113919
113940
  }))
113920
113941
  ));
113921
113942
  }
@@ -135736,6 +135757,7 @@ var DocumentHighlights;
135736
135757
  case 127 /* YieldKeyword */:
135737
135758
  return highlightSpans(getYieldOccurrences(node));
135738
135759
  case 103 /* InKeyword */:
135760
+ case 147 /* OutKeyword */:
135739
135761
  return void 0;
135740
135762
  default:
135741
135763
  return isModifierKind(node.kind) && (isDeclaration(node.parent) || isVariableStatement(node.parent)) ? highlightSpans(getModifierOccurrences(node.kind, node.parent)) : void 0;
@@ -175255,6 +175277,7 @@ __export(ts_server_exports3, {
175255
175277
  TextStorage: () => TextStorage,
175256
175278
  ThrottledOperations: () => ThrottledOperations,
175257
175279
  TypingsCache: () => TypingsCache,
175280
+ TypingsInstallerAdapter: () => TypingsInstallerAdapter,
175258
175281
  allFilesAreJsOrDts: () => allFilesAreJsOrDts,
175259
175282
  allRootFilesAreJsOrDts: () => allRootFilesAreJsOrDts,
175260
175283
  asNormalizedPath: () => asNormalizedPath,
@@ -175376,6 +175399,32 @@ var TypingsInstaller = class {
175376
175399
  }
175377
175400
  this.processCacheLocation(this.globalCachePath);
175378
175401
  }
175402
+ /** @internal */
175403
+ handleRequest(req) {
175404
+ switch (req.kind) {
175405
+ case "discover":
175406
+ this.install(req);
175407
+ break;
175408
+ case "closeProject":
175409
+ this.closeProject(req);
175410
+ break;
175411
+ case "typesRegistry": {
175412
+ const typesRegistry = {};
175413
+ this.typesRegistry.forEach((value, key) => {
175414
+ typesRegistry[key] = value;
175415
+ });
175416
+ const response = { kind: EventTypesRegistry, typesRegistry };
175417
+ this.sendResponse(response);
175418
+ break;
175419
+ }
175420
+ case "installPackage": {
175421
+ this.installPackage(req);
175422
+ break;
175423
+ }
175424
+ default:
175425
+ Debug.assertNever(req);
175426
+ }
175427
+ }
175379
175428
  closeProject(req) {
175380
175429
  this.closeWatchers(req.projectName);
175381
175430
  }
@@ -175433,7 +175482,7 @@ var TypingsInstaller = class {
175433
175482
  }
175434
175483
  /** @internal */
175435
175484
  installPackage(req) {
175436
- const { fileName, packageName, projectName, projectRootPath } = req;
175485
+ const { fileName, packageName, projectName, projectRootPath, id } = req;
175437
175486
  const cwd = forEachAncestorDirectory(getDirectoryPath(fileName), (directory) => {
175438
175487
  if (this.installTypingHost.fileExists(combinePaths(directory, "package.json"))) {
175439
175488
  return directory;
@@ -175445,6 +175494,7 @@ var TypingsInstaller = class {
175445
175494
  const response = {
175446
175495
  kind: ActionPackageInstalled,
175447
175496
  projectName,
175497
+ id,
175448
175498
  success,
175449
175499
  message
175450
175500
  };
@@ -175454,6 +175504,7 @@ var TypingsInstaller = class {
175454
175504
  const response = {
175455
175505
  kind: ActionPackageInstalled,
175456
175506
  projectName,
175507
+ id,
175457
175508
  success: false,
175458
175509
  message: "Could not determine a project root path."
175459
175510
  };
@@ -176704,8 +176755,9 @@ var TypingsCache = class {
176704
176755
  return !typeAcquisition || !typeAcquisition.enable ? emptyArray2 : typings;
176705
176756
  }
176706
176757
  onProjectClosed(project) {
176707
- this.perProjectCache.delete(project.getProjectName());
176708
- this.installer.onProjectClosed(project);
176758
+ if (this.perProjectCache.delete(project.getProjectName())) {
176759
+ this.installer.onProjectClosed(project);
176760
+ }
176709
176761
  }
176710
176762
  };
176711
176763
 
@@ -186633,6 +186685,184 @@ var LineLeaf = class {
186633
186685
  }
186634
186686
  };
186635
186687
 
186688
+ // src/server/typingInstallerAdapter.ts
186689
+ var _TypingsInstallerAdapter = class _TypingsInstallerAdapter {
186690
+ constructor(telemetryEnabled, logger, host, globalTypingsCacheLocation, event, maxActiveRequestCount) {
186691
+ this.telemetryEnabled = telemetryEnabled;
186692
+ this.logger = logger;
186693
+ this.host = host;
186694
+ this.globalTypingsCacheLocation = globalTypingsCacheLocation;
186695
+ this.event = event;
186696
+ this.maxActiveRequestCount = maxActiveRequestCount;
186697
+ this.activeRequestCount = 0;
186698
+ this.requestQueue = createQueue();
186699
+ this.requestMap = /* @__PURE__ */ new Map();
186700
+ // Maps project name to newest requestQueue entry for that project
186701
+ /** We will lazily request the types registry on the first call to `isKnownTypesPackageName` and store it in `typesRegistryCache`. */
186702
+ this.requestedRegistry = false;
186703
+ this.packageInstallId = 0;
186704
+ }
186705
+ isKnownTypesPackageName(name) {
186706
+ var _a;
186707
+ const validationResult = ts_JsTyping_exports.validatePackageName(name);
186708
+ if (validationResult !== ts_JsTyping_exports.NameValidationResult.Ok) {
186709
+ return false;
186710
+ }
186711
+ if (!this.requestedRegistry) {
186712
+ this.requestedRegistry = true;
186713
+ this.installer.send({ kind: "typesRegistry" });
186714
+ }
186715
+ return !!((_a = this.typesRegistryCache) == null ? void 0 : _a.has(name));
186716
+ }
186717
+ installPackage(options) {
186718
+ this.packageInstallId++;
186719
+ const request = { kind: "installPackage", ...options, id: this.packageInstallId };
186720
+ const promise = new Promise((resolve, reject) => {
186721
+ (this.packageInstalledPromise ?? (this.packageInstalledPromise = /* @__PURE__ */ new Map())).set(this.packageInstallId, { resolve, reject });
186722
+ });
186723
+ this.installer.send(request);
186724
+ return promise;
186725
+ }
186726
+ attach(projectService) {
186727
+ this.projectService = projectService;
186728
+ this.installer = this.createInstallerProcess();
186729
+ }
186730
+ onProjectClosed(p) {
186731
+ this.installer.send({ projectName: p.getProjectName(), kind: "closeProject" });
186732
+ }
186733
+ enqueueInstallTypingsRequest(project, typeAcquisition, unresolvedImports) {
186734
+ const request = createInstallTypingsRequest(project, typeAcquisition, unresolvedImports);
186735
+ if (this.logger.hasLevel(3 /* verbose */)) {
186736
+ this.logger.info(`TIAdapter:: Scheduling throttled operation:${stringifyIndented(request)}`);
186737
+ }
186738
+ if (this.activeRequestCount < this.maxActiveRequestCount) {
186739
+ this.scheduleRequest(request);
186740
+ } else {
186741
+ if (this.logger.hasLevel(3 /* verbose */)) {
186742
+ this.logger.info(`TIAdapter:: Deferring request for: ${request.projectName}`);
186743
+ }
186744
+ this.requestQueue.enqueue(request);
186745
+ this.requestMap.set(request.projectName, request);
186746
+ }
186747
+ }
186748
+ handleMessage(response) {
186749
+ var _a, _b;
186750
+ if (this.logger.hasLevel(3 /* verbose */)) {
186751
+ this.logger.info(`TIAdapter:: Received response:${stringifyIndented(response)}`);
186752
+ }
186753
+ switch (response.kind) {
186754
+ case EventTypesRegistry:
186755
+ this.typesRegistryCache = new Map(Object.entries(response.typesRegistry));
186756
+ break;
186757
+ case ActionPackageInstalled: {
186758
+ const promise = (_a = this.packageInstalledPromise) == null ? void 0 : _a.get(response.id);
186759
+ Debug.assertIsDefined(promise, "Should find the promise for package install");
186760
+ (_b = this.packageInstalledPromise) == null ? void 0 : _b.delete(response.id);
186761
+ if (response.success) {
186762
+ promise.resolve({ successMessage: response.message });
186763
+ } else {
186764
+ promise.reject(response.message);
186765
+ }
186766
+ this.projectService.updateTypingsForProject(response);
186767
+ this.event(response, "setTypings");
186768
+ break;
186769
+ }
186770
+ case EventInitializationFailed: {
186771
+ const body = {
186772
+ message: response.message
186773
+ };
186774
+ const eventName = "typesInstallerInitializationFailed";
186775
+ this.event(body, eventName);
186776
+ break;
186777
+ }
186778
+ case EventBeginInstallTypes: {
186779
+ const body = {
186780
+ eventId: response.eventId,
186781
+ packages: response.packagesToInstall
186782
+ };
186783
+ const eventName = "beginInstallTypes";
186784
+ this.event(body, eventName);
186785
+ break;
186786
+ }
186787
+ case EventEndInstallTypes: {
186788
+ if (this.telemetryEnabled) {
186789
+ const body2 = {
186790
+ telemetryEventName: "typingsInstalled",
186791
+ payload: {
186792
+ installedPackages: response.packagesToInstall.join(","),
186793
+ installSuccess: response.installSuccess,
186794
+ typingsInstallerVersion: response.typingsInstallerVersion
186795
+ }
186796
+ };
186797
+ const eventName2 = "telemetry";
186798
+ this.event(body2, eventName2);
186799
+ }
186800
+ const body = {
186801
+ eventId: response.eventId,
186802
+ packages: response.packagesToInstall,
186803
+ success: response.installSuccess
186804
+ };
186805
+ const eventName = "endInstallTypes";
186806
+ this.event(body, eventName);
186807
+ break;
186808
+ }
186809
+ case ActionInvalidate: {
186810
+ this.projectService.updateTypingsForProject(response);
186811
+ break;
186812
+ }
186813
+ case ActionSet: {
186814
+ if (this.activeRequestCount > 0) {
186815
+ this.activeRequestCount--;
186816
+ } else {
186817
+ Debug.fail("TIAdapter:: Received too many responses");
186818
+ }
186819
+ while (!this.requestQueue.isEmpty()) {
186820
+ const queuedRequest = this.requestQueue.dequeue();
186821
+ if (this.requestMap.get(queuedRequest.projectName) === queuedRequest) {
186822
+ this.requestMap.delete(queuedRequest.projectName);
186823
+ this.scheduleRequest(queuedRequest);
186824
+ break;
186825
+ }
186826
+ if (this.logger.hasLevel(3 /* verbose */)) {
186827
+ this.logger.info(`TIAdapter:: Skipping defunct request for: ${queuedRequest.projectName}`);
186828
+ }
186829
+ }
186830
+ this.projectService.updateTypingsForProject(response);
186831
+ this.event(response, "setTypings");
186832
+ break;
186833
+ }
186834
+ case ActionWatchTypingLocations:
186835
+ this.projectService.watchTypingLocations(response);
186836
+ break;
186837
+ default:
186838
+ assertType(response);
186839
+ }
186840
+ }
186841
+ scheduleRequest(request) {
186842
+ if (this.logger.hasLevel(3 /* verbose */)) {
186843
+ this.logger.info(`TIAdapter:: Scheduling request for: ${request.projectName}`);
186844
+ }
186845
+ this.activeRequestCount++;
186846
+ this.host.setTimeout(
186847
+ () => {
186848
+ if (this.logger.hasLevel(3 /* verbose */)) {
186849
+ this.logger.info(`TIAdapter:: Sending request:${stringifyIndented(request)}`);
186850
+ }
186851
+ this.installer.send(request);
186852
+ },
186853
+ _TypingsInstallerAdapter.requestDelayMillis,
186854
+ `${request.projectName}::${request.kind}`
186855
+ );
186856
+ }
186857
+ };
186858
+ // This number is essentially arbitrary. Processing more than one typings request
186859
+ // at a time makes sense, but having too many in the pipe results in a hang
186860
+ // (see https://github.com/nodejs/node/issues/7657).
186861
+ // It would be preferable to base our limit on the amount of space left in the
186862
+ // buffer, but we have yet to find a way to retrieve that value.
186863
+ _TypingsInstallerAdapter.requestDelayMillis = 100;
186864
+ var TypingsInstallerAdapter = _TypingsInstallerAdapter;
186865
+
186636
186866
  // src/tsserver/_namespaces/ts.server.ts
186637
186867
  var ts_server_exports4 = {};
186638
186868
  __export(ts_server_exports4, {
@@ -186680,6 +186910,7 @@ __export(ts_server_exports4, {
186680
186910
  TextStorage: () => TextStorage,
186681
186911
  ThrottledOperations: () => ThrottledOperations,
186682
186912
  TypingsCache: () => TypingsCache,
186913
+ TypingsInstallerAdapter: () => TypingsInstallerAdapter,
186683
186914
  allFilesAreJsOrDts: () => allFilesAreJsOrDts,
186684
186915
  allRootFilesAreJsOrDts: () => allRootFilesAreJsOrDts,
186685
186916
  asNormalizedPath: () => asNormalizedPath,
@@ -186799,7 +187030,7 @@ function initializeNodeSystem() {
186799
187030
  const sys2 = Debug.checkDefined(sys);
186800
187031
  const childProcess = require("child_process");
186801
187032
  const fs = require("fs");
186802
- class Logger6 {
187033
+ class Logger7 {
186803
187034
  constructor(logFilename, traceToConsole, level) {
186804
187035
  this.logFilename = logFilename;
186805
187036
  this.traceToConsole = traceToConsole;
@@ -186866,7 +187097,7 @@ function initializeNodeSystem() {
186866
187097
  s = `[${nowString()}] ${s}
186867
187098
  `;
186868
187099
  if (!this.inGroup || this.firstInGroup) {
186869
- const prefix = Logger6.padStringRight(type + " " + this.seq.toString(), " ");
187100
+ const prefix = Logger7.padStringRight(type + " " + this.seq.toString(), " ");
186870
187101
  s = prefix + s;
186871
187102
  }
186872
187103
  this.write(s, type);
@@ -187003,7 +187234,7 @@ function initializeNodeSystem() {
187003
187234
  const unsubstitutedLogFileName = cmdLineLogFileName ? stripQuotes(cmdLineLogFileName) : envLogOptions.logToFile ? envLogOptions.file || libDirectory + "/.log" + process.pid.toString() : void 0;
187004
187235
  const substitutedLogFileName = unsubstitutedLogFileName ? unsubstitutedLogFileName.replace("PID", process.pid.toString()) : void 0;
187005
187236
  const logVerbosity = cmdLineVerbosity || envLogOptions.detailLevel;
187006
- return new Logger6(substitutedLogFileName, envLogOptions.traceToConsole, logVerbosity);
187237
+ return new Logger7(substitutedLogFileName, envLogOptions.traceToConsole, logVerbosity);
187007
187238
  }
187008
187239
  function writeMessage(buf) {
187009
187240
  if (!canWrite) {
@@ -187063,45 +187294,22 @@ function startNodeSession(options, logger, cancellationToken) {
187063
187294
  output: process.stdout,
187064
187295
  terminal: false
187065
187296
  });
187066
- const _NodeTypingsInstaller = class _NodeTypingsInstaller {
187297
+ const _NodeTypingsInstallerAdapter = class _NodeTypingsInstallerAdapter extends TypingsInstallerAdapter {
187067
187298
  constructor(telemetryEnabled2, logger2, host, globalTypingsCacheLocation, typingSafeListLocation2, typesMapLocation2, npmLocation2, validateDefaultNpmLocation2, event) {
187068
- this.telemetryEnabled = telemetryEnabled2;
187069
- this.logger = logger2;
187070
- this.host = host;
187071
- this.globalTypingsCacheLocation = globalTypingsCacheLocation;
187299
+ super(
187300
+ telemetryEnabled2,
187301
+ logger2,
187302
+ host,
187303
+ globalTypingsCacheLocation,
187304
+ event,
187305
+ _NodeTypingsInstallerAdapter.maxActiveRequestCount
187306
+ );
187072
187307
  this.typingSafeListLocation = typingSafeListLocation2;
187073
187308
  this.typesMapLocation = typesMapLocation2;
187074
187309
  this.npmLocation = npmLocation2;
187075
187310
  this.validateDefaultNpmLocation = validateDefaultNpmLocation2;
187076
- this.event = event;
187077
- this.activeRequestCount = 0;
187078
- this.requestQueue = createQueue();
187079
- this.requestMap = /* @__PURE__ */ new Map();
187080
- // Maps operation ID to newest requestQueue entry with that ID
187081
- /** We will lazily request the types registry on the first call to `isKnownTypesPackageName` and store it in `typesRegistryCache`. */
187082
- this.requestedRegistry = false;
187083
- }
187084
- isKnownTypesPackageName(name) {
187085
- const validationResult = ts_JsTyping_exports.validatePackageName(name);
187086
- if (validationResult !== ts_JsTyping_exports.NameValidationResult.Ok) {
187087
- return false;
187088
- }
187089
- if (this.requestedRegistry) {
187090
- return !!this.typesRegistryCache && this.typesRegistryCache.has(name);
187091
- }
187092
- this.requestedRegistry = true;
187093
- this.send({ kind: "typesRegistry" });
187094
- return false;
187095
- }
187096
- installPackage(options2) {
187097
- this.send({ kind: "installPackage", ...options2 });
187098
- Debug.assert(this.packageInstalledPromise === void 0);
187099
- return new Promise((resolve, reject) => {
187100
- this.packageInstalledPromise = { resolve, reject };
187101
- });
187102
187311
  }
187103
- attach(projectService) {
187104
- this.projectService = projectService;
187312
+ createInstallerProcess() {
187105
187313
  if (this.logger.hasLevel(2 /* requestTime */)) {
187106
187314
  this.logger.info("Binding...");
187107
187315
  }
@@ -187140,135 +187348,7 @@ function startNodeSession(options, logger, cancellationToken) {
187140
187348
  process.on("exit", () => {
187141
187349
  this.installer.kill();
187142
187350
  });
187143
- }
187144
- onProjectClosed(p) {
187145
- this.send({ projectName: p.getProjectName(), kind: "closeProject" });
187146
- }
187147
- send(rq) {
187148
- this.installer.send(rq);
187149
- }
187150
- enqueueInstallTypingsRequest(project, typeAcquisition, unresolvedImports) {
187151
- const request = createInstallTypingsRequest(project, typeAcquisition, unresolvedImports);
187152
- if (this.logger.hasLevel(3 /* verbose */)) {
187153
- if (this.logger.hasLevel(3 /* verbose */)) {
187154
- this.logger.info(`Scheduling throttled operation:${stringifyIndented(request)}`);
187155
- }
187156
- }
187157
- const operationId = project.getProjectName();
187158
- const operation = () => {
187159
- if (this.logger.hasLevel(3 /* verbose */)) {
187160
- this.logger.info(`Sending request:${stringifyIndented(request)}`);
187161
- }
187162
- this.send(request);
187163
- };
187164
- const queuedRequest = { operationId, operation };
187165
- if (this.activeRequestCount < _NodeTypingsInstaller.maxActiveRequestCount) {
187166
- this.scheduleRequest(queuedRequest);
187167
- } else {
187168
- if (this.logger.hasLevel(3 /* verbose */)) {
187169
- this.logger.info(`Deferring request for: ${operationId}`);
187170
- }
187171
- this.requestQueue.enqueue(queuedRequest);
187172
- this.requestMap.set(operationId, queuedRequest);
187173
- }
187174
- }
187175
- handleMessage(response) {
187176
- if (this.logger.hasLevel(3 /* verbose */)) {
187177
- this.logger.info(`Received response:${stringifyIndented(response)}`);
187178
- }
187179
- switch (response.kind) {
187180
- case EventTypesRegistry:
187181
- this.typesRegistryCache = new Map(Object.entries(response.typesRegistry));
187182
- break;
187183
- case ActionPackageInstalled: {
187184
- const { success, message } = response;
187185
- if (success) {
187186
- this.packageInstalledPromise.resolve({ successMessage: message });
187187
- } else {
187188
- this.packageInstalledPromise.reject(message);
187189
- }
187190
- this.packageInstalledPromise = void 0;
187191
- this.projectService.updateTypingsForProject(response);
187192
- this.event(response, "setTypings");
187193
- break;
187194
- }
187195
- case EventInitializationFailed: {
187196
- const body = {
187197
- message: response.message
187198
- };
187199
- const eventName = "typesInstallerInitializationFailed";
187200
- this.event(body, eventName);
187201
- break;
187202
- }
187203
- case EventBeginInstallTypes: {
187204
- const body = {
187205
- eventId: response.eventId,
187206
- packages: response.packagesToInstall
187207
- };
187208
- const eventName = "beginInstallTypes";
187209
- this.event(body, eventName);
187210
- break;
187211
- }
187212
- case EventEndInstallTypes: {
187213
- if (this.telemetryEnabled) {
187214
- const body2 = {
187215
- telemetryEventName: "typingsInstalled",
187216
- payload: {
187217
- installedPackages: response.packagesToInstall.join(","),
187218
- installSuccess: response.installSuccess,
187219
- typingsInstallerVersion: response.typingsInstallerVersion
187220
- }
187221
- };
187222
- const eventName2 = "telemetry";
187223
- this.event(body2, eventName2);
187224
- }
187225
- const body = {
187226
- eventId: response.eventId,
187227
- packages: response.packagesToInstall,
187228
- success: response.installSuccess
187229
- };
187230
- const eventName = "endInstallTypes";
187231
- this.event(body, eventName);
187232
- break;
187233
- }
187234
- case ActionInvalidate: {
187235
- this.projectService.updateTypingsForProject(response);
187236
- break;
187237
- }
187238
- case ActionSet: {
187239
- if (this.activeRequestCount > 0) {
187240
- this.activeRequestCount--;
187241
- } else {
187242
- Debug.fail("Received too many responses");
187243
- }
187244
- while (!this.requestQueue.isEmpty()) {
187245
- const queuedRequest = this.requestQueue.dequeue();
187246
- if (this.requestMap.get(queuedRequest.operationId) === queuedRequest) {
187247
- this.requestMap.delete(queuedRequest.operationId);
187248
- this.scheduleRequest(queuedRequest);
187249
- break;
187250
- }
187251
- if (this.logger.hasLevel(3 /* verbose */)) {
187252
- this.logger.info(`Skipping defunct request for: ${queuedRequest.operationId}`);
187253
- }
187254
- }
187255
- this.projectService.updateTypingsForProject(response);
187256
- this.event(response, "setTypings");
187257
- break;
187258
- }
187259
- case ActionWatchTypingLocations:
187260
- this.projectService.watchTypingLocations(response);
187261
- break;
187262
- default:
187263
- assertType(response);
187264
- }
187265
- }
187266
- scheduleRequest(request) {
187267
- if (this.logger.hasLevel(3 /* verbose */)) {
187268
- this.logger.info(`Scheduling request for: ${request.operationId}`);
187269
- }
187270
- this.activeRequestCount++;
187271
- this.host.setTimeout(request.operation, _NodeTypingsInstaller.requestDelayMillis);
187351
+ return this.installer;
187272
187352
  }
187273
187353
  };
187274
187354
  // This number is essentially arbitrary. Processing more than one typings request
@@ -187276,21 +187356,20 @@ function startNodeSession(options, logger, cancellationToken) {
187276
187356
  // (see https://github.com/nodejs/node/issues/7657).
187277
187357
  // It would be preferable to base our limit on the amount of space left in the
187278
187358
  // buffer, but we have yet to find a way to retrieve that value.
187279
- _NodeTypingsInstaller.maxActiveRequestCount = 10;
187280
- _NodeTypingsInstaller.requestDelayMillis = 100;
187281
- let NodeTypingsInstaller = _NodeTypingsInstaller;
187359
+ _NodeTypingsInstallerAdapter.maxActiveRequestCount = 10;
187360
+ let NodeTypingsInstallerAdapter = _NodeTypingsInstallerAdapter;
187282
187361
  class IOSession extends Session3 {
187283
187362
  constructor() {
187284
187363
  const event = (body, eventName) => {
187285
187364
  this.event(body, eventName);
187286
187365
  };
187287
187366
  const host = sys;
187288
- const typingsInstaller = disableAutomaticTypingAcquisition ? void 0 : new NodeTypingsInstaller(telemetryEnabled, logger, host, getGlobalTypingsCacheLocation(), typingSafeListLocation, typesMapLocation, npmLocation, validateDefaultNpmLocation, event);
187367
+ const typingsInstaller = disableAutomaticTypingAcquisition ? void 0 : new NodeTypingsInstallerAdapter(telemetryEnabled, logger, host, getGlobalTypingsCacheLocation(), typingSafeListLocation, typesMapLocation, npmLocation, validateDefaultNpmLocation, event);
187289
187368
  super({
187290
187369
  host,
187291
187370
  cancellationToken,
187292
187371
  ...options,
187293
- typingsInstaller: typingsInstaller || nullTypingsInstaller,
187372
+ typingsInstaller,
187294
187373
  byteLength: Buffer.byteLength,
187295
187374
  hrtime: process.hrtime,
187296
187375
  logger,