typescript 4.8.0-dev.20220516 → 4.8.0-dev.20220519

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
@@ -100,7 +100,7 @@ var ts;
100
100
  // The following is baselined as a literal template type without intervention
101
101
  /** The version of the TypeScript compiler release */
102
102
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
103
- ts.version = ts.versionMajorMinor + ".0-dev.20220516";
103
+ ts.version = ts.versionMajorMinor + ".0-dev.20220519";
104
104
  /* @internal */
105
105
  var Comparison;
106
106
  (function (Comparison) {
@@ -58933,9 +58933,9 @@ var ts;
58933
58933
  t.flags & 2097152 /* Intersection */ ? getApparentTypeOfIntersectionType(t) :
58934
58934
  t.flags & 402653316 /* StringLike */ ? globalStringType :
58935
58935
  t.flags & 296 /* NumberLike */ ? globalNumberType :
58936
- t.flags & 2112 /* BigIntLike */ ? getGlobalBigIntType(/*reportErrors*/ languageVersion >= 7 /* ES2020 */) :
58936
+ t.flags & 2112 /* BigIntLike */ ? getGlobalBigIntType() :
58937
58937
  t.flags & 528 /* BooleanLike */ ? globalBooleanType :
58938
- t.flags & 12288 /* ESSymbolLike */ ? getGlobalESSymbolType(/*reportErrors*/ languageVersion >= 2 /* ES2015 */) :
58938
+ t.flags & 12288 /* ESSymbolLike */ ? getGlobalESSymbolType() :
58939
58939
  t.flags & 67108864 /* NonPrimitive */ ? emptyObjectType :
58940
58940
  t.flags & 4194304 /* Index */ ? keyofConstraintType :
58941
58941
  t.flags & 2 /* Unknown */ && !strictNullChecks ? emptyObjectType :
@@ -60510,8 +60510,8 @@ var ts;
60510
60510
  function getGlobalESSymbolConstructorTypeSymbol(reportErrors) {
60511
60511
  return deferredGlobalESSymbolConstructorTypeSymbol || (deferredGlobalESSymbolConstructorTypeSymbol = getGlobalTypeSymbol("SymbolConstructor", reportErrors));
60512
60512
  }
60513
- function getGlobalESSymbolType(reportErrors) {
60514
- return (deferredGlobalESSymbolType || (deferredGlobalESSymbolType = getGlobalType("Symbol", /*arity*/ 0, reportErrors))) || emptyObjectType;
60513
+ function getGlobalESSymbolType() {
60514
+ return (deferredGlobalESSymbolType || (deferredGlobalESSymbolType = getGlobalType("Symbol", /*arity*/ 0, /*reportErrors*/ false))) || emptyObjectType;
60515
60515
  }
60516
60516
  function getGlobalPromiseType(reportErrors) {
60517
60517
  return (deferredGlobalPromiseType || (deferredGlobalPromiseType = getGlobalType("Promise", /*arity*/ 1, reportErrors))) || emptyGenericType;
@@ -60575,8 +60575,8 @@ var ts;
60575
60575
  deferredGlobalAwaitedSymbol || (deferredGlobalAwaitedSymbol = getGlobalTypeAliasSymbol("Awaited", /*arity*/ 1, reportErrors) || (reportErrors ? unknownSymbol : undefined));
60576
60576
  return deferredGlobalAwaitedSymbol === unknownSymbol ? undefined : deferredGlobalAwaitedSymbol;
60577
60577
  }
60578
- function getGlobalBigIntType(reportErrors) {
60579
- return (deferredGlobalBigIntType || (deferredGlobalBigIntType = getGlobalType("BigInt", /*arity*/ 0, reportErrors))) || emptyObjectType;
60578
+ function getGlobalBigIntType() {
60579
+ return (deferredGlobalBigIntType || (deferredGlobalBigIntType = getGlobalType("BigInt", /*arity*/ 0, /*reportErrors*/ false))) || emptyObjectType;
60580
60580
  }
60581
60581
  /**
60582
60582
  * Instantiates a global type that is generic with some element type, and returns that instantiation.
@@ -64728,7 +64728,7 @@ var ts;
64728
64728
  if ((globalStringType === source && stringType === target) ||
64729
64729
  (globalNumberType === source && numberType === target) ||
64730
64730
  (globalBooleanType === source && booleanType === target) ||
64731
- (getGlobalESSymbolType(/*reportErrors*/ false) === source && esSymbolType === target)) {
64731
+ (getGlobalESSymbolType() === source && esSymbolType === target)) {
64732
64732
  reportError(ts.Diagnostics._0_is_a_primitive_but_1_is_a_wrapper_object_Prefer_using_0_when_possible, targetType, sourceType);
64733
64733
  }
64734
64734
  }
@@ -82616,7 +82616,7 @@ var ts;
82616
82616
  var childSymbol = getSymbolAtLocation(childNode);
82617
82617
  if (childSymbol && childSymbol === testedSymbol) {
82618
82618
  // If the test was a simple identifier, the above check is sufficient
82619
- if (ts.isIdentifier(expr)) {
82619
+ if (ts.isIdentifier(expr) || ts.isIdentifier(testedNode) && ts.isBinaryExpression(testedNode.parent)) {
82620
82620
  return true;
82621
82621
  }
82622
82622
  // Otherwise we need to ensure the symbol is called on the same target
@@ -115830,7 +115830,7 @@ var ts;
115830
115830
  };
115831
115831
  }
115832
115832
  // directoryExists
115833
- if (originalDirectoryExists && originalCreateDirectory) {
115833
+ if (originalDirectoryExists) {
115834
115834
  host.directoryExists = function (directory) {
115835
115835
  var key = toPath(directory);
115836
115836
  var value = directoryExistsCache.get(key);
@@ -115840,11 +115840,13 @@ var ts;
115840
115840
  directoryExistsCache.set(key, !!newValue);
115841
115841
  return newValue;
115842
115842
  };
115843
- host.createDirectory = function (directory) {
115844
- var key = toPath(directory);
115845
- directoryExistsCache.delete(key);
115846
- originalCreateDirectory.call(host, directory);
115847
- };
115843
+ if (originalCreateDirectory) {
115844
+ host.createDirectory = function (directory) {
115845
+ var key = toPath(directory);
115846
+ directoryExistsCache.delete(key);
115847
+ originalCreateDirectory.call(host, directory);
115848
+ };
115849
+ }
115848
115850
  }
115849
115851
  return {
115850
115852
  originalReadFile: originalReadFile,
@@ -127813,6 +127815,41 @@ var ts;
127813
127815
  return true;
127814
127816
  }
127815
127817
  ts.isTextWhiteSpaceLike = isTextWhiteSpaceLike;
127818
+ function getMappedLocation(location, sourceMapper, fileExists) {
127819
+ var mapsTo = sourceMapper.tryGetSourcePosition(location);
127820
+ return mapsTo && (!fileExists || fileExists(ts.normalizePath(mapsTo.fileName)) ? mapsTo : undefined);
127821
+ }
127822
+ ts.getMappedLocation = getMappedLocation;
127823
+ function getMappedDocumentSpan(documentSpan, sourceMapper, fileExists) {
127824
+ var fileName = documentSpan.fileName, textSpan = documentSpan.textSpan;
127825
+ var newPosition = getMappedLocation({ fileName: fileName, pos: textSpan.start }, sourceMapper, fileExists);
127826
+ if (!newPosition)
127827
+ return undefined;
127828
+ var newEndPosition = getMappedLocation({ fileName: fileName, pos: textSpan.start + textSpan.length }, sourceMapper, fileExists);
127829
+ var newLength = newEndPosition
127830
+ ? newEndPosition.pos - newPosition.pos
127831
+ : textSpan.length; // This shouldn't happen
127832
+ return {
127833
+ fileName: newPosition.fileName,
127834
+ textSpan: {
127835
+ start: newPosition.pos,
127836
+ length: newLength,
127837
+ },
127838
+ originalFileName: documentSpan.fileName,
127839
+ originalTextSpan: documentSpan.textSpan,
127840
+ contextSpan: getMappedContextSpan(documentSpan, sourceMapper, fileExists),
127841
+ originalContextSpan: documentSpan.contextSpan
127842
+ };
127843
+ }
127844
+ ts.getMappedDocumentSpan = getMappedDocumentSpan;
127845
+ function getMappedContextSpan(documentSpan, sourceMapper, fileExists) {
127846
+ var contextSpanStart = documentSpan.contextSpan && getMappedLocation({ fileName: documentSpan.fileName, pos: documentSpan.contextSpan.start }, sourceMapper, fileExists);
127847
+ var contextSpanEnd = documentSpan.contextSpan && getMappedLocation({ fileName: documentSpan.fileName, pos: documentSpan.contextSpan.start + documentSpan.contextSpan.length }, sourceMapper, fileExists);
127848
+ return contextSpanStart && contextSpanEnd ?
127849
+ { start: contextSpanStart.pos, length: contextSpanEnd.pos - contextSpanStart.pos } :
127850
+ undefined;
127851
+ }
127852
+ ts.getMappedContextSpan = getMappedContextSpan;
127816
127853
  // #endregion
127817
127854
  // Display-part writer helpers
127818
127855
  // #region
@@ -136734,6 +136771,7 @@ var ts;
136734
136771
  var commonjsSource = source && ts.isBinaryExpression(source) ? source.left : undefined;
136735
136772
  return !!(source && ((_a = target.declarations) === null || _a === void 0 ? void 0 : _a.some(function (d) { return d === source || d === commonjsSource; })));
136736
136773
  }
136774
+ FindAllReferences.isDeclarationOfSymbol = isDeclarationOfSymbol;
136737
136775
  /**
136738
136776
  * True if 'decl' provides a value, as in `function f() {}`;
136739
136777
  * false if 'decl' is just a location for a future write, as in 'let x;'
@@ -163893,9 +163931,8 @@ var ts;
163893
163931
  var isStaticMember = ts.hasStaticModifier(declaration);
163894
163932
  return ts.firstDefined(ts.getAllSuperTypeNodes(classOrInterfaceDeclaration), function (superTypeNode) {
163895
163933
  var baseType = checker.getTypeAtLocation(superTypeNode);
163896
- var symbol = isStaticMember
163897
- ? ts.find(checker.getExportsOfModule(baseType.symbol), function (s) { return s.escapedName === declaration.symbol.name; })
163898
- : checker.getPropertyOfType(baseType, declaration.symbol.name);
163934
+ var type = isStaticMember && baseType.symbol ? checker.getTypeOfSymbol(baseType.symbol) : baseType;
163935
+ var symbol = checker.getPropertyOfType(type, declaration.symbol.name);
163899
163936
  return symbol ? cb(symbol) : undefined;
163900
163937
  });
163901
163938
  }
@@ -164138,70 +164175,6 @@ var ts;
164138
164175
  return ts.codefix.getSupportedErrorCodes();
164139
164176
  }
164140
164177
  ts.getSupportedCodeFixes = getSupportedCodeFixes;
164141
- // Cache host information about script Should be refreshed
164142
- // at each language service public entry point, since we don't know when
164143
- // the set of scripts handled by the host changes.
164144
- var HostCache = /** @class */ (function () {
164145
- function HostCache(host, getCanonicalFileName) {
164146
- this.host = host;
164147
- // script id => script index
164148
- this.currentDirectory = host.getCurrentDirectory();
164149
- this.fileNameToEntry = new ts.Map();
164150
- // Initialize the list with the root file names
164151
- var rootFileNames = host.getScriptFileNames();
164152
- ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("session" /* Session */, "initializeHostCache", { count: rootFileNames.length });
164153
- for (var _i = 0, rootFileNames_1 = rootFileNames; _i < rootFileNames_1.length; _i++) {
164154
- var fileName = rootFileNames_1[_i];
164155
- this.createEntry(fileName, ts.toPath(fileName, this.currentDirectory, getCanonicalFileName));
164156
- }
164157
- ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
164158
- }
164159
- HostCache.prototype.createEntry = function (fileName, path) {
164160
- var entry;
164161
- var scriptSnapshot = this.host.getScriptSnapshot(fileName);
164162
- if (scriptSnapshot) {
164163
- entry = {
164164
- hostFileName: fileName,
164165
- version: this.host.getScriptVersion(fileName),
164166
- scriptSnapshot: scriptSnapshot,
164167
- scriptKind: ts.getScriptKind(fileName, this.host)
164168
- };
164169
- }
164170
- else {
164171
- entry = fileName;
164172
- }
164173
- this.fileNameToEntry.set(path, entry);
164174
- return entry;
164175
- };
164176
- HostCache.prototype.getEntryByPath = function (path) {
164177
- return this.fileNameToEntry.get(path);
164178
- };
164179
- HostCache.prototype.getHostFileInformation = function (path) {
164180
- var entry = this.fileNameToEntry.get(path);
164181
- return !ts.isString(entry) ? entry : undefined;
164182
- };
164183
- HostCache.prototype.getOrCreateEntryByPath = function (fileName, path) {
164184
- var info = this.getEntryByPath(path) || this.createEntry(fileName, path);
164185
- return ts.isString(info) ? undefined : info; // TODO: GH#18217
164186
- };
164187
- HostCache.prototype.getRootFileNames = function () {
164188
- var names = [];
164189
- this.fileNameToEntry.forEach(function (entry) {
164190
- if (ts.isString(entry)) {
164191
- names.push(entry);
164192
- }
164193
- else {
164194
- names.push(entry.hostFileName);
164195
- }
164196
- });
164197
- return names;
164198
- };
164199
- HostCache.prototype.getScriptSnapshot = function (path) {
164200
- var file = this.getHostFileInformation(path);
164201
- return (file && file.scriptSnapshot); // TODO: GH#18217
164202
- };
164203
- return HostCache;
164204
- }());
164205
164178
  var SyntaxTreeCache = /** @class */ (function () {
164206
164179
  function SyntaxTreeCache(host) {
164207
164180
  this.host = host;
@@ -164463,32 +164436,13 @@ var ts;
164463
164436
  program = undefined; // TODO: GH#18217
164464
164437
  lastTypesRootVersion = typeRootsVersion;
164465
164438
  }
164439
+ var rootFileNames = host.getScriptFileNames();
164466
164440
  // Get a fresh cache of the host information
164467
- var hostCache = new HostCache(host, getCanonicalFileName);
164468
- var rootFileNames = hostCache.getRootFileNames();
164469
164441
  var newSettings = host.getCompilationSettings() || getDefaultCompilerOptions();
164470
164442
  var hasInvalidatedResolution = host.hasInvalidatedResolution || ts.returnFalse;
164471
164443
  var hasChangedAutomaticTypeDirectiveNames = ts.maybeBind(host, host.hasChangedAutomaticTypeDirectiveNames);
164472
164444
  var projectReferences = (_b = host.getProjectReferences) === null || _b === void 0 ? void 0 : _b.call(host);
164473
164445
  var parsedCommandLines;
164474
- var parseConfigHost = {
164475
- useCaseSensitiveFileNames: useCaseSensitiveFileNames,
164476
- fileExists: fileExists,
164477
- readFile: readFile,
164478
- readDirectory: readDirectory,
164479
- trace: ts.maybeBind(host, host.trace),
164480
- getCurrentDirectory: function () { return currentDirectory; },
164481
- onUnRecoverableConfigFileDiagnostic: ts.noop,
164482
- };
164483
- // If the program is already up-to-date, we can reuse it
164484
- if (ts.isProgramUptoDate(program, rootFileNames, newSettings, function (_path, fileName) { return host.getScriptVersion(fileName); }, fileExists, hasInvalidatedResolution, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) {
164485
- return;
164486
- }
164487
- // IMPORTANT - It is critical from this moment onward that we do not check
164488
- // cancellation tokens. We are about to mutate source files from a previous program
164489
- // instance. If we cancel midway through, we may end up in an inconsistent state where
164490
- // the program points to old source files that have been invalidated because of
164491
- // incremental parsing.
164492
164446
  // Now create a new compiler
164493
164447
  var compilerHost = {
164494
164448
  getSourceFile: getOrCreateSourceFile,
@@ -164500,8 +164454,8 @@ var ts;
164500
164454
  getDefaultLibFileName: function (options) { return host.getDefaultLibFileName(options); },
164501
164455
  writeFile: ts.noop,
164502
164456
  getCurrentDirectory: function () { return currentDirectory; },
164503
- fileExists: fileExists,
164504
- readFile: readFile,
164457
+ fileExists: function (fileName) { return host.fileExists(fileName); },
164458
+ readFile: function (fileName) { return host.readFile && host.readFile(fileName); },
164505
164459
  getSymlinkCache: ts.maybeBind(host, host.getSymlinkCache),
164506
164460
  realpath: ts.maybeBind(host, host.realpath),
164507
164461
  directoryExists: function (directoryName) {
@@ -164510,19 +164464,56 @@ var ts;
164510
164464
  getDirectories: function (path) {
164511
164465
  return host.getDirectories ? host.getDirectories(path) : [];
164512
164466
  },
164513
- readDirectory: readDirectory,
164467
+ readDirectory: function (path, extensions, exclude, include, depth) {
164468
+ ts.Debug.checkDefined(host.readDirectory, "'LanguageServiceHost.readDirectory' must be implemented to correctly process 'projectReferences'");
164469
+ return host.readDirectory(path, extensions, exclude, include, depth);
164470
+ },
164514
164471
  onReleaseOldSourceFile: onReleaseOldSourceFile,
164515
164472
  onReleaseParsedCommandLine: onReleaseParsedCommandLine,
164516
164473
  hasInvalidatedResolution: hasInvalidatedResolution,
164517
164474
  hasChangedAutomaticTypeDirectiveNames: hasChangedAutomaticTypeDirectiveNames,
164518
- trace: parseConfigHost.trace,
164475
+ trace: ts.maybeBind(host, host.trace),
164519
164476
  resolveModuleNames: ts.maybeBind(host, host.resolveModuleNames),
164520
164477
  getModuleResolutionCache: ts.maybeBind(host, host.getModuleResolutionCache),
164521
164478
  resolveTypeReferenceDirectives: ts.maybeBind(host, host.resolveTypeReferenceDirectives),
164522
164479
  useSourceOfProjectReferenceRedirect: ts.maybeBind(host, host.useSourceOfProjectReferenceRedirect),
164523
164480
  getParsedCommandLine: getParsedCommandLine,
164524
164481
  };
164482
+ var originalGetSourceFile = compilerHost.getSourceFile;
164483
+ var getSourceFileWithCache = ts.changeCompilerHostLikeToUseCache(compilerHost, function (fileName) { return ts.toPath(fileName, currentDirectory, getCanonicalFileName); }, function () {
164484
+ var args = [];
164485
+ for (var _i = 0; _i < arguments.length; _i++) {
164486
+ args[_i] = arguments[_i];
164487
+ }
164488
+ return originalGetSourceFile.call.apply(originalGetSourceFile, __spreadArray([compilerHost], args, false));
164489
+ }).getSourceFileWithCache;
164490
+ compilerHost.getSourceFile = getSourceFileWithCache;
164525
164491
  (_c = host.setCompilerHost) === null || _c === void 0 ? void 0 : _c.call(host, compilerHost);
164492
+ var parseConfigHost = {
164493
+ useCaseSensitiveFileNames: useCaseSensitiveFileNames,
164494
+ fileExists: function (fileName) { return compilerHost.fileExists(fileName); },
164495
+ readFile: function (fileName) { return compilerHost.readFile(fileName); },
164496
+ readDirectory: function () {
164497
+ var _a;
164498
+ var args = [];
164499
+ for (var _i = 0; _i < arguments.length; _i++) {
164500
+ args[_i] = arguments[_i];
164501
+ }
164502
+ return (_a = compilerHost).readDirectory.apply(_a, args);
164503
+ },
164504
+ trace: compilerHost.trace,
164505
+ getCurrentDirectory: compilerHost.getCurrentDirectory,
164506
+ onUnRecoverableConfigFileDiagnostic: ts.noop,
164507
+ };
164508
+ // If the program is already up-to-date, we can reuse it
164509
+ if (ts.isProgramUptoDate(program, rootFileNames, newSettings, function (_path, fileName) { return host.getScriptVersion(fileName); }, function (fileName) { return compilerHost.fileExists(fileName); }, hasInvalidatedResolution, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) {
164510
+ return;
164511
+ }
164512
+ // IMPORTANT - It is critical from this moment onward that we do not check
164513
+ // cancellation tokens. We are about to mutate source files from a previous program
164514
+ // instance. If we cancel midway through, we may end up in an inconsistent state where
164515
+ // the program points to old source files that have been invalidated because of
164516
+ // incremental parsing.
164526
164517
  var documentRegistryBucketKey = documentRegistry.getKeyForCompilationSettings(newSettings);
164527
164518
  var options = {
164528
164519
  rootNames: rootFileNames,
@@ -164532,9 +164523,9 @@ var ts;
164532
164523
  projectReferences: projectReferences
164533
164524
  };
164534
164525
  program = ts.createProgram(options);
164535
- // hostCache is captured in the closure for 'getOrCreateSourceFile' but it should not be used past this point.
164536
- // It needs to be cleared to allow all collected snapshots to be released
164537
- hostCache = undefined;
164526
+ // 'getOrCreateSourceFile' depends on caching but should be used past this point.
164527
+ // After this point, the cache needs to be cleared to allow all collected snapshots to be released
164528
+ compilerHost = undefined;
164538
164529
  parsedCommandLines = undefined;
164539
164530
  // We reset this cache on structure invalidation so we don't hold on to outdated files for long; however we can't use the `compilerHost` above,
164540
164531
  // Because it only functions until `hostCache` is cleared, while we'll potentially need the functionality to lazily read sourcemap files during
@@ -164574,26 +164565,6 @@ var ts;
164574
164565
  onReleaseOldSourceFile(oldResolvedRef.sourceFile, oldOptions);
164575
164566
  }
164576
164567
  }
164577
- function fileExists(fileName) {
164578
- var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
164579
- var entry = hostCache && hostCache.getEntryByPath(path);
164580
- return entry ?
164581
- !ts.isString(entry) :
164582
- (!!host.fileExists && host.fileExists(fileName));
164583
- }
164584
- function readFile(fileName) {
164585
- // stub missing host functionality
164586
- var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
164587
- var entry = hostCache && hostCache.getEntryByPath(path);
164588
- if (entry) {
164589
- return ts.isString(entry) ? undefined : ts.getSnapshotText(entry.scriptSnapshot);
164590
- }
164591
- return host.readFile && host.readFile(fileName);
164592
- }
164593
- function readDirectory(path, extensions, exclude, include, depth) {
164594
- ts.Debug.checkDefined(host.readDirectory, "'LanguageServiceHost.readDirectory' must be implemented to correctly process 'projectReferences'");
164595
- return host.readDirectory(path, extensions, exclude, include, depth);
164596
- }
164597
164568
  // Release any files we have acquired in the old program but are
164598
164569
  // not part of the new program.
164599
164570
  function onReleaseOldSourceFile(oldSourceFile, oldOptions) {
@@ -164604,14 +164575,16 @@ var ts;
164604
164575
  return getOrCreateSourceFileByPath(fileName, ts.toPath(fileName, currentDirectory, getCanonicalFileName), languageVersion, onError, shouldCreateNewSourceFile);
164605
164576
  }
164606
164577
  function getOrCreateSourceFileByPath(fileName, path, _languageVersion, _onError, shouldCreateNewSourceFile) {
164607
- ts.Debug.assert(hostCache !== undefined, "getOrCreateSourceFileByPath called after typical CompilerHost lifetime, check the callstack something with a reference to an old host.");
164578
+ ts.Debug.assert(compilerHost, "getOrCreateSourceFileByPath called after typical CompilerHost lifetime, check the callstack something with a reference to an old host.");
164608
164579
  // The program is asking for this file, check first if the host can locate it.
164609
164580
  // If the host can not locate the file, then it does not exist. return undefined
164610
164581
  // to the program to allow reporting of errors for missing files.
164611
- var hostFileInformation = hostCache && hostCache.getOrCreateEntryByPath(fileName, path);
164612
- if (!hostFileInformation) {
164582
+ var scriptSnapshot = host.getScriptSnapshot(fileName);
164583
+ if (!scriptSnapshot) {
164613
164584
  return undefined;
164614
164585
  }
164586
+ var scriptKind = ts.getScriptKind(fileName, host);
164587
+ var scriptVersion = host.getScriptVersion(fileName);
164615
164588
  // Check if the language version has changed since we last created a program; if they are the same,
164616
164589
  // it is safe to reuse the sourceFiles; if not, then the shape of the AST can change, and the oldSourceFile
164617
164590
  // can not be reused. we have to dump all syntax trees and create new ones.
@@ -164643,8 +164616,8 @@ var ts;
164643
164616
  // We do not support the scenario where a host can modify a registered
164644
164617
  // file's script kind, i.e. in one project some file is treated as ".ts"
164645
164618
  // and in another as ".js"
164646
- if (hostFileInformation.scriptKind === oldSourceFile.scriptKind) {
164647
- return documentRegistry.updateDocumentWithKey(fileName, path, host, documentRegistryBucketKey, hostFileInformation.scriptSnapshot, hostFileInformation.version, hostFileInformation.scriptKind);
164619
+ if (scriptKind === oldSourceFile.scriptKind) {
164620
+ return documentRegistry.updateDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind);
164648
164621
  }
164649
164622
  else {
164650
164623
  // Release old source file and fall through to aquire new file with new script kind
@@ -164654,7 +164627,7 @@ var ts;
164654
164627
  // We didn't already have the file. Fall through and acquire it from the registry.
164655
164628
  }
164656
164629
  // Could not find this file in the old program, create a new SourceFile for it.
164657
- return documentRegistry.acquireDocumentWithKey(fileName, path, host, documentRegistryBucketKey, hostFileInformation.scriptSnapshot, hostFileInformation.version, hostFileInformation.scriptKind);
164630
+ return documentRegistry.acquireDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind);
164658
164631
  }
164659
164632
  }
164660
164633
  // TODO: GH#18217 frequently asserted as defined
@@ -164670,6 +164643,61 @@ var ts;
164670
164643
  var _a;
164671
164644
  return (_a = host.getPackageJsonAutoImportProvider) === null || _a === void 0 ? void 0 : _a.call(host);
164672
164645
  }
164646
+ function updateIsDefinitionOfReferencedSymbols(referencedSymbols, knownSymbolSpans) {
164647
+ var checker = program.getTypeChecker();
164648
+ var symbol = getSymbolForProgram();
164649
+ if (!symbol)
164650
+ return false;
164651
+ for (var _i = 0, referencedSymbols_1 = referencedSymbols; _i < referencedSymbols_1.length; _i++) {
164652
+ var referencedSymbol = referencedSymbols_1[_i];
164653
+ for (var _a = 0, _b = referencedSymbol.references; _a < _b.length; _a++) {
164654
+ var ref = _b[_a];
164655
+ var refNode = getNodeForSpan(ref);
164656
+ ts.Debug.assertIsDefined(refNode);
164657
+ if (knownSymbolSpans.has(ref) || ts.FindAllReferences.isDeclarationOfSymbol(refNode, symbol)) {
164658
+ knownSymbolSpans.add(ref);
164659
+ ref.isDefinition = true;
164660
+ var mappedSpan = ts.getMappedDocumentSpan(ref, sourceMapper, ts.maybeBind(host, host.fileExists));
164661
+ if (mappedSpan) {
164662
+ knownSymbolSpans.add(mappedSpan);
164663
+ }
164664
+ }
164665
+ else {
164666
+ ref.isDefinition = false;
164667
+ }
164668
+ }
164669
+ }
164670
+ return true;
164671
+ function getSymbolForProgram() {
164672
+ for (var _i = 0, referencedSymbols_2 = referencedSymbols; _i < referencedSymbols_2.length; _i++) {
164673
+ var referencedSymbol = referencedSymbols_2[_i];
164674
+ for (var _a = 0, _b = referencedSymbol.references; _a < _b.length; _a++) {
164675
+ var ref = _b[_a];
164676
+ if (knownSymbolSpans.has(ref)) {
164677
+ var refNode = getNodeForSpan(ref);
164678
+ ts.Debug.assertIsDefined(refNode);
164679
+ return checker.getSymbolAtLocation(refNode);
164680
+ }
164681
+ var mappedSpan = ts.getMappedDocumentSpan(ref, sourceMapper, ts.maybeBind(host, host.fileExists));
164682
+ if (mappedSpan && knownSymbolSpans.has(mappedSpan)) {
164683
+ var refNode = getNodeForSpan(mappedSpan);
164684
+ if (refNode) {
164685
+ return checker.getSymbolAtLocation(refNode);
164686
+ }
164687
+ }
164688
+ }
164689
+ }
164690
+ return undefined;
164691
+ }
164692
+ function getNodeForSpan(docSpan) {
164693
+ var sourceFile = program.getSourceFile(docSpan.fileName);
164694
+ if (!sourceFile)
164695
+ return undefined;
164696
+ var rawNode = ts.getTouchingPropertyName(sourceFile, docSpan.textSpan.start);
164697
+ var adjustedNode = ts.FindAllReferences.Core.getAdjustedNode(rawNode, { use: 1 /* References */ });
164698
+ return adjustedNode;
164699
+ }
164700
+ }
164673
164701
  function cleanupSemanticCache() {
164674
164702
  program = undefined; // TODO: GH#18217
164675
164703
  }
@@ -165596,6 +165624,7 @@ var ts;
165596
165624
  getNonBoundSourceFile: getNonBoundSourceFile,
165597
165625
  getProgram: getProgram,
165598
165626
  getAutoImportProvider: getAutoImportProvider,
165627
+ updateIsDefinitionOfReferencedSymbols: updateIsDefinitionOfReferencedSymbols,
165599
165628
  getApplicableRefactors: getApplicableRefactors,
165600
165629
  getEditsForRefactor: getEditsForRefactor,
165601
165630
  toLineColumnOffset: toLineColumnOffset,
@@ -174736,66 +174765,142 @@ var ts;
174736
174765
  return textSpan.start + 100003 * textSpan.length;
174737
174766
  }, ts.documentSpansEqual);
174738
174767
  }
174739
- function combineProjectOutputForRenameLocations(projects, defaultProject, initialLocation, findInStrings, findInComments, _a) {
174768
+ function getRenameLocationsWorker(projects, defaultProject, initialLocation, findInStrings, findInComments, _a) {
174740
174769
  var providePrefixAndSuffixTextForRename = _a.providePrefixAndSuffixTextForRename;
174741
- var outputs = [];
174770
+ var perProjectResults = getPerProjectReferences(projects, defaultProject, initialLocation,
174771
+ /*isForRename*/ true, function (project, position) { return project.getLanguageService().findRenameLocations(position.fileName, position.pos, findInStrings, findInComments, providePrefixAndSuffixTextForRename); }, function (renameLocation, cb) { return cb(documentSpanLocation(renameLocation)); });
174772
+ // No filtering or dedup'ing is required if there's exactly one project
174773
+ if (ts.isArray(perProjectResults)) {
174774
+ return perProjectResults;
174775
+ }
174776
+ var results = [];
174742
174777
  var seen = createDocumentSpanSet();
174743
- combineProjectOutputWorker(projects, defaultProject, initialLocation,
174744
- /*isForRename*/ true, function (project, location, tryAddToTodo) {
174745
- var projectOutputs = project.getLanguageService().findRenameLocations(location.fileName, location.pos, findInStrings, findInComments, providePrefixAndSuffixTextForRename);
174746
- if (projectOutputs) {
174747
- for (var _i = 0, projectOutputs_1 = projectOutputs; _i < projectOutputs_1.length; _i++) {
174748
- var output = projectOutputs_1[_i];
174749
- if (!seen.has(output) && !tryAddToTodo(project, documentSpanLocation(output))) {
174750
- seen.add(output);
174751
- outputs.push(output);
174752
- }
174778
+ perProjectResults.forEach(function (projectResults, project) {
174779
+ for (var _i = 0, projectResults_1 = projectResults; _i < projectResults_1.length; _i++) {
174780
+ var result = projectResults_1[_i];
174781
+ // If there's a mapped location, it'll appear in the results for another project
174782
+ if (!seen.has(result) && !getMappedLocationForProject(documentSpanLocation(result), project)) {
174783
+ results.push(result);
174784
+ seen.add(result);
174753
174785
  }
174754
174786
  }
174755
174787
  });
174756
- return outputs;
174788
+ return results;
174757
174789
  }
174758
174790
  function getDefinitionLocation(defaultProject, initialLocation, isForRename) {
174759
- var infos = defaultProject.getLanguageService().getDefinitionAtPosition(initialLocation.fileName, initialLocation.pos, /*searchOtherFilesOnly*/ false, isForRename);
174791
+ var infos = defaultProject.getLanguageService().getDefinitionAtPosition(initialLocation.fileName, initialLocation.pos, /*searchOtherFilesOnly*/ false, /*stopAtAlias*/ isForRename);
174760
174792
  var info = infos && ts.firstOrUndefined(infos);
174761
174793
  return info && !info.isLocal ? { fileName: info.fileName, pos: info.textSpan.start } : undefined;
174762
174794
  }
174763
- function combineProjectOutputForReferences(projects, defaultProject, initialLocation, logger) {
174764
- var outputs = [];
174765
- combineProjectOutputWorker(projects, defaultProject, initialLocation,
174766
- /*isForRename*/ false, function (project, location, getMappedLocation) {
174767
- var _a, _b;
174768
- logger.info("Finding references to " + location.fileName + " position " + location.pos + " in project " + project.getProjectName());
174769
- var projectOutputs = project.getLanguageService().findReferences(location.fileName, location.pos);
174770
- if (projectOutputs) {
174771
- var clearIsDefinition = ((_b = (_a = projectOutputs[0]) === null || _a === void 0 ? void 0 : _a.references[0]) === null || _b === void 0 ? void 0 : _b.isDefinition) === undefined;
174772
- var _loop_9 = function (referencedSymbol) {
174773
- var mappedDefinitionFile = getMappedLocation(project, documentSpanLocation(referencedSymbol.definition));
174774
- var definition = mappedDefinitionFile === undefined ?
174775
- referencedSymbol.definition : __assign(__assign({}, referencedSymbol.definition), { textSpan: ts.createTextSpan(mappedDefinitionFile.pos, referencedSymbol.definition.textSpan.length), fileName: mappedDefinitionFile.fileName, contextSpan: getMappedContextSpan(referencedSymbol.definition, project) });
174776
- var symbolToAddTo = ts.find(outputs, function (o) { return ts.documentSpansEqual(o.definition, definition); });
174777
- if (!symbolToAddTo) {
174778
- symbolToAddTo = { definition: definition, references: [] };
174779
- outputs.push(symbolToAddTo);
174780
- }
174781
- for (var _c = 0, _d = referencedSymbol.references; _c < _d.length; _c++) {
174782
- var ref = _d[_c];
174783
- // If it's in a mapped file, that is added to the todo list by `getMappedLocation`.
174784
- if (!ts.contains(symbolToAddTo.references, ref, ts.documentSpansEqual) && !getMappedLocation(project, documentSpanLocation(ref))) {
174785
- if (clearIsDefinition) {
174786
- delete ref.isDefinition;
174787
- }
174788
- symbolToAddTo.references.push(ref);
174789
- }
174795
+ function getReferencesWorker(projects, defaultProject, initialLocation, logger) {
174796
+ var perProjectResults = getPerProjectReferences(projects, defaultProject, initialLocation,
174797
+ /*isForRename*/ false, function (project, position) {
174798
+ logger.info("Finding references to " + position.fileName + " position " + position.pos + " in project " + project.getProjectName());
174799
+ return project.getLanguageService().findReferences(position.fileName, position.pos);
174800
+ }, function (referencedSymbol, cb) {
174801
+ cb(documentSpanLocation(referencedSymbol.definition));
174802
+ for (var _i = 0, _a = referencedSymbol.references; _i < _a.length; _i++) {
174803
+ var ref = _a[_i];
174804
+ cb(documentSpanLocation(ref));
174805
+ }
174806
+ });
174807
+ // No re-mapping or isDefinition updatses are required if there's exactly one project
174808
+ if (ts.isArray(perProjectResults)) {
174809
+ return perProjectResults;
174810
+ }
174811
+ // `isDefinition` is only (definitely) correct in `defaultProject` because we might
174812
+ // have started the other project searches from related symbols. Propagate the
174813
+ // correct results to all other projects.
174814
+ var defaultProjectResults = perProjectResults.get(defaultProject);
174815
+ if (defaultProjectResults[0].references[0].isDefinition === undefined) {
174816
+ // Clear all isDefinition properties
174817
+ perProjectResults.forEach(function (projectResults) {
174818
+ for (var _i = 0, projectResults_2 = projectResults; _i < projectResults_2.length; _i++) {
174819
+ var referencedSymbol = projectResults_2[_i];
174820
+ for (var _a = 0, _b = referencedSymbol.references; _a < _b.length; _a++) {
174821
+ var ref = _b[_a];
174822
+ delete ref.isDefinition;
174823
+ }
174824
+ }
174825
+ });
174826
+ }
174827
+ else {
174828
+ // Correct isDefinition properties from projects other than defaultProject
174829
+ var knownSymbolSpans_1 = createDocumentSpanSet();
174830
+ for (var _i = 0, defaultProjectResults_1 = defaultProjectResults; _i < defaultProjectResults_1.length; _i++) {
174831
+ var referencedSymbol = defaultProjectResults_1[_i];
174832
+ for (var _a = 0, _b = referencedSymbol.references; _a < _b.length; _a++) {
174833
+ var ref = _b[_a];
174834
+ if (ref.isDefinition) {
174835
+ knownSymbolSpans_1.add(ref);
174836
+ // One is enough - updateIsDefinitionOfReferencedSymbols will fill out the set based on symbols
174837
+ break;
174838
+ }
174839
+ }
174840
+ }
174841
+ var updatedProjects_1 = new ts.Set();
174842
+ var _loop_9 = function () {
174843
+ var progress = false;
174844
+ perProjectResults.forEach(function (referencedSymbols, project) {
174845
+ if (updatedProjects_1.has(project))
174846
+ return;
174847
+ var updated = project.getLanguageService().updateIsDefinitionOfReferencedSymbols(referencedSymbols, knownSymbolSpans_1);
174848
+ if (updated) {
174849
+ updatedProjects_1.add(project);
174850
+ progress = true;
174851
+ }
174852
+ });
174853
+ if (!progress)
174854
+ return "break";
174855
+ };
174856
+ while (true) {
174857
+ var state_2 = _loop_9();
174858
+ if (state_2 === "break")
174859
+ break;
174860
+ }
174861
+ perProjectResults.forEach(function (referencedSymbols, project) {
174862
+ if (updatedProjects_1.has(project))
174863
+ return;
174864
+ for (var _i = 0, referencedSymbols_1 = referencedSymbols; _i < referencedSymbols_1.length; _i++) {
174865
+ var referencedSymbol = referencedSymbols_1[_i];
174866
+ for (var _a = 0, _b = referencedSymbol.references; _a < _b.length; _a++) {
174867
+ var ref = _b[_a];
174868
+ ref.isDefinition = false;
174790
174869
  }
174791
- };
174792
- for (var _i = 0, projectOutputs_2 = projectOutputs; _i < projectOutputs_2.length; _i++) {
174793
- var referencedSymbol = projectOutputs_2[_i];
174794
- _loop_9(referencedSymbol);
174795
174870
  }
174871
+ });
174872
+ }
174873
+ // We need to de-duplicate and aggregate the results by choosing an authoritative version
174874
+ // of each definition and merging references from all the projects where they appear.
174875
+ var results = [];
174876
+ var seenRefs = createDocumentSpanSet(); // It doesn't make sense to have a reference in two definition lists, so we de-dup globally
174877
+ // TODO: We might end up with a more logical allocation of refs to defs if we pre-sorted the defs by descending ref-count.
174878
+ // Otherwise, it just ends up attached to the first corresponding def we happen to process. The others may or may not be
174879
+ // dropped later when we check for defs with ref-count 0.
174880
+ perProjectResults.forEach(function (projectResults, project) {
174881
+ var _loop_10 = function (referencedSymbol) {
174882
+ var mappedDefinitionFile = getMappedLocationForProject(documentSpanLocation(referencedSymbol.definition), project);
174883
+ var definition = mappedDefinitionFile === undefined ?
174884
+ referencedSymbol.definition : __assign(__assign({}, referencedSymbol.definition), { textSpan: ts.createTextSpan(mappedDefinitionFile.pos, referencedSymbol.definition.textSpan.length), fileName: mappedDefinitionFile.fileName, contextSpan: getMappedContextSpanForProject(referencedSymbol.definition, project) });
174885
+ var symbolToAddTo = ts.find(results, function (o) { return ts.documentSpansEqual(o.definition, definition); });
174886
+ if (!symbolToAddTo) {
174887
+ symbolToAddTo = { definition: definition, references: [] };
174888
+ results.push(symbolToAddTo);
174889
+ }
174890
+ for (var _a = 0, _b = referencedSymbol.references; _a < _b.length; _a++) {
174891
+ var ref = _b[_a];
174892
+ if (!seenRefs.has(ref) && !getMappedLocationForProject(documentSpanLocation(ref), project)) {
174893
+ seenRefs.add(ref);
174894
+ symbolToAddTo.references.push(ref);
174895
+ }
174896
+ }
174897
+ };
174898
+ for (var _i = 0, projectResults_3 = projectResults; _i < projectResults_3.length; _i++) {
174899
+ var referencedSymbol = projectResults_3[_i];
174900
+ _loop_10(referencedSymbol);
174796
174901
  }
174797
174902
  });
174798
- return outputs.filter(function (o) { return o.references.length !== 0; });
174903
+ return results.filter(function (o) { return o.references.length !== 0; });
174799
174904
  }
174800
174905
  function forEachProjectInProjects(projects, path, cb) {
174801
174906
  for (var _i = 0, _a = ts.isArray(projects) ? projects : projects.projects; _i < _a.length; _i++) {
@@ -174811,40 +174916,117 @@ var ts;
174811
174916
  });
174812
174917
  }
174813
174918
  }
174814
- function combineProjectOutputWorker(projects, defaultProject, initialLocation, isForRename, cb) {
174815
- var projectService = defaultProject.projectService;
174816
- var toDo;
174817
- var seenProjects = new ts.Set();
174818
- forEachProjectInProjects(projects, initialLocation && initialLocation.fileName, function (project, path) {
174819
- // TLocation should be either `DocumentPosition` or `undefined`. Since `initialLocation` is `TLocation` this cast should be valid.
174820
- var location = (initialLocation ? { fileName: path, pos: initialLocation.pos } : undefined);
174821
- toDo = callbackProjectAndLocation(project, location, projectService, toDo, seenProjects, cb);
174919
+ /**
174920
+ * @param projects Projects initially known to contain {@link initialLocation}
174921
+ * @param defaultProject The default project containing {@link initialLocation}
174922
+ * @param initialLocation Where the search operation was triggered
174923
+ * @param getResultsForPosition This is where you plug in `findReferences`, `renameLocation`, etc
174924
+ * @param forPositionInResult Given an item returned by {@link getResultsForPosition} enumerate the positions referred to by that result
174925
+ * @returns In the common case where there's only one project, returns an array of results from {@link getResultsForPosition}.
174926
+ * If multiple projects were searched - even if they didn't return results - the result will be a map from project to per-project results.
174927
+ */
174928
+ function getPerProjectReferences(projects, defaultProject, initialLocation, isForRename, getResultsForPosition, forPositionInResult) {
174929
+ // If `getResultsForPosition` returns results for a project, they go in here
174930
+ var resultsMap = new ts.Map();
174931
+ var queue = [];
174932
+ // In order to get accurate isDefinition values for `defaultProject`,
174933
+ // we need to ensure that it is searched from `initialLocation`.
174934
+ // The easiest way to do this is to search it first.
174935
+ queue.push({ project: defaultProject, location: initialLocation });
174936
+ // This will queue `defaultProject` a second time, but it will be dropped
174937
+ // as a dup when it is dequeued.
174938
+ forEachProjectInProjects(projects, initialLocation.fileName, function (project, path) {
174939
+ var location = { fileName: path, pos: initialLocation.pos };
174940
+ queue.push({ project: project, location: location });
174822
174941
  });
174823
- // After initial references are collected, go over every other project and see if it has a reference for the symbol definition.
174824
- if (initialLocation) {
174825
- var defaultDefinition_1 = getDefinitionLocation(defaultProject, initialLocation, isForRename);
174826
- if (defaultDefinition_1) {
174827
- var getGeneratedDefinition_1 = ts.memoize(function () { return defaultProject.isSourceOfProjectReferenceRedirect(defaultDefinition_1.fileName) ?
174828
- defaultDefinition_1 :
174829
- defaultProject.getLanguageService().getSourceMapper().tryGetGeneratedPosition(defaultDefinition_1); });
174830
- var getSourceDefinition_1 = ts.memoize(function () { return defaultProject.isSourceOfProjectReferenceRedirect(defaultDefinition_1.fileName) ?
174831
- defaultDefinition_1 :
174832
- defaultProject.getLanguageService().getSourceMapper().tryGetSourcePosition(defaultDefinition_1); });
174833
- projectService.loadAncestorProjectTree(seenProjects);
174942
+ var projectService = defaultProject.projectService;
174943
+ var cancellationToken = defaultProject.getCancellationToken();
174944
+ var defaultDefinition = getDefinitionLocation(defaultProject, initialLocation, isForRename);
174945
+ // Don't call these unless !!defaultDefinition
174946
+ var getGeneratedDefinition = ts.memoize(function () { return defaultProject.isSourceOfProjectReferenceRedirect(defaultDefinition.fileName) ?
174947
+ defaultDefinition :
174948
+ defaultProject.getLanguageService().getSourceMapper().tryGetGeneratedPosition(defaultDefinition); });
174949
+ var getSourceDefinition = ts.memoize(function () { return defaultProject.isSourceOfProjectReferenceRedirect(defaultDefinition.fileName) ?
174950
+ defaultDefinition :
174951
+ defaultProject.getLanguageService().getSourceMapper().tryGetSourcePosition(defaultDefinition); });
174952
+ // Track which projects we have already searched so that we don't repeat searches.
174953
+ // We store the project key, rather than the project, because that's what `loadAncestorProjectTree` wants.
174954
+ // (For that same reason, we don't use `resultsMap` for this check.)
174955
+ var searchedProjects = new ts.Set();
174956
+ onCancellation: while (queue.length) {
174957
+ while (queue.length) {
174958
+ if (cancellationToken.isCancellationRequested())
174959
+ break onCancellation;
174960
+ var _a = queue.shift(), project = _a.project, location = _a.location;
174961
+ if (isLocationProjectReferenceRedirect(project, location))
174962
+ continue;
174963
+ if (!ts.tryAddToSet(searchedProjects, getProjectKey(project)))
174964
+ continue;
174965
+ var projectResults = searchPosition(project, location);
174966
+ if (projectResults) {
174967
+ resultsMap.set(project, projectResults);
174968
+ }
174969
+ }
174970
+ // At this point, we know about all projects passed in as arguments and any projects in which
174971
+ // `getResultsForPosition` has returned results. We expand that set to include any projects
174972
+ // downstream from any of these and then queue new initial-position searches for any new project
174973
+ // containing `initialLocation`.
174974
+ if (defaultDefinition) {
174975
+ // This seems to mean "load all projects downstream from any member of `seenProjects`".
174976
+ projectService.loadAncestorProjectTree(searchedProjects);
174834
174977
  projectService.forEachEnabledProject(function (project) {
174835
- if (!addToSeen(seenProjects, project))
174836
- return;
174837
- var definition = mapDefinitionInProject(defaultDefinition_1, project, getGeneratedDefinition_1, getSourceDefinition_1);
174838
- if (definition) {
174839
- toDo = callbackProjectAndLocation(project, definition, projectService, toDo, seenProjects, cb);
174978
+ if (cancellationToken.isCancellationRequested())
174979
+ return; // There's no mechanism for skipping the remaining projects
174980
+ if (searchedProjects.has(getProjectKey(project)))
174981
+ return; // Can loop forever without this (enqueue here, dequeue above, repeat)
174982
+ var location = mapDefinitionInProject(defaultDefinition, project, getGeneratedDefinition, getSourceDefinition);
174983
+ if (location) {
174984
+ queue.push({ project: project, location: location });
174840
174985
  }
174841
174986
  });
174842
174987
  }
174843
174988
  }
174844
- while (toDo && toDo.length) {
174845
- var next = toDo.pop();
174846
- ts.Debug.assertIsDefined(next);
174847
- toDo = callbackProjectAndLocation(next.project, next.location, projectService, toDo, seenProjects, cb);
174989
+ // In the common case where there's only one project, return a simpler result to make
174990
+ // it easier for the caller to skip post-processing.
174991
+ if (searchedProjects.size === 1) {
174992
+ var it = resultsMap.values().next();
174993
+ ts.Debug.assert(!it.done);
174994
+ return it.value;
174995
+ }
174996
+ return resultsMap;
174997
+ // May enqueue to otherPositionQueue
174998
+ function searchPosition(project, location) {
174999
+ var projectResults = getResultsForPosition(project, location);
175000
+ if (!projectResults)
175001
+ return undefined;
175002
+ for (var _i = 0, projectResults_4 = projectResults; _i < projectResults_4.length; _i++) {
175003
+ var result = projectResults_4[_i];
175004
+ forPositionInResult(result, function (position) {
175005
+ // This may trigger a search for a tsconfig, but there are several layers of caching that make it inexpensive
175006
+ var originalLocation = projectService.getOriginalLocationEnsuringConfiguredProject(project, position);
175007
+ if (!originalLocation)
175008
+ return;
175009
+ var originalScriptInfo = projectService.getScriptInfo(originalLocation.fileName);
175010
+ for (var _i = 0, _a = originalScriptInfo.containingProjects; _i < _a.length; _i++) {
175011
+ var project_1 = _a[_i];
175012
+ if (!project_1.isOrphan()) {
175013
+ queue.push({ project: project_1, location: originalLocation });
175014
+ }
175015
+ }
175016
+ var symlinkedProjectsMap = projectService.getSymlinkedProjects(originalScriptInfo);
175017
+ if (symlinkedProjectsMap) {
175018
+ symlinkedProjectsMap.forEach(function (symlinkedProjects, symlinkedPath) {
175019
+ for (var _i = 0, symlinkedProjects_2 = symlinkedProjects; _i < symlinkedProjects_2.length; _i++) {
175020
+ var symlinkedProject = symlinkedProjects_2[_i];
175021
+ if (!symlinkedProject.isOrphan()) {
175022
+ queue.push({ project: symlinkedProject, location: { fileName: symlinkedPath, pos: originalLocation.pos } });
175023
+ }
175024
+ }
175025
+ });
175026
+ }
175027
+ });
175028
+ }
175029
+ return projectResults;
174848
175030
  }
174849
175031
  }
174850
175032
  function mapDefinitionInProject(definition, project, getGeneratedDefinition, getSourceDefinition) {
@@ -174875,43 +175057,6 @@ var ts;
174875
175057
  sourceFile.resolvedPath !== sourceFile.path &&
174876
175058
  sourceFile.resolvedPath !== project.toPath(location.fileName);
174877
175059
  }
174878
- function callbackProjectAndLocation(project, location, projectService, toDo, seenProjects, cb) {
174879
- if (project.getCancellationToken().isCancellationRequested())
174880
- return undefined; // Skip rest of toDo if cancelled
174881
- // If this is not the file we were actually looking, return rest of the toDo
174882
- if (isLocationProjectReferenceRedirect(project, location))
174883
- return toDo;
174884
- cb(project, location, function (innerProject, location) {
174885
- addToSeen(seenProjects, project);
174886
- var originalLocation = projectService.getOriginalLocationEnsuringConfiguredProject(innerProject, location);
174887
- if (!originalLocation)
174888
- return undefined;
174889
- var originalScriptInfo = projectService.getScriptInfo(originalLocation.fileName);
174890
- toDo = toDo || [];
174891
- for (var _i = 0, _a = originalScriptInfo.containingProjects; _i < _a.length; _i++) {
174892
- var project_1 = _a[_i];
174893
- addToTodo(project_1, originalLocation, toDo, seenProjects);
174894
- }
174895
- var symlinkedProjectsMap = projectService.getSymlinkedProjects(originalScriptInfo);
174896
- if (symlinkedProjectsMap) {
174897
- symlinkedProjectsMap.forEach(function (symlinkedProjects, symlinkedPath) {
174898
- for (var _i = 0, symlinkedProjects_2 = symlinkedProjects; _i < symlinkedProjects_2.length; _i++) {
174899
- var symlinkedProject = symlinkedProjects_2[_i];
174900
- addToTodo(symlinkedProject, { fileName: symlinkedPath, pos: originalLocation.pos }, toDo, seenProjects);
174901
- }
174902
- });
174903
- }
174904
- return originalLocation === location ? undefined : originalLocation;
174905
- });
174906
- return toDo;
174907
- }
174908
- function addToTodo(project, location, toDo, seenProjects) {
174909
- if (!project.isOrphan() && addToSeen(seenProjects, project))
174910
- toDo.push({ project: project, location: location });
174911
- }
174912
- function addToSeen(seenProjects, project) {
174913
- return ts.tryAddToSet(seenProjects, getProjectKey(project));
174914
- }
174915
175060
  function getProjectKey(project) {
174916
175061
  return server.isConfiguredProject(project) ? project.canonicalConfigFilePath : project.getProjectName();
174917
175062
  }
@@ -174919,32 +175064,14 @@ var ts;
174919
175064
  var fileName = _a.fileName, textSpan = _a.textSpan;
174920
175065
  return { fileName: fileName, pos: textSpan.start };
174921
175066
  }
174922
- function getMappedLocation(location, project) {
174923
- var mapsTo = project.getSourceMapper().tryGetSourcePosition(location);
174924
- return mapsTo && project.projectService.fileExists(server.toNormalizedPath(mapsTo.fileName)) ? mapsTo : undefined;
175067
+ function getMappedLocationForProject(location, project) {
175068
+ return ts.getMappedLocation(location, project.getSourceMapper(), function (p) { return project.projectService.fileExists(p); });
174925
175069
  }
174926
- function getMappedDocumentSpan(documentSpan, project) {
174927
- var newPosition = getMappedLocation(documentSpanLocation(documentSpan), project);
174928
- if (!newPosition)
174929
- return undefined;
174930
- return {
174931
- fileName: newPosition.fileName,
174932
- textSpan: {
174933
- start: newPosition.pos,
174934
- length: documentSpan.textSpan.length
174935
- },
174936
- originalFileName: documentSpan.fileName,
174937
- originalTextSpan: documentSpan.textSpan,
174938
- contextSpan: getMappedContextSpan(documentSpan, project),
174939
- originalContextSpan: documentSpan.contextSpan
174940
- };
175070
+ function getMappedDocumentSpanForProject(documentSpan, project) {
175071
+ return ts.getMappedDocumentSpan(documentSpan, project.getSourceMapper(), function (p) { return project.projectService.fileExists(p); });
174941
175072
  }
174942
- function getMappedContextSpan(documentSpan, project) {
174943
- var contextSpanStart = documentSpan.contextSpan && getMappedLocation({ fileName: documentSpan.fileName, pos: documentSpan.contextSpan.start }, project);
174944
- var contextSpanEnd = documentSpan.contextSpan && getMappedLocation({ fileName: documentSpan.fileName, pos: documentSpan.contextSpan.start + documentSpan.contextSpan.length }, project);
174945
- return contextSpanStart && contextSpanEnd ?
174946
- { start: contextSpanStart.pos, length: contextSpanEnd.pos - contextSpanStart.pos } :
174947
- undefined;
175073
+ function getMappedContextSpanForProject(documentSpan, project) {
175074
+ return ts.getMappedContextSpan(documentSpan, project.getSourceMapper(), function (p) { return project.projectService.fileExists(p); });
174948
175075
  }
174949
175076
  var invalidPartialSemanticModeCommands = [
174950
175077
  server.CommandNames.OpenExternalProject,
@@ -175837,7 +175964,7 @@ var ts;
175837
175964
  };
175838
175965
  Session.prototype.mapDefinitionInfoLocations = function (definitions, project) {
175839
175966
  return definitions.map(function (info) {
175840
- var newDocumentSpan = getMappedDocumentSpan(info, project);
175967
+ var newDocumentSpan = getMappedDocumentSpanForProject(info, project);
175841
175968
  return !newDocumentSpan ? info : __assign(__assign(__assign({}, newDocumentSpan), { containerKind: info.containerKind, containerName: info.containerName, kind: info.kind, name: info.name, failedAliasResolution: info.failedAliasResolution }), info.unverified && { unverified: info.unverified });
175842
175969
  });
175843
175970
  };
@@ -176082,7 +176209,7 @@ var ts;
176082
176209
  };
176083
176210
  Session.prototype.mapImplementationLocations = function (implementations, project) {
176084
176211
  return implementations.map(function (info) {
176085
- var newDocumentSpan = getMappedDocumentSpan(info, project);
176212
+ var newDocumentSpan = getMappedDocumentSpanForProject(info, project);
176086
176213
  return !newDocumentSpan ? info : __assign(__assign({}, newDocumentSpan), { kind: info.kind, displayParts: info.displayParts });
176087
176214
  });
176088
176215
  };
@@ -176239,7 +176366,7 @@ var ts;
176239
176366
  var renameInfo = this.mapRenameInfo(defaultProject.getLanguageService().getRenameInfo(file, position, { allowRenameOfImportPath: this.getPreferences(file).allowRenameOfImportPath }), ts.Debug.checkDefined(this.projectService.getScriptInfo(file)));
176240
176367
  if (!renameInfo.canRename)
176241
176368
  return simplifiedResult ? { info: renameInfo, locs: [] } : [];
176242
- var locations = combineProjectOutputForRenameLocations(projects, defaultProject, { fileName: args.file, pos: position }, !!args.findInStrings, !!args.findInComments, this.getPreferences(file));
176369
+ var locations = getRenameLocationsWorker(projects, defaultProject, { fileName: args.file, pos: position }, !!args.findInStrings, !!args.findInComments, this.getPreferences(file));
176243
176370
  if (!simplifiedResult)
176244
176371
  return locations;
176245
176372
  return { info: renameInfo, locs: this.toSpanGroups(locations) };
@@ -176271,7 +176398,7 @@ var ts;
176271
176398
  var file = server.toNormalizedPath(args.file);
176272
176399
  var projects = this.getProjects(args);
176273
176400
  var position = this.getPositionInFile(args, file);
176274
- var references = combineProjectOutputForReferences(projects, this.getDefaultProject(args), { fileName: args.file, pos: position }, this.logger);
176401
+ var references = getReferencesWorker(projects, this.getDefaultProject(args), { fileName: args.file, pos: position }, this.logger);
176275
176402
  if (!simplifiedResult)
176276
176403
  return references;
176277
176404
  var defaultProject = this.getDefaultProject(args);
@@ -176297,8 +176424,8 @@ var ts;
176297
176424
  return;
176298
176425
  var projectOutputs = project.getLanguageService().getFileReferences(fileName);
176299
176426
  if (projectOutputs) {
176300
- for (var _i = 0, projectOutputs_3 = projectOutputs; _i < projectOutputs_3.length; _i++) {
176301
- var referenceEntry = projectOutputs_3[_i];
176427
+ for (var _i = 0, projectOutputs_1 = projectOutputs; _i < projectOutputs_1.length; _i++) {
176428
+ var referenceEntry = projectOutputs_1[_i];
176302
176429
  if (!seen.has(referenceEntry)) {
176303
176430
  references.push(referenceEntry);
176304
176431
  seen.add(referenceEntry);
@@ -176763,7 +176890,8 @@ var ts;
176763
176890
  // `name` is a very cheap hash function, but we could incorporate other properties to reduce collisions.
176764
176891
  var seenItems = new ts.Map(); // name to items with that name
176765
176892
  if (!args.file && !projectFileName) {
176766
- // VS Code's `Go to symbol in workspaces` sends request like this
176893
+ // VS Code's `Go to symbol in workspaces` sends request like this by default.
176894
+ // There's a setting to have it send a file name (reverting to older behavior).
176767
176895
  // TODO (https://github.com/microsoft/TypeScript/issues/47839)
176768
176896
  // This appears to have been intended to search all projects but, in practice, it seems to only search
176769
176897
  // those that are downstream from already-loaded projects.
@@ -176784,7 +176912,7 @@ var ts;
176784
176912
  // Mutates `outputs`
176785
176913
  function addItemsForProject(project) {
176786
176914
  var projectItems = project.getLanguageService().getNavigateToItems(searchValue, maxResultCount, /*filename*/ undefined, /*excludeDts*/ project.isNonTsProject());
176787
- var unseenItems = ts.filter(projectItems, function (item) { return tryAddSeenItem(item) && !getMappedLocation(documentSpanLocation(item), project); });
176915
+ var unseenItems = ts.filter(projectItems, function (item) { return tryAddSeenItem(item) && !getMappedLocationForProject(documentSpanLocation(item), project); });
176788
176916
  if (unseenItems.length) {
176789
176917
  outputs.push({ project: project, navigateToItems: unseenItems });
176790
176918
  }