typescript 4.8.0-dev.20220518 → 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.20220518";
103
+ ts.version = ts.versionMajorMinor + ".0-dev.20220519";
104
104
  /* @internal */
105
105
  var Comparison;
106
106
  (function (Comparison) {
@@ -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;'
@@ -164137,70 +164175,6 @@ var ts;
164137
164175
  return ts.codefix.getSupportedErrorCodes();
164138
164176
  }
164139
164177
  ts.getSupportedCodeFixes = getSupportedCodeFixes;
164140
- // Cache host information about script Should be refreshed
164141
- // at each language service public entry point, since we don't know when
164142
- // the set of scripts handled by the host changes.
164143
- var HostCache = /** @class */ (function () {
164144
- function HostCache(host, getCanonicalFileName) {
164145
- this.host = host;
164146
- // script id => script index
164147
- this.currentDirectory = host.getCurrentDirectory();
164148
- this.fileNameToEntry = new ts.Map();
164149
- // Initialize the list with the root file names
164150
- var rootFileNames = host.getScriptFileNames();
164151
- ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("session" /* Session */, "initializeHostCache", { count: rootFileNames.length });
164152
- for (var _i = 0, rootFileNames_1 = rootFileNames; _i < rootFileNames_1.length; _i++) {
164153
- var fileName = rootFileNames_1[_i];
164154
- this.createEntry(fileName, ts.toPath(fileName, this.currentDirectory, getCanonicalFileName));
164155
- }
164156
- ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
164157
- }
164158
- HostCache.prototype.createEntry = function (fileName, path) {
164159
- var entry;
164160
- var scriptSnapshot = this.host.getScriptSnapshot(fileName);
164161
- if (scriptSnapshot) {
164162
- entry = {
164163
- hostFileName: fileName,
164164
- version: this.host.getScriptVersion(fileName),
164165
- scriptSnapshot: scriptSnapshot,
164166
- scriptKind: ts.getScriptKind(fileName, this.host)
164167
- };
164168
- }
164169
- else {
164170
- entry = fileName;
164171
- }
164172
- this.fileNameToEntry.set(path, entry);
164173
- return entry;
164174
- };
164175
- HostCache.prototype.getEntryByPath = function (path) {
164176
- return this.fileNameToEntry.get(path);
164177
- };
164178
- HostCache.prototype.getHostFileInformation = function (path) {
164179
- var entry = this.fileNameToEntry.get(path);
164180
- return !ts.isString(entry) ? entry : undefined;
164181
- };
164182
- HostCache.prototype.getOrCreateEntryByPath = function (fileName, path) {
164183
- var info = this.getEntryByPath(path) || this.createEntry(fileName, path);
164184
- return ts.isString(info) ? undefined : info; // TODO: GH#18217
164185
- };
164186
- HostCache.prototype.getRootFileNames = function () {
164187
- var names = [];
164188
- this.fileNameToEntry.forEach(function (entry) {
164189
- if (ts.isString(entry)) {
164190
- names.push(entry);
164191
- }
164192
- else {
164193
- names.push(entry.hostFileName);
164194
- }
164195
- });
164196
- return names;
164197
- };
164198
- HostCache.prototype.getScriptSnapshot = function (path) {
164199
- var file = this.getHostFileInformation(path);
164200
- return (file && file.scriptSnapshot); // TODO: GH#18217
164201
- };
164202
- return HostCache;
164203
- }());
164204
164178
  var SyntaxTreeCache = /** @class */ (function () {
164205
164179
  function SyntaxTreeCache(host) {
164206
164180
  this.host = host;
@@ -164462,32 +164436,13 @@ var ts;
164462
164436
  program = undefined; // TODO: GH#18217
164463
164437
  lastTypesRootVersion = typeRootsVersion;
164464
164438
  }
164439
+ var rootFileNames = host.getScriptFileNames();
164465
164440
  // Get a fresh cache of the host information
164466
- var hostCache = new HostCache(host, getCanonicalFileName);
164467
- var rootFileNames = hostCache.getRootFileNames();
164468
164441
  var newSettings = host.getCompilationSettings() || getDefaultCompilerOptions();
164469
164442
  var hasInvalidatedResolution = host.hasInvalidatedResolution || ts.returnFalse;
164470
164443
  var hasChangedAutomaticTypeDirectiveNames = ts.maybeBind(host, host.hasChangedAutomaticTypeDirectiveNames);
164471
164444
  var projectReferences = (_b = host.getProjectReferences) === null || _b === void 0 ? void 0 : _b.call(host);
164472
164445
  var parsedCommandLines;
164473
- var parseConfigHost = {
164474
- useCaseSensitiveFileNames: useCaseSensitiveFileNames,
164475
- fileExists: fileExists,
164476
- readFile: readFile,
164477
- readDirectory: readDirectory,
164478
- trace: ts.maybeBind(host, host.trace),
164479
- getCurrentDirectory: function () { return currentDirectory; },
164480
- onUnRecoverableConfigFileDiagnostic: ts.noop,
164481
- };
164482
- // If the program is already up-to-date, we can reuse it
164483
- if (ts.isProgramUptoDate(program, rootFileNames, newSettings, function (_path, fileName) { return host.getScriptVersion(fileName); }, fileExists, hasInvalidatedResolution, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) {
164484
- return;
164485
- }
164486
- // IMPORTANT - It is critical from this moment onward that we do not check
164487
- // cancellation tokens. We are about to mutate source files from a previous program
164488
- // instance. If we cancel midway through, we may end up in an inconsistent state where
164489
- // the program points to old source files that have been invalidated because of
164490
- // incremental parsing.
164491
164446
  // Now create a new compiler
164492
164447
  var compilerHost = {
164493
164448
  getSourceFile: getOrCreateSourceFile,
@@ -164499,8 +164454,8 @@ var ts;
164499
164454
  getDefaultLibFileName: function (options) { return host.getDefaultLibFileName(options); },
164500
164455
  writeFile: ts.noop,
164501
164456
  getCurrentDirectory: function () { return currentDirectory; },
164502
- fileExists: fileExists,
164503
- readFile: readFile,
164457
+ fileExists: function (fileName) { return host.fileExists(fileName); },
164458
+ readFile: function (fileName) { return host.readFile && host.readFile(fileName); },
164504
164459
  getSymlinkCache: ts.maybeBind(host, host.getSymlinkCache),
164505
164460
  realpath: ts.maybeBind(host, host.realpath),
164506
164461
  directoryExists: function (directoryName) {
@@ -164509,19 +164464,56 @@ var ts;
164509
164464
  getDirectories: function (path) {
164510
164465
  return host.getDirectories ? host.getDirectories(path) : [];
164511
164466
  },
164512
- 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
+ },
164513
164471
  onReleaseOldSourceFile: onReleaseOldSourceFile,
164514
164472
  onReleaseParsedCommandLine: onReleaseParsedCommandLine,
164515
164473
  hasInvalidatedResolution: hasInvalidatedResolution,
164516
164474
  hasChangedAutomaticTypeDirectiveNames: hasChangedAutomaticTypeDirectiveNames,
164517
- trace: parseConfigHost.trace,
164475
+ trace: ts.maybeBind(host, host.trace),
164518
164476
  resolveModuleNames: ts.maybeBind(host, host.resolveModuleNames),
164519
164477
  getModuleResolutionCache: ts.maybeBind(host, host.getModuleResolutionCache),
164520
164478
  resolveTypeReferenceDirectives: ts.maybeBind(host, host.resolveTypeReferenceDirectives),
164521
164479
  useSourceOfProjectReferenceRedirect: ts.maybeBind(host, host.useSourceOfProjectReferenceRedirect),
164522
164480
  getParsedCommandLine: getParsedCommandLine,
164523
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;
164524
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.
164525
164517
  var documentRegistryBucketKey = documentRegistry.getKeyForCompilationSettings(newSettings);
164526
164518
  var options = {
164527
164519
  rootNames: rootFileNames,
@@ -164531,9 +164523,9 @@ var ts;
164531
164523
  projectReferences: projectReferences
164532
164524
  };
164533
164525
  program = ts.createProgram(options);
164534
- // hostCache is captured in the closure for 'getOrCreateSourceFile' but it should not be used past this point.
164535
- // It needs to be cleared to allow all collected snapshots to be released
164536
- 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;
164537
164529
  parsedCommandLines = undefined;
164538
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,
164539
164531
  // Because it only functions until `hostCache` is cleared, while we'll potentially need the functionality to lazily read sourcemap files during
@@ -164573,26 +164565,6 @@ var ts;
164573
164565
  onReleaseOldSourceFile(oldResolvedRef.sourceFile, oldOptions);
164574
164566
  }
164575
164567
  }
164576
- function fileExists(fileName) {
164577
- var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
164578
- var entry = hostCache && hostCache.getEntryByPath(path);
164579
- return entry ?
164580
- !ts.isString(entry) :
164581
- (!!host.fileExists && host.fileExists(fileName));
164582
- }
164583
- function readFile(fileName) {
164584
- // stub missing host functionality
164585
- var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
164586
- var entry = hostCache && hostCache.getEntryByPath(path);
164587
- if (entry) {
164588
- return ts.isString(entry) ? undefined : ts.getSnapshotText(entry.scriptSnapshot);
164589
- }
164590
- return host.readFile && host.readFile(fileName);
164591
- }
164592
- function readDirectory(path, extensions, exclude, include, depth) {
164593
- ts.Debug.checkDefined(host.readDirectory, "'LanguageServiceHost.readDirectory' must be implemented to correctly process 'projectReferences'");
164594
- return host.readDirectory(path, extensions, exclude, include, depth);
164595
- }
164596
164568
  // Release any files we have acquired in the old program but are
164597
164569
  // not part of the new program.
164598
164570
  function onReleaseOldSourceFile(oldSourceFile, oldOptions) {
@@ -164603,14 +164575,16 @@ var ts;
164603
164575
  return getOrCreateSourceFileByPath(fileName, ts.toPath(fileName, currentDirectory, getCanonicalFileName), languageVersion, onError, shouldCreateNewSourceFile);
164604
164576
  }
164605
164577
  function getOrCreateSourceFileByPath(fileName, path, _languageVersion, _onError, shouldCreateNewSourceFile) {
164606
- 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.");
164607
164579
  // The program is asking for this file, check first if the host can locate it.
164608
164580
  // If the host can not locate the file, then it does not exist. return undefined
164609
164581
  // to the program to allow reporting of errors for missing files.
164610
- var hostFileInformation = hostCache && hostCache.getOrCreateEntryByPath(fileName, path);
164611
- if (!hostFileInformation) {
164582
+ var scriptSnapshot = host.getScriptSnapshot(fileName);
164583
+ if (!scriptSnapshot) {
164612
164584
  return undefined;
164613
164585
  }
164586
+ var scriptKind = ts.getScriptKind(fileName, host);
164587
+ var scriptVersion = host.getScriptVersion(fileName);
164614
164588
  // Check if the language version has changed since we last created a program; if they are the same,
164615
164589
  // it is safe to reuse the sourceFiles; if not, then the shape of the AST can change, and the oldSourceFile
164616
164590
  // can not be reused. we have to dump all syntax trees and create new ones.
@@ -164642,8 +164616,8 @@ var ts;
164642
164616
  // We do not support the scenario where a host can modify a registered
164643
164617
  // file's script kind, i.e. in one project some file is treated as ".ts"
164644
164618
  // and in another as ".js"
164645
- if (hostFileInformation.scriptKind === oldSourceFile.scriptKind) {
164646
- 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);
164647
164621
  }
164648
164622
  else {
164649
164623
  // Release old source file and fall through to aquire new file with new script kind
@@ -164653,7 +164627,7 @@ var ts;
164653
164627
  // We didn't already have the file. Fall through and acquire it from the registry.
164654
164628
  }
164655
164629
  // Could not find this file in the old program, create a new SourceFile for it.
164656
- return documentRegistry.acquireDocumentWithKey(fileName, path, host, documentRegistryBucketKey, hostFileInformation.scriptSnapshot, hostFileInformation.version, hostFileInformation.scriptKind);
164630
+ return documentRegistry.acquireDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind);
164657
164631
  }
164658
164632
  }
164659
164633
  // TODO: GH#18217 frequently asserted as defined
@@ -164669,6 +164643,61 @@ var ts;
164669
164643
  var _a;
164670
164644
  return (_a = host.getPackageJsonAutoImportProvider) === null || _a === void 0 ? void 0 : _a.call(host);
164671
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
+ }
164672
164701
  function cleanupSemanticCache() {
164673
164702
  program = undefined; // TODO: GH#18217
164674
164703
  }
@@ -165595,6 +165624,7 @@ var ts;
165595
165624
  getNonBoundSourceFile: getNonBoundSourceFile,
165596
165625
  getProgram: getProgram,
165597
165626
  getAutoImportProvider: getAutoImportProvider,
165627
+ updateIsDefinitionOfReferencedSymbols: updateIsDefinitionOfReferencedSymbols,
165598
165628
  getApplicableRefactors: getApplicableRefactors,
165599
165629
  getEditsForRefactor: getEditsForRefactor,
165600
165630
  toLineColumnOffset: toLineColumnOffset,
@@ -174735,66 +174765,142 @@ var ts;
174735
174765
  return textSpan.start + 100003 * textSpan.length;
174736
174766
  }, ts.documentSpansEqual);
174737
174767
  }
174738
- function combineProjectOutputForRenameLocations(projects, defaultProject, initialLocation, findInStrings, findInComments, _a) {
174768
+ function getRenameLocationsWorker(projects, defaultProject, initialLocation, findInStrings, findInComments, _a) {
174739
174769
  var providePrefixAndSuffixTextForRename = _a.providePrefixAndSuffixTextForRename;
174740
- 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 = [];
174741
174777
  var seen = createDocumentSpanSet();
174742
- combineProjectOutputWorker(projects, defaultProject, initialLocation,
174743
- /*isForRename*/ true, function (project, location, tryAddToTodo) {
174744
- var projectOutputs = project.getLanguageService().findRenameLocations(location.fileName, location.pos, findInStrings, findInComments, providePrefixAndSuffixTextForRename);
174745
- if (projectOutputs) {
174746
- for (var _i = 0, projectOutputs_1 = projectOutputs; _i < projectOutputs_1.length; _i++) {
174747
- var output = projectOutputs_1[_i];
174748
- if (!seen.has(output) && !tryAddToTodo(project, documentSpanLocation(output))) {
174749
- seen.add(output);
174750
- outputs.push(output);
174751
- }
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);
174752
174785
  }
174753
174786
  }
174754
174787
  });
174755
- return outputs;
174788
+ return results;
174756
174789
  }
174757
174790
  function getDefinitionLocation(defaultProject, initialLocation, isForRename) {
174758
- 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);
174759
174792
  var info = infos && ts.firstOrUndefined(infos);
174760
174793
  return info && !info.isLocal ? { fileName: info.fileName, pos: info.textSpan.start } : undefined;
174761
174794
  }
174762
- function combineProjectOutputForReferences(projects, defaultProject, initialLocation, logger) {
174763
- var outputs = [];
174764
- combineProjectOutputWorker(projects, defaultProject, initialLocation,
174765
- /*isForRename*/ false, function (project, location, getMappedLocation) {
174766
- var _a, _b;
174767
- logger.info("Finding references to " + location.fileName + " position " + location.pos + " in project " + project.getProjectName());
174768
- var projectOutputs = project.getLanguageService().findReferences(location.fileName, location.pos);
174769
- if (projectOutputs) {
174770
- var clearIsDefinition = ((_b = (_a = projectOutputs[0]) === null || _a === void 0 ? void 0 : _a.references[0]) === null || _b === void 0 ? void 0 : _b.isDefinition) === undefined;
174771
- var _loop_9 = function (referencedSymbol) {
174772
- var mappedDefinitionFile = getMappedLocation(project, documentSpanLocation(referencedSymbol.definition));
174773
- var definition = mappedDefinitionFile === undefined ?
174774
- referencedSymbol.definition : __assign(__assign({}, referencedSymbol.definition), { textSpan: ts.createTextSpan(mappedDefinitionFile.pos, referencedSymbol.definition.textSpan.length), fileName: mappedDefinitionFile.fileName, contextSpan: getMappedContextSpan(referencedSymbol.definition, project) });
174775
- var symbolToAddTo = ts.find(outputs, function (o) { return ts.documentSpansEqual(o.definition, definition); });
174776
- if (!symbolToAddTo) {
174777
- symbolToAddTo = { definition: definition, references: [] };
174778
- outputs.push(symbolToAddTo);
174779
- }
174780
- for (var _c = 0, _d = referencedSymbol.references; _c < _d.length; _c++) {
174781
- var ref = _d[_c];
174782
- // If it's in a mapped file, that is added to the todo list by `getMappedLocation`.
174783
- if (!ts.contains(symbolToAddTo.references, ref, ts.documentSpansEqual) && !getMappedLocation(project, documentSpanLocation(ref))) {
174784
- if (clearIsDefinition) {
174785
- delete ref.isDefinition;
174786
- }
174787
- symbolToAddTo.references.push(ref);
174788
- }
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;
174789
174869
  }
174790
- };
174791
- for (var _i = 0, projectOutputs_2 = projectOutputs; _i < projectOutputs_2.length; _i++) {
174792
- var referencedSymbol = projectOutputs_2[_i];
174793
- _loop_9(referencedSymbol);
174794
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);
174795
174901
  }
174796
174902
  });
174797
- return outputs.filter(function (o) { return o.references.length !== 0; });
174903
+ return results.filter(function (o) { return o.references.length !== 0; });
174798
174904
  }
174799
174905
  function forEachProjectInProjects(projects, path, cb) {
174800
174906
  for (var _i = 0, _a = ts.isArray(projects) ? projects : projects.projects; _i < _a.length; _i++) {
@@ -174810,40 +174916,117 @@ var ts;
174810
174916
  });
174811
174917
  }
174812
174918
  }
174813
- function combineProjectOutputWorker(projects, defaultProject, initialLocation, isForRename, cb) {
174814
- var projectService = defaultProject.projectService;
174815
- var toDo;
174816
- var seenProjects = new ts.Set();
174817
- forEachProjectInProjects(projects, initialLocation && initialLocation.fileName, function (project, path) {
174818
- // TLocation should be either `DocumentPosition` or `undefined`. Since `initialLocation` is `TLocation` this cast should be valid.
174819
- var location = (initialLocation ? { fileName: path, pos: initialLocation.pos } : undefined);
174820
- 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 });
174821
174941
  });
174822
- // After initial references are collected, go over every other project and see if it has a reference for the symbol definition.
174823
- if (initialLocation) {
174824
- var defaultDefinition_1 = getDefinitionLocation(defaultProject, initialLocation, isForRename);
174825
- if (defaultDefinition_1) {
174826
- var getGeneratedDefinition_1 = ts.memoize(function () { return defaultProject.isSourceOfProjectReferenceRedirect(defaultDefinition_1.fileName) ?
174827
- defaultDefinition_1 :
174828
- defaultProject.getLanguageService().getSourceMapper().tryGetGeneratedPosition(defaultDefinition_1); });
174829
- var getSourceDefinition_1 = ts.memoize(function () { return defaultProject.isSourceOfProjectReferenceRedirect(defaultDefinition_1.fileName) ?
174830
- defaultDefinition_1 :
174831
- defaultProject.getLanguageService().getSourceMapper().tryGetSourcePosition(defaultDefinition_1); });
174832
- 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);
174833
174977
  projectService.forEachEnabledProject(function (project) {
174834
- if (!addToSeen(seenProjects, project))
174835
- return;
174836
- var definition = mapDefinitionInProject(defaultDefinition_1, project, getGeneratedDefinition_1, getSourceDefinition_1);
174837
- if (definition) {
174838
- 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 });
174839
174985
  }
174840
174986
  });
174841
174987
  }
174842
174988
  }
174843
- while (toDo && toDo.length) {
174844
- var next = toDo.pop();
174845
- ts.Debug.assertIsDefined(next);
174846
- 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;
174847
175030
  }
174848
175031
  }
174849
175032
  function mapDefinitionInProject(definition, project, getGeneratedDefinition, getSourceDefinition) {
@@ -174874,43 +175057,6 @@ var ts;
174874
175057
  sourceFile.resolvedPath !== sourceFile.path &&
174875
175058
  sourceFile.resolvedPath !== project.toPath(location.fileName);
174876
175059
  }
174877
- function callbackProjectAndLocation(project, location, projectService, toDo, seenProjects, cb) {
174878
- if (project.getCancellationToken().isCancellationRequested())
174879
- return undefined; // Skip rest of toDo if cancelled
174880
- // If this is not the file we were actually looking, return rest of the toDo
174881
- if (isLocationProjectReferenceRedirect(project, location))
174882
- return toDo;
174883
- cb(project, location, function (innerProject, location) {
174884
- addToSeen(seenProjects, project);
174885
- var originalLocation = projectService.getOriginalLocationEnsuringConfiguredProject(innerProject, location);
174886
- if (!originalLocation)
174887
- return undefined;
174888
- var originalScriptInfo = projectService.getScriptInfo(originalLocation.fileName);
174889
- toDo = toDo || [];
174890
- for (var _i = 0, _a = originalScriptInfo.containingProjects; _i < _a.length; _i++) {
174891
- var project_1 = _a[_i];
174892
- addToTodo(project_1, originalLocation, toDo, seenProjects);
174893
- }
174894
- var symlinkedProjectsMap = projectService.getSymlinkedProjects(originalScriptInfo);
174895
- if (symlinkedProjectsMap) {
174896
- symlinkedProjectsMap.forEach(function (symlinkedProjects, symlinkedPath) {
174897
- for (var _i = 0, symlinkedProjects_2 = symlinkedProjects; _i < symlinkedProjects_2.length; _i++) {
174898
- var symlinkedProject = symlinkedProjects_2[_i];
174899
- addToTodo(symlinkedProject, { fileName: symlinkedPath, pos: originalLocation.pos }, toDo, seenProjects);
174900
- }
174901
- });
174902
- }
174903
- return originalLocation === location ? undefined : originalLocation;
174904
- });
174905
- return toDo;
174906
- }
174907
- function addToTodo(project, location, toDo, seenProjects) {
174908
- if (!project.isOrphan() && addToSeen(seenProjects, project))
174909
- toDo.push({ project: project, location: location });
174910
- }
174911
- function addToSeen(seenProjects, project) {
174912
- return ts.tryAddToSet(seenProjects, getProjectKey(project));
174913
- }
174914
175060
  function getProjectKey(project) {
174915
175061
  return server.isConfiguredProject(project) ? project.canonicalConfigFilePath : project.getProjectName();
174916
175062
  }
@@ -174918,32 +175064,14 @@ var ts;
174918
175064
  var fileName = _a.fileName, textSpan = _a.textSpan;
174919
175065
  return { fileName: fileName, pos: textSpan.start };
174920
175066
  }
174921
- function getMappedLocation(location, project) {
174922
- var mapsTo = project.getSourceMapper().tryGetSourcePosition(location);
174923
- 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); });
174924
175069
  }
174925
- function getMappedDocumentSpan(documentSpan, project) {
174926
- var newPosition = getMappedLocation(documentSpanLocation(documentSpan), project);
174927
- if (!newPosition)
174928
- return undefined;
174929
- return {
174930
- fileName: newPosition.fileName,
174931
- textSpan: {
174932
- start: newPosition.pos,
174933
- length: documentSpan.textSpan.length
174934
- },
174935
- originalFileName: documentSpan.fileName,
174936
- originalTextSpan: documentSpan.textSpan,
174937
- contextSpan: getMappedContextSpan(documentSpan, project),
174938
- originalContextSpan: documentSpan.contextSpan
174939
- };
175070
+ function getMappedDocumentSpanForProject(documentSpan, project) {
175071
+ return ts.getMappedDocumentSpan(documentSpan, project.getSourceMapper(), function (p) { return project.projectService.fileExists(p); });
174940
175072
  }
174941
- function getMappedContextSpan(documentSpan, project) {
174942
- var contextSpanStart = documentSpan.contextSpan && getMappedLocation({ fileName: documentSpan.fileName, pos: documentSpan.contextSpan.start }, project);
174943
- var contextSpanEnd = documentSpan.contextSpan && getMappedLocation({ fileName: documentSpan.fileName, pos: documentSpan.contextSpan.start + documentSpan.contextSpan.length }, project);
174944
- return contextSpanStart && contextSpanEnd ?
174945
- { start: contextSpanStart.pos, length: contextSpanEnd.pos - contextSpanStart.pos } :
174946
- undefined;
175073
+ function getMappedContextSpanForProject(documentSpan, project) {
175074
+ return ts.getMappedContextSpan(documentSpan, project.getSourceMapper(), function (p) { return project.projectService.fileExists(p); });
174947
175075
  }
174948
175076
  var invalidPartialSemanticModeCommands = [
174949
175077
  server.CommandNames.OpenExternalProject,
@@ -175836,7 +175964,7 @@ var ts;
175836
175964
  };
175837
175965
  Session.prototype.mapDefinitionInfoLocations = function (definitions, project) {
175838
175966
  return definitions.map(function (info) {
175839
- var newDocumentSpan = getMappedDocumentSpan(info, project);
175967
+ var newDocumentSpan = getMappedDocumentSpanForProject(info, project);
175840
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 });
175841
175969
  });
175842
175970
  };
@@ -176081,7 +176209,7 @@ var ts;
176081
176209
  };
176082
176210
  Session.prototype.mapImplementationLocations = function (implementations, project) {
176083
176211
  return implementations.map(function (info) {
176084
- var newDocumentSpan = getMappedDocumentSpan(info, project);
176212
+ var newDocumentSpan = getMappedDocumentSpanForProject(info, project);
176085
176213
  return !newDocumentSpan ? info : __assign(__assign({}, newDocumentSpan), { kind: info.kind, displayParts: info.displayParts });
176086
176214
  });
176087
176215
  };
@@ -176238,7 +176366,7 @@ var ts;
176238
176366
  var renameInfo = this.mapRenameInfo(defaultProject.getLanguageService().getRenameInfo(file, position, { allowRenameOfImportPath: this.getPreferences(file).allowRenameOfImportPath }), ts.Debug.checkDefined(this.projectService.getScriptInfo(file)));
176239
176367
  if (!renameInfo.canRename)
176240
176368
  return simplifiedResult ? { info: renameInfo, locs: [] } : [];
176241
- 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));
176242
176370
  if (!simplifiedResult)
176243
176371
  return locations;
176244
176372
  return { info: renameInfo, locs: this.toSpanGroups(locations) };
@@ -176270,7 +176398,7 @@ var ts;
176270
176398
  var file = server.toNormalizedPath(args.file);
176271
176399
  var projects = this.getProjects(args);
176272
176400
  var position = this.getPositionInFile(args, file);
176273
- 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);
176274
176402
  if (!simplifiedResult)
176275
176403
  return references;
176276
176404
  var defaultProject = this.getDefaultProject(args);
@@ -176296,8 +176424,8 @@ var ts;
176296
176424
  return;
176297
176425
  var projectOutputs = project.getLanguageService().getFileReferences(fileName);
176298
176426
  if (projectOutputs) {
176299
- for (var _i = 0, projectOutputs_3 = projectOutputs; _i < projectOutputs_3.length; _i++) {
176300
- var referenceEntry = projectOutputs_3[_i];
176427
+ for (var _i = 0, projectOutputs_1 = projectOutputs; _i < projectOutputs_1.length; _i++) {
176428
+ var referenceEntry = projectOutputs_1[_i];
176301
176429
  if (!seen.has(referenceEntry)) {
176302
176430
  references.push(referenceEntry);
176303
176431
  seen.add(referenceEntry);
@@ -176762,7 +176890,8 @@ var ts;
176762
176890
  // `name` is a very cheap hash function, but we could incorporate other properties to reduce collisions.
176763
176891
  var seenItems = new ts.Map(); // name to items with that name
176764
176892
  if (!args.file && !projectFileName) {
176765
- // 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).
176766
176895
  // TODO (https://github.com/microsoft/TypeScript/issues/47839)
176767
176896
  // This appears to have been intended to search all projects but, in practice, it seems to only search
176768
176897
  // those that are downstream from already-loaded projects.
@@ -176783,7 +176912,7 @@ var ts;
176783
176912
  // Mutates `outputs`
176784
176913
  function addItemsForProject(project) {
176785
176914
  var projectItems = project.getLanguageService().getNavigateToItems(searchValue, maxResultCount, /*filename*/ undefined, /*excludeDts*/ project.isNonTsProject());
176786
- 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); });
176787
176916
  if (unseenItems.length) {
176788
176917
  outputs.push({ project: project, navigateToItems: unseenItems });
176789
176918
  }