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.
@@ -294,7 +294,7 @@ var ts;
294
294
  // The following is baselined as a literal template type without intervention
295
295
  /** The version of the TypeScript compiler release */
296
296
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
297
- ts.version = ts.versionMajorMinor + ".0-dev.20220516";
297
+ ts.version = ts.versionMajorMinor + ".0-dev.20220519";
298
298
  /* @internal */
299
299
  var Comparison;
300
300
  (function (Comparison) {
@@ -59127,9 +59127,9 @@ var ts;
59127
59127
  t.flags & 2097152 /* Intersection */ ? getApparentTypeOfIntersectionType(t) :
59128
59128
  t.flags & 402653316 /* StringLike */ ? globalStringType :
59129
59129
  t.flags & 296 /* NumberLike */ ? globalNumberType :
59130
- t.flags & 2112 /* BigIntLike */ ? getGlobalBigIntType(/*reportErrors*/ languageVersion >= 7 /* ES2020 */) :
59130
+ t.flags & 2112 /* BigIntLike */ ? getGlobalBigIntType() :
59131
59131
  t.flags & 528 /* BooleanLike */ ? globalBooleanType :
59132
- t.flags & 12288 /* ESSymbolLike */ ? getGlobalESSymbolType(/*reportErrors*/ languageVersion >= 2 /* ES2015 */) :
59132
+ t.flags & 12288 /* ESSymbolLike */ ? getGlobalESSymbolType() :
59133
59133
  t.flags & 67108864 /* NonPrimitive */ ? emptyObjectType :
59134
59134
  t.flags & 4194304 /* Index */ ? keyofConstraintType :
59135
59135
  t.flags & 2 /* Unknown */ && !strictNullChecks ? emptyObjectType :
@@ -60704,8 +60704,8 @@ var ts;
60704
60704
  function getGlobalESSymbolConstructorTypeSymbol(reportErrors) {
60705
60705
  return deferredGlobalESSymbolConstructorTypeSymbol || (deferredGlobalESSymbolConstructorTypeSymbol = getGlobalTypeSymbol("SymbolConstructor", reportErrors));
60706
60706
  }
60707
- function getGlobalESSymbolType(reportErrors) {
60708
- return (deferredGlobalESSymbolType || (deferredGlobalESSymbolType = getGlobalType("Symbol", /*arity*/ 0, reportErrors))) || emptyObjectType;
60707
+ function getGlobalESSymbolType() {
60708
+ return (deferredGlobalESSymbolType || (deferredGlobalESSymbolType = getGlobalType("Symbol", /*arity*/ 0, /*reportErrors*/ false))) || emptyObjectType;
60709
60709
  }
60710
60710
  function getGlobalPromiseType(reportErrors) {
60711
60711
  return (deferredGlobalPromiseType || (deferredGlobalPromiseType = getGlobalType("Promise", /*arity*/ 1, reportErrors))) || emptyGenericType;
@@ -60769,8 +60769,8 @@ var ts;
60769
60769
  deferredGlobalAwaitedSymbol || (deferredGlobalAwaitedSymbol = getGlobalTypeAliasSymbol("Awaited", /*arity*/ 1, reportErrors) || (reportErrors ? unknownSymbol : undefined));
60770
60770
  return deferredGlobalAwaitedSymbol === unknownSymbol ? undefined : deferredGlobalAwaitedSymbol;
60771
60771
  }
60772
- function getGlobalBigIntType(reportErrors) {
60773
- return (deferredGlobalBigIntType || (deferredGlobalBigIntType = getGlobalType("BigInt", /*arity*/ 0, reportErrors))) || emptyObjectType;
60772
+ function getGlobalBigIntType() {
60773
+ return (deferredGlobalBigIntType || (deferredGlobalBigIntType = getGlobalType("BigInt", /*arity*/ 0, /*reportErrors*/ false))) || emptyObjectType;
60774
60774
  }
60775
60775
  /**
60776
60776
  * Instantiates a global type that is generic with some element type, and returns that instantiation.
@@ -64922,7 +64922,7 @@ var ts;
64922
64922
  if ((globalStringType === source && stringType === target) ||
64923
64923
  (globalNumberType === source && numberType === target) ||
64924
64924
  (globalBooleanType === source && booleanType === target) ||
64925
- (getGlobalESSymbolType(/*reportErrors*/ false) === source && esSymbolType === target)) {
64925
+ (getGlobalESSymbolType() === source && esSymbolType === target)) {
64926
64926
  reportError(ts.Diagnostics._0_is_a_primitive_but_1_is_a_wrapper_object_Prefer_using_0_when_possible, targetType, sourceType);
64927
64927
  }
64928
64928
  }
@@ -82810,7 +82810,7 @@ var ts;
82810
82810
  var childSymbol = getSymbolAtLocation(childNode);
82811
82811
  if (childSymbol && childSymbol === testedSymbol) {
82812
82812
  // If the test was a simple identifier, the above check is sufficient
82813
- if (ts.isIdentifier(expr)) {
82813
+ if (ts.isIdentifier(expr) || ts.isIdentifier(testedNode) && ts.isBinaryExpression(testedNode.parent)) {
82814
82814
  return true;
82815
82815
  }
82816
82816
  // Otherwise we need to ensure the symbol is called on the same target
@@ -116024,7 +116024,7 @@ var ts;
116024
116024
  };
116025
116025
  }
116026
116026
  // directoryExists
116027
- if (originalDirectoryExists && originalCreateDirectory) {
116027
+ if (originalDirectoryExists) {
116028
116028
  host.directoryExists = function (directory) {
116029
116029
  var key = toPath(directory);
116030
116030
  var value = directoryExistsCache.get(key);
@@ -116034,11 +116034,13 @@ var ts;
116034
116034
  directoryExistsCache.set(key, !!newValue);
116035
116035
  return newValue;
116036
116036
  };
116037
- host.createDirectory = function (directory) {
116038
- var key = toPath(directory);
116039
- directoryExistsCache.delete(key);
116040
- originalCreateDirectory.call(host, directory);
116041
- };
116037
+ if (originalCreateDirectory) {
116038
+ host.createDirectory = function (directory) {
116039
+ var key = toPath(directory);
116040
+ directoryExistsCache.delete(key);
116041
+ originalCreateDirectory.call(host, directory);
116042
+ };
116043
+ }
116042
116044
  }
116043
116045
  return {
116044
116046
  originalReadFile: originalReadFile,
@@ -128424,6 +128426,41 @@ var ts;
128424
128426
  return true;
128425
128427
  }
128426
128428
  ts.isTextWhiteSpaceLike = isTextWhiteSpaceLike;
128429
+ function getMappedLocation(location, sourceMapper, fileExists) {
128430
+ var mapsTo = sourceMapper.tryGetSourcePosition(location);
128431
+ return mapsTo && (!fileExists || fileExists(ts.normalizePath(mapsTo.fileName)) ? mapsTo : undefined);
128432
+ }
128433
+ ts.getMappedLocation = getMappedLocation;
128434
+ function getMappedDocumentSpan(documentSpan, sourceMapper, fileExists) {
128435
+ var fileName = documentSpan.fileName, textSpan = documentSpan.textSpan;
128436
+ var newPosition = getMappedLocation({ fileName: fileName, pos: textSpan.start }, sourceMapper, fileExists);
128437
+ if (!newPosition)
128438
+ return undefined;
128439
+ var newEndPosition = getMappedLocation({ fileName: fileName, pos: textSpan.start + textSpan.length }, sourceMapper, fileExists);
128440
+ var newLength = newEndPosition
128441
+ ? newEndPosition.pos - newPosition.pos
128442
+ : textSpan.length; // This shouldn't happen
128443
+ return {
128444
+ fileName: newPosition.fileName,
128445
+ textSpan: {
128446
+ start: newPosition.pos,
128447
+ length: newLength,
128448
+ },
128449
+ originalFileName: documentSpan.fileName,
128450
+ originalTextSpan: documentSpan.textSpan,
128451
+ contextSpan: getMappedContextSpan(documentSpan, sourceMapper, fileExists),
128452
+ originalContextSpan: documentSpan.contextSpan
128453
+ };
128454
+ }
128455
+ ts.getMappedDocumentSpan = getMappedDocumentSpan;
128456
+ function getMappedContextSpan(documentSpan, sourceMapper, fileExists) {
128457
+ var contextSpanStart = documentSpan.contextSpan && getMappedLocation({ fileName: documentSpan.fileName, pos: documentSpan.contextSpan.start }, sourceMapper, fileExists);
128458
+ var contextSpanEnd = documentSpan.contextSpan && getMappedLocation({ fileName: documentSpan.fileName, pos: documentSpan.contextSpan.start + documentSpan.contextSpan.length }, sourceMapper, fileExists);
128459
+ return contextSpanStart && contextSpanEnd ?
128460
+ { start: contextSpanStart.pos, length: contextSpanEnd.pos - contextSpanStart.pos } :
128461
+ undefined;
128462
+ }
128463
+ ts.getMappedContextSpan = getMappedContextSpan;
128427
128464
  // #endregion
128428
128465
  // Display-part writer helpers
128429
128466
  // #region
@@ -137345,6 +137382,7 @@ var ts;
137345
137382
  var commonjsSource = source && ts.isBinaryExpression(source) ? source.left : undefined;
137346
137383
  return !!(source && ((_a = target.declarations) === null || _a === void 0 ? void 0 : _a.some(function (d) { return d === source || d === commonjsSource; })));
137347
137384
  }
137385
+ FindAllReferences.isDeclarationOfSymbol = isDeclarationOfSymbol;
137348
137386
  /**
137349
137387
  * True if 'decl' provides a value, as in `function f() {}`;
137350
137388
  * false if 'decl' is just a location for a future write, as in 'let x;'
@@ -164504,9 +164542,8 @@ var ts;
164504
164542
  var isStaticMember = ts.hasStaticModifier(declaration);
164505
164543
  return ts.firstDefined(ts.getAllSuperTypeNodes(classOrInterfaceDeclaration), function (superTypeNode) {
164506
164544
  var baseType = checker.getTypeAtLocation(superTypeNode);
164507
- var symbol = isStaticMember
164508
- ? ts.find(checker.getExportsOfModule(baseType.symbol), function (s) { return s.escapedName === declaration.symbol.name; })
164509
- : checker.getPropertyOfType(baseType, declaration.symbol.name);
164545
+ var type = isStaticMember && baseType.symbol ? checker.getTypeOfSymbol(baseType.symbol) : baseType;
164546
+ var symbol = checker.getPropertyOfType(type, declaration.symbol.name);
164510
164547
  return symbol ? cb(symbol) : undefined;
164511
164548
  });
164512
164549
  }
@@ -164749,70 +164786,6 @@ var ts;
164749
164786
  return ts.codefix.getSupportedErrorCodes();
164750
164787
  }
164751
164788
  ts.getSupportedCodeFixes = getSupportedCodeFixes;
164752
- // Cache host information about script Should be refreshed
164753
- // at each language service public entry point, since we don't know when
164754
- // the set of scripts handled by the host changes.
164755
- var HostCache = /** @class */ (function () {
164756
- function HostCache(host, getCanonicalFileName) {
164757
- this.host = host;
164758
- // script id => script index
164759
- this.currentDirectory = host.getCurrentDirectory();
164760
- this.fileNameToEntry = new ts.Map();
164761
- // Initialize the list with the root file names
164762
- var rootFileNames = host.getScriptFileNames();
164763
- ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("session" /* Session */, "initializeHostCache", { count: rootFileNames.length });
164764
- for (var _i = 0, rootFileNames_1 = rootFileNames; _i < rootFileNames_1.length; _i++) {
164765
- var fileName = rootFileNames_1[_i];
164766
- this.createEntry(fileName, ts.toPath(fileName, this.currentDirectory, getCanonicalFileName));
164767
- }
164768
- ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
164769
- }
164770
- HostCache.prototype.createEntry = function (fileName, path) {
164771
- var entry;
164772
- var scriptSnapshot = this.host.getScriptSnapshot(fileName);
164773
- if (scriptSnapshot) {
164774
- entry = {
164775
- hostFileName: fileName,
164776
- version: this.host.getScriptVersion(fileName),
164777
- scriptSnapshot: scriptSnapshot,
164778
- scriptKind: ts.getScriptKind(fileName, this.host)
164779
- };
164780
- }
164781
- else {
164782
- entry = fileName;
164783
- }
164784
- this.fileNameToEntry.set(path, entry);
164785
- return entry;
164786
- };
164787
- HostCache.prototype.getEntryByPath = function (path) {
164788
- return this.fileNameToEntry.get(path);
164789
- };
164790
- HostCache.prototype.getHostFileInformation = function (path) {
164791
- var entry = this.fileNameToEntry.get(path);
164792
- return !ts.isString(entry) ? entry : undefined;
164793
- };
164794
- HostCache.prototype.getOrCreateEntryByPath = function (fileName, path) {
164795
- var info = this.getEntryByPath(path) || this.createEntry(fileName, path);
164796
- return ts.isString(info) ? undefined : info; // TODO: GH#18217
164797
- };
164798
- HostCache.prototype.getRootFileNames = function () {
164799
- var names = [];
164800
- this.fileNameToEntry.forEach(function (entry) {
164801
- if (ts.isString(entry)) {
164802
- names.push(entry);
164803
- }
164804
- else {
164805
- names.push(entry.hostFileName);
164806
- }
164807
- });
164808
- return names;
164809
- };
164810
- HostCache.prototype.getScriptSnapshot = function (path) {
164811
- var file = this.getHostFileInformation(path);
164812
- return (file && file.scriptSnapshot); // TODO: GH#18217
164813
- };
164814
- return HostCache;
164815
- }());
164816
164789
  var SyntaxTreeCache = /** @class */ (function () {
164817
164790
  function SyntaxTreeCache(host) {
164818
164791
  this.host = host;
@@ -165074,32 +165047,13 @@ var ts;
165074
165047
  program = undefined; // TODO: GH#18217
165075
165048
  lastTypesRootVersion = typeRootsVersion;
165076
165049
  }
165050
+ var rootFileNames = host.getScriptFileNames();
165077
165051
  // Get a fresh cache of the host information
165078
- var hostCache = new HostCache(host, getCanonicalFileName);
165079
- var rootFileNames = hostCache.getRootFileNames();
165080
165052
  var newSettings = host.getCompilationSettings() || getDefaultCompilerOptions();
165081
165053
  var hasInvalidatedResolution = host.hasInvalidatedResolution || ts.returnFalse;
165082
165054
  var hasChangedAutomaticTypeDirectiveNames = ts.maybeBind(host, host.hasChangedAutomaticTypeDirectiveNames);
165083
165055
  var projectReferences = (_b = host.getProjectReferences) === null || _b === void 0 ? void 0 : _b.call(host);
165084
165056
  var parsedCommandLines;
165085
- var parseConfigHost = {
165086
- useCaseSensitiveFileNames: useCaseSensitiveFileNames,
165087
- fileExists: fileExists,
165088
- readFile: readFile,
165089
- readDirectory: readDirectory,
165090
- trace: ts.maybeBind(host, host.trace),
165091
- getCurrentDirectory: function () { return currentDirectory; },
165092
- onUnRecoverableConfigFileDiagnostic: ts.noop,
165093
- };
165094
- // If the program is already up-to-date, we can reuse it
165095
- if (ts.isProgramUptoDate(program, rootFileNames, newSettings, function (_path, fileName) { return host.getScriptVersion(fileName); }, fileExists, hasInvalidatedResolution, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) {
165096
- return;
165097
- }
165098
- // IMPORTANT - It is critical from this moment onward that we do not check
165099
- // cancellation tokens. We are about to mutate source files from a previous program
165100
- // instance. If we cancel midway through, we may end up in an inconsistent state where
165101
- // the program points to old source files that have been invalidated because of
165102
- // incremental parsing.
165103
165057
  // Now create a new compiler
165104
165058
  var compilerHost = {
165105
165059
  getSourceFile: getOrCreateSourceFile,
@@ -165111,8 +165065,8 @@ var ts;
165111
165065
  getDefaultLibFileName: function (options) { return host.getDefaultLibFileName(options); },
165112
165066
  writeFile: ts.noop,
165113
165067
  getCurrentDirectory: function () { return currentDirectory; },
165114
- fileExists: fileExists,
165115
- readFile: readFile,
165068
+ fileExists: function (fileName) { return host.fileExists(fileName); },
165069
+ readFile: function (fileName) { return host.readFile && host.readFile(fileName); },
165116
165070
  getSymlinkCache: ts.maybeBind(host, host.getSymlinkCache),
165117
165071
  realpath: ts.maybeBind(host, host.realpath),
165118
165072
  directoryExists: function (directoryName) {
@@ -165121,19 +165075,56 @@ var ts;
165121
165075
  getDirectories: function (path) {
165122
165076
  return host.getDirectories ? host.getDirectories(path) : [];
165123
165077
  },
165124
- readDirectory: readDirectory,
165078
+ readDirectory: function (path, extensions, exclude, include, depth) {
165079
+ ts.Debug.checkDefined(host.readDirectory, "'LanguageServiceHost.readDirectory' must be implemented to correctly process 'projectReferences'");
165080
+ return host.readDirectory(path, extensions, exclude, include, depth);
165081
+ },
165125
165082
  onReleaseOldSourceFile: onReleaseOldSourceFile,
165126
165083
  onReleaseParsedCommandLine: onReleaseParsedCommandLine,
165127
165084
  hasInvalidatedResolution: hasInvalidatedResolution,
165128
165085
  hasChangedAutomaticTypeDirectiveNames: hasChangedAutomaticTypeDirectiveNames,
165129
- trace: parseConfigHost.trace,
165086
+ trace: ts.maybeBind(host, host.trace),
165130
165087
  resolveModuleNames: ts.maybeBind(host, host.resolveModuleNames),
165131
165088
  getModuleResolutionCache: ts.maybeBind(host, host.getModuleResolutionCache),
165132
165089
  resolveTypeReferenceDirectives: ts.maybeBind(host, host.resolveTypeReferenceDirectives),
165133
165090
  useSourceOfProjectReferenceRedirect: ts.maybeBind(host, host.useSourceOfProjectReferenceRedirect),
165134
165091
  getParsedCommandLine: getParsedCommandLine,
165135
165092
  };
165093
+ var originalGetSourceFile = compilerHost.getSourceFile;
165094
+ var getSourceFileWithCache = ts.changeCompilerHostLikeToUseCache(compilerHost, function (fileName) { return ts.toPath(fileName, currentDirectory, getCanonicalFileName); }, function () {
165095
+ var args = [];
165096
+ for (var _i = 0; _i < arguments.length; _i++) {
165097
+ args[_i] = arguments[_i];
165098
+ }
165099
+ return originalGetSourceFile.call.apply(originalGetSourceFile, __spreadArray([compilerHost], args, false));
165100
+ }).getSourceFileWithCache;
165101
+ compilerHost.getSourceFile = getSourceFileWithCache;
165136
165102
  (_c = host.setCompilerHost) === null || _c === void 0 ? void 0 : _c.call(host, compilerHost);
165103
+ var parseConfigHost = {
165104
+ useCaseSensitiveFileNames: useCaseSensitiveFileNames,
165105
+ fileExists: function (fileName) { return compilerHost.fileExists(fileName); },
165106
+ readFile: function (fileName) { return compilerHost.readFile(fileName); },
165107
+ readDirectory: function () {
165108
+ var _a;
165109
+ var args = [];
165110
+ for (var _i = 0; _i < arguments.length; _i++) {
165111
+ args[_i] = arguments[_i];
165112
+ }
165113
+ return (_a = compilerHost).readDirectory.apply(_a, args);
165114
+ },
165115
+ trace: compilerHost.trace,
165116
+ getCurrentDirectory: compilerHost.getCurrentDirectory,
165117
+ onUnRecoverableConfigFileDiagnostic: ts.noop,
165118
+ };
165119
+ // If the program is already up-to-date, we can reuse it
165120
+ if (ts.isProgramUptoDate(program, rootFileNames, newSettings, function (_path, fileName) { return host.getScriptVersion(fileName); }, function (fileName) { return compilerHost.fileExists(fileName); }, hasInvalidatedResolution, hasChangedAutomaticTypeDirectiveNames, getParsedCommandLine, projectReferences)) {
165121
+ return;
165122
+ }
165123
+ // IMPORTANT - It is critical from this moment onward that we do not check
165124
+ // cancellation tokens. We are about to mutate source files from a previous program
165125
+ // instance. If we cancel midway through, we may end up in an inconsistent state where
165126
+ // the program points to old source files that have been invalidated because of
165127
+ // incremental parsing.
165137
165128
  var documentRegistryBucketKey = documentRegistry.getKeyForCompilationSettings(newSettings);
165138
165129
  var options = {
165139
165130
  rootNames: rootFileNames,
@@ -165143,9 +165134,9 @@ var ts;
165143
165134
  projectReferences: projectReferences
165144
165135
  };
165145
165136
  program = ts.createProgram(options);
165146
- // hostCache is captured in the closure for 'getOrCreateSourceFile' but it should not be used past this point.
165147
- // It needs to be cleared to allow all collected snapshots to be released
165148
- hostCache = undefined;
165137
+ // 'getOrCreateSourceFile' depends on caching but should be used past this point.
165138
+ // After this point, the cache needs to be cleared to allow all collected snapshots to be released
165139
+ compilerHost = undefined;
165149
165140
  parsedCommandLines = undefined;
165150
165141
  // 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,
165151
165142
  // Because it only functions until `hostCache` is cleared, while we'll potentially need the functionality to lazily read sourcemap files during
@@ -165185,26 +165176,6 @@ var ts;
165185
165176
  onReleaseOldSourceFile(oldResolvedRef.sourceFile, oldOptions);
165186
165177
  }
165187
165178
  }
165188
- function fileExists(fileName) {
165189
- var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
165190
- var entry = hostCache && hostCache.getEntryByPath(path);
165191
- return entry ?
165192
- !ts.isString(entry) :
165193
- (!!host.fileExists && host.fileExists(fileName));
165194
- }
165195
- function readFile(fileName) {
165196
- // stub missing host functionality
165197
- var path = ts.toPath(fileName, currentDirectory, getCanonicalFileName);
165198
- var entry = hostCache && hostCache.getEntryByPath(path);
165199
- if (entry) {
165200
- return ts.isString(entry) ? undefined : ts.getSnapshotText(entry.scriptSnapshot);
165201
- }
165202
- return host.readFile && host.readFile(fileName);
165203
- }
165204
- function readDirectory(path, extensions, exclude, include, depth) {
165205
- ts.Debug.checkDefined(host.readDirectory, "'LanguageServiceHost.readDirectory' must be implemented to correctly process 'projectReferences'");
165206
- return host.readDirectory(path, extensions, exclude, include, depth);
165207
- }
165208
165179
  // Release any files we have acquired in the old program but are
165209
165180
  // not part of the new program.
165210
165181
  function onReleaseOldSourceFile(oldSourceFile, oldOptions) {
@@ -165215,14 +165186,16 @@ var ts;
165215
165186
  return getOrCreateSourceFileByPath(fileName, ts.toPath(fileName, currentDirectory, getCanonicalFileName), languageVersion, onError, shouldCreateNewSourceFile);
165216
165187
  }
165217
165188
  function getOrCreateSourceFileByPath(fileName, path, _languageVersion, _onError, shouldCreateNewSourceFile) {
165218
- ts.Debug.assert(hostCache !== undefined, "getOrCreateSourceFileByPath called after typical CompilerHost lifetime, check the callstack something with a reference to an old host.");
165189
+ ts.Debug.assert(compilerHost, "getOrCreateSourceFileByPath called after typical CompilerHost lifetime, check the callstack something with a reference to an old host.");
165219
165190
  // The program is asking for this file, check first if the host can locate it.
165220
165191
  // If the host can not locate the file, then it does not exist. return undefined
165221
165192
  // to the program to allow reporting of errors for missing files.
165222
- var hostFileInformation = hostCache && hostCache.getOrCreateEntryByPath(fileName, path);
165223
- if (!hostFileInformation) {
165193
+ var scriptSnapshot = host.getScriptSnapshot(fileName);
165194
+ if (!scriptSnapshot) {
165224
165195
  return undefined;
165225
165196
  }
165197
+ var scriptKind = ts.getScriptKind(fileName, host);
165198
+ var scriptVersion = host.getScriptVersion(fileName);
165226
165199
  // Check if the language version has changed since we last created a program; if they are the same,
165227
165200
  // it is safe to reuse the sourceFiles; if not, then the shape of the AST can change, and the oldSourceFile
165228
165201
  // can not be reused. we have to dump all syntax trees and create new ones.
@@ -165254,8 +165227,8 @@ var ts;
165254
165227
  // We do not support the scenario where a host can modify a registered
165255
165228
  // file's script kind, i.e. in one project some file is treated as ".ts"
165256
165229
  // and in another as ".js"
165257
- if (hostFileInformation.scriptKind === oldSourceFile.scriptKind) {
165258
- return documentRegistry.updateDocumentWithKey(fileName, path, host, documentRegistryBucketKey, hostFileInformation.scriptSnapshot, hostFileInformation.version, hostFileInformation.scriptKind);
165230
+ if (scriptKind === oldSourceFile.scriptKind) {
165231
+ return documentRegistry.updateDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind);
165259
165232
  }
165260
165233
  else {
165261
165234
  // Release old source file and fall through to aquire new file with new script kind
@@ -165265,7 +165238,7 @@ var ts;
165265
165238
  // We didn't already have the file. Fall through and acquire it from the registry.
165266
165239
  }
165267
165240
  // Could not find this file in the old program, create a new SourceFile for it.
165268
- return documentRegistry.acquireDocumentWithKey(fileName, path, host, documentRegistryBucketKey, hostFileInformation.scriptSnapshot, hostFileInformation.version, hostFileInformation.scriptKind);
165241
+ return documentRegistry.acquireDocumentWithKey(fileName, path, host, documentRegistryBucketKey, scriptSnapshot, scriptVersion, scriptKind);
165269
165242
  }
165270
165243
  }
165271
165244
  // TODO: GH#18217 frequently asserted as defined
@@ -165281,6 +165254,61 @@ var ts;
165281
165254
  var _a;
165282
165255
  return (_a = host.getPackageJsonAutoImportProvider) === null || _a === void 0 ? void 0 : _a.call(host);
165283
165256
  }
165257
+ function updateIsDefinitionOfReferencedSymbols(referencedSymbols, knownSymbolSpans) {
165258
+ var checker = program.getTypeChecker();
165259
+ var symbol = getSymbolForProgram();
165260
+ if (!symbol)
165261
+ return false;
165262
+ for (var _i = 0, referencedSymbols_1 = referencedSymbols; _i < referencedSymbols_1.length; _i++) {
165263
+ var referencedSymbol = referencedSymbols_1[_i];
165264
+ for (var _a = 0, _b = referencedSymbol.references; _a < _b.length; _a++) {
165265
+ var ref = _b[_a];
165266
+ var refNode = getNodeForSpan(ref);
165267
+ ts.Debug.assertIsDefined(refNode);
165268
+ if (knownSymbolSpans.has(ref) || ts.FindAllReferences.isDeclarationOfSymbol(refNode, symbol)) {
165269
+ knownSymbolSpans.add(ref);
165270
+ ref.isDefinition = true;
165271
+ var mappedSpan = ts.getMappedDocumentSpan(ref, sourceMapper, ts.maybeBind(host, host.fileExists));
165272
+ if (mappedSpan) {
165273
+ knownSymbolSpans.add(mappedSpan);
165274
+ }
165275
+ }
165276
+ else {
165277
+ ref.isDefinition = false;
165278
+ }
165279
+ }
165280
+ }
165281
+ return true;
165282
+ function getSymbolForProgram() {
165283
+ for (var _i = 0, referencedSymbols_2 = referencedSymbols; _i < referencedSymbols_2.length; _i++) {
165284
+ var referencedSymbol = referencedSymbols_2[_i];
165285
+ for (var _a = 0, _b = referencedSymbol.references; _a < _b.length; _a++) {
165286
+ var ref = _b[_a];
165287
+ if (knownSymbolSpans.has(ref)) {
165288
+ var refNode = getNodeForSpan(ref);
165289
+ ts.Debug.assertIsDefined(refNode);
165290
+ return checker.getSymbolAtLocation(refNode);
165291
+ }
165292
+ var mappedSpan = ts.getMappedDocumentSpan(ref, sourceMapper, ts.maybeBind(host, host.fileExists));
165293
+ if (mappedSpan && knownSymbolSpans.has(mappedSpan)) {
165294
+ var refNode = getNodeForSpan(mappedSpan);
165295
+ if (refNode) {
165296
+ return checker.getSymbolAtLocation(refNode);
165297
+ }
165298
+ }
165299
+ }
165300
+ }
165301
+ return undefined;
165302
+ }
165303
+ function getNodeForSpan(docSpan) {
165304
+ var sourceFile = program.getSourceFile(docSpan.fileName);
165305
+ if (!sourceFile)
165306
+ return undefined;
165307
+ var rawNode = ts.getTouchingPropertyName(sourceFile, docSpan.textSpan.start);
165308
+ var adjustedNode = ts.FindAllReferences.Core.getAdjustedNode(rawNode, { use: 1 /* References */ });
165309
+ return adjustedNode;
165310
+ }
165311
+ }
165284
165312
  function cleanupSemanticCache() {
165285
165313
  program = undefined; // TODO: GH#18217
165286
165314
  }
@@ -166207,6 +166235,7 @@ var ts;
166207
166235
  getNonBoundSourceFile: getNonBoundSourceFile,
166208
166236
  getProgram: getProgram,
166209
166237
  getAutoImportProvider: getAutoImportProvider,
166238
+ updateIsDefinitionOfReferencedSymbols: updateIsDefinitionOfReferencedSymbols,
166210
166239
  getApplicableRefactors: getApplicableRefactors,
166211
166240
  getEditsForRefactor: getEditsForRefactor,
166212
166241
  toLineColumnOffset: toLineColumnOffset,
@@ -174930,66 +174959,142 @@ var ts;
174930
174959
  return textSpan.start + 100003 * textSpan.length;
174931
174960
  }, ts.documentSpansEqual);
174932
174961
  }
174933
- function combineProjectOutputForRenameLocations(projects, defaultProject, initialLocation, findInStrings, findInComments, _a) {
174962
+ function getRenameLocationsWorker(projects, defaultProject, initialLocation, findInStrings, findInComments, _a) {
174934
174963
  var providePrefixAndSuffixTextForRename = _a.providePrefixAndSuffixTextForRename;
174935
- var outputs = [];
174964
+ var perProjectResults = getPerProjectReferences(projects, defaultProject, initialLocation,
174965
+ /*isForRename*/ true, function (project, position) { return project.getLanguageService().findRenameLocations(position.fileName, position.pos, findInStrings, findInComments, providePrefixAndSuffixTextForRename); }, function (renameLocation, cb) { return cb(documentSpanLocation(renameLocation)); });
174966
+ // No filtering or dedup'ing is required if there's exactly one project
174967
+ if (ts.isArray(perProjectResults)) {
174968
+ return perProjectResults;
174969
+ }
174970
+ var results = [];
174936
174971
  var seen = createDocumentSpanSet();
174937
- combineProjectOutputWorker(projects, defaultProject, initialLocation,
174938
- /*isForRename*/ true, function (project, location, tryAddToTodo) {
174939
- var projectOutputs = project.getLanguageService().findRenameLocations(location.fileName, location.pos, findInStrings, findInComments, providePrefixAndSuffixTextForRename);
174940
- if (projectOutputs) {
174941
- for (var _i = 0, projectOutputs_1 = projectOutputs; _i < projectOutputs_1.length; _i++) {
174942
- var output = projectOutputs_1[_i];
174943
- if (!seen.has(output) && !tryAddToTodo(project, documentSpanLocation(output))) {
174944
- seen.add(output);
174945
- outputs.push(output);
174946
- }
174972
+ perProjectResults.forEach(function (projectResults, project) {
174973
+ for (var _i = 0, projectResults_1 = projectResults; _i < projectResults_1.length; _i++) {
174974
+ var result = projectResults_1[_i];
174975
+ // If there's a mapped location, it'll appear in the results for another project
174976
+ if (!seen.has(result) && !getMappedLocationForProject(documentSpanLocation(result), project)) {
174977
+ results.push(result);
174978
+ seen.add(result);
174947
174979
  }
174948
174980
  }
174949
174981
  });
174950
- return outputs;
174982
+ return results;
174951
174983
  }
174952
174984
  function getDefinitionLocation(defaultProject, initialLocation, isForRename) {
174953
- var infos = defaultProject.getLanguageService().getDefinitionAtPosition(initialLocation.fileName, initialLocation.pos, /*searchOtherFilesOnly*/ false, isForRename);
174985
+ var infos = defaultProject.getLanguageService().getDefinitionAtPosition(initialLocation.fileName, initialLocation.pos, /*searchOtherFilesOnly*/ false, /*stopAtAlias*/ isForRename);
174954
174986
  var info = infos && ts.firstOrUndefined(infos);
174955
174987
  return info && !info.isLocal ? { fileName: info.fileName, pos: info.textSpan.start } : undefined;
174956
174988
  }
174957
- function combineProjectOutputForReferences(projects, defaultProject, initialLocation, logger) {
174958
- var outputs = [];
174959
- combineProjectOutputWorker(projects, defaultProject, initialLocation,
174960
- /*isForRename*/ false, function (project, location, getMappedLocation) {
174961
- var _a, _b;
174962
- logger.info("Finding references to " + location.fileName + " position " + location.pos + " in project " + project.getProjectName());
174963
- var projectOutputs = project.getLanguageService().findReferences(location.fileName, location.pos);
174964
- if (projectOutputs) {
174965
- var clearIsDefinition = ((_b = (_a = projectOutputs[0]) === null || _a === void 0 ? void 0 : _a.references[0]) === null || _b === void 0 ? void 0 : _b.isDefinition) === undefined;
174966
- var _loop_9 = function (referencedSymbol) {
174967
- var mappedDefinitionFile = getMappedLocation(project, documentSpanLocation(referencedSymbol.definition));
174968
- var definition = mappedDefinitionFile === undefined ?
174969
- referencedSymbol.definition : __assign(__assign({}, referencedSymbol.definition), { textSpan: ts.createTextSpan(mappedDefinitionFile.pos, referencedSymbol.definition.textSpan.length), fileName: mappedDefinitionFile.fileName, contextSpan: getMappedContextSpan(referencedSymbol.definition, project) });
174970
- var symbolToAddTo = ts.find(outputs, function (o) { return ts.documentSpansEqual(o.definition, definition); });
174971
- if (!symbolToAddTo) {
174972
- symbolToAddTo = { definition: definition, references: [] };
174973
- outputs.push(symbolToAddTo);
174974
- }
174975
- for (var _c = 0, _d = referencedSymbol.references; _c < _d.length; _c++) {
174976
- var ref = _d[_c];
174977
- // If it's in a mapped file, that is added to the todo list by `getMappedLocation`.
174978
- if (!ts.contains(symbolToAddTo.references, ref, ts.documentSpansEqual) && !getMappedLocation(project, documentSpanLocation(ref))) {
174979
- if (clearIsDefinition) {
174980
- delete ref.isDefinition;
174981
- }
174982
- symbolToAddTo.references.push(ref);
174983
- }
174989
+ function getReferencesWorker(projects, defaultProject, initialLocation, logger) {
174990
+ var perProjectResults = getPerProjectReferences(projects, defaultProject, initialLocation,
174991
+ /*isForRename*/ false, function (project, position) {
174992
+ logger.info("Finding references to " + position.fileName + " position " + position.pos + " in project " + project.getProjectName());
174993
+ return project.getLanguageService().findReferences(position.fileName, position.pos);
174994
+ }, function (referencedSymbol, cb) {
174995
+ cb(documentSpanLocation(referencedSymbol.definition));
174996
+ for (var _i = 0, _a = referencedSymbol.references; _i < _a.length; _i++) {
174997
+ var ref = _a[_i];
174998
+ cb(documentSpanLocation(ref));
174999
+ }
175000
+ });
175001
+ // No re-mapping or isDefinition updatses are required if there's exactly one project
175002
+ if (ts.isArray(perProjectResults)) {
175003
+ return perProjectResults;
175004
+ }
175005
+ // `isDefinition` is only (definitely) correct in `defaultProject` because we might
175006
+ // have started the other project searches from related symbols. Propagate the
175007
+ // correct results to all other projects.
175008
+ var defaultProjectResults = perProjectResults.get(defaultProject);
175009
+ if (defaultProjectResults[0].references[0].isDefinition === undefined) {
175010
+ // Clear all isDefinition properties
175011
+ perProjectResults.forEach(function (projectResults) {
175012
+ for (var _i = 0, projectResults_2 = projectResults; _i < projectResults_2.length; _i++) {
175013
+ var referencedSymbol = projectResults_2[_i];
175014
+ for (var _a = 0, _b = referencedSymbol.references; _a < _b.length; _a++) {
175015
+ var ref = _b[_a];
175016
+ delete ref.isDefinition;
174984
175017
  }
174985
- };
174986
- for (var _i = 0, projectOutputs_2 = projectOutputs; _i < projectOutputs_2.length; _i++) {
174987
- var referencedSymbol = projectOutputs_2[_i];
174988
- _loop_9(referencedSymbol);
174989
175018
  }
175019
+ });
175020
+ }
175021
+ else {
175022
+ // Correct isDefinition properties from projects other than defaultProject
175023
+ var knownSymbolSpans_1 = createDocumentSpanSet();
175024
+ for (var _i = 0, defaultProjectResults_1 = defaultProjectResults; _i < defaultProjectResults_1.length; _i++) {
175025
+ var referencedSymbol = defaultProjectResults_1[_i];
175026
+ for (var _a = 0, _b = referencedSymbol.references; _a < _b.length; _a++) {
175027
+ var ref = _b[_a];
175028
+ if (ref.isDefinition) {
175029
+ knownSymbolSpans_1.add(ref);
175030
+ // One is enough - updateIsDefinitionOfReferencedSymbols will fill out the set based on symbols
175031
+ break;
175032
+ }
175033
+ }
175034
+ }
175035
+ var updatedProjects_1 = new ts.Set();
175036
+ var _loop_9 = function () {
175037
+ var progress = false;
175038
+ perProjectResults.forEach(function (referencedSymbols, project) {
175039
+ if (updatedProjects_1.has(project))
175040
+ return;
175041
+ var updated = project.getLanguageService().updateIsDefinitionOfReferencedSymbols(referencedSymbols, knownSymbolSpans_1);
175042
+ if (updated) {
175043
+ updatedProjects_1.add(project);
175044
+ progress = true;
175045
+ }
175046
+ });
175047
+ if (!progress)
175048
+ return "break";
175049
+ };
175050
+ while (true) {
175051
+ var state_2 = _loop_9();
175052
+ if (state_2 === "break")
175053
+ break;
175054
+ }
175055
+ perProjectResults.forEach(function (referencedSymbols, project) {
175056
+ if (updatedProjects_1.has(project))
175057
+ return;
175058
+ for (var _i = 0, referencedSymbols_1 = referencedSymbols; _i < referencedSymbols_1.length; _i++) {
175059
+ var referencedSymbol = referencedSymbols_1[_i];
175060
+ for (var _a = 0, _b = referencedSymbol.references; _a < _b.length; _a++) {
175061
+ var ref = _b[_a];
175062
+ ref.isDefinition = false;
175063
+ }
175064
+ }
175065
+ });
175066
+ }
175067
+ // We need to de-duplicate and aggregate the results by choosing an authoritative version
175068
+ // of each definition and merging references from all the projects where they appear.
175069
+ var results = [];
175070
+ var seenRefs = createDocumentSpanSet(); // It doesn't make sense to have a reference in two definition lists, so we de-dup globally
175071
+ // TODO: We might end up with a more logical allocation of refs to defs if we pre-sorted the defs by descending ref-count.
175072
+ // Otherwise, it just ends up attached to the first corresponding def we happen to process. The others may or may not be
175073
+ // dropped later when we check for defs with ref-count 0.
175074
+ perProjectResults.forEach(function (projectResults, project) {
175075
+ var _loop_10 = function (referencedSymbol) {
175076
+ var mappedDefinitionFile = getMappedLocationForProject(documentSpanLocation(referencedSymbol.definition), project);
175077
+ var definition = mappedDefinitionFile === undefined ?
175078
+ referencedSymbol.definition : __assign(__assign({}, referencedSymbol.definition), { textSpan: ts.createTextSpan(mappedDefinitionFile.pos, referencedSymbol.definition.textSpan.length), fileName: mappedDefinitionFile.fileName, contextSpan: getMappedContextSpanForProject(referencedSymbol.definition, project) });
175079
+ var symbolToAddTo = ts.find(results, function (o) { return ts.documentSpansEqual(o.definition, definition); });
175080
+ if (!symbolToAddTo) {
175081
+ symbolToAddTo = { definition: definition, references: [] };
175082
+ results.push(symbolToAddTo);
175083
+ }
175084
+ for (var _a = 0, _b = referencedSymbol.references; _a < _b.length; _a++) {
175085
+ var ref = _b[_a];
175086
+ if (!seenRefs.has(ref) && !getMappedLocationForProject(documentSpanLocation(ref), project)) {
175087
+ seenRefs.add(ref);
175088
+ symbolToAddTo.references.push(ref);
175089
+ }
175090
+ }
175091
+ };
175092
+ for (var _i = 0, projectResults_3 = projectResults; _i < projectResults_3.length; _i++) {
175093
+ var referencedSymbol = projectResults_3[_i];
175094
+ _loop_10(referencedSymbol);
174990
175095
  }
174991
175096
  });
174992
- return outputs.filter(function (o) { return o.references.length !== 0; });
175097
+ return results.filter(function (o) { return o.references.length !== 0; });
174993
175098
  }
174994
175099
  function forEachProjectInProjects(projects, path, cb) {
174995
175100
  for (var _i = 0, _a = ts.isArray(projects) ? projects : projects.projects; _i < _a.length; _i++) {
@@ -175005,40 +175110,117 @@ var ts;
175005
175110
  });
175006
175111
  }
175007
175112
  }
175008
- function combineProjectOutputWorker(projects, defaultProject, initialLocation, isForRename, cb) {
175009
- var projectService = defaultProject.projectService;
175010
- var toDo;
175011
- var seenProjects = new ts.Set();
175012
- forEachProjectInProjects(projects, initialLocation && initialLocation.fileName, function (project, path) {
175013
- // TLocation should be either `DocumentPosition` or `undefined`. Since `initialLocation` is `TLocation` this cast should be valid.
175014
- var location = (initialLocation ? { fileName: path, pos: initialLocation.pos } : undefined);
175015
- toDo = callbackProjectAndLocation(project, location, projectService, toDo, seenProjects, cb);
175113
+ /**
175114
+ * @param projects Projects initially known to contain {@link initialLocation}
175115
+ * @param defaultProject The default project containing {@link initialLocation}
175116
+ * @param initialLocation Where the search operation was triggered
175117
+ * @param getResultsForPosition This is where you plug in `findReferences`, `renameLocation`, etc
175118
+ * @param forPositionInResult Given an item returned by {@link getResultsForPosition} enumerate the positions referred to by that result
175119
+ * @returns In the common case where there's only one project, returns an array of results from {@link getResultsForPosition}.
175120
+ * If multiple projects were searched - even if they didn't return results - the result will be a map from project to per-project results.
175121
+ */
175122
+ function getPerProjectReferences(projects, defaultProject, initialLocation, isForRename, getResultsForPosition, forPositionInResult) {
175123
+ // If `getResultsForPosition` returns results for a project, they go in here
175124
+ var resultsMap = new ts.Map();
175125
+ var queue = [];
175126
+ // In order to get accurate isDefinition values for `defaultProject`,
175127
+ // we need to ensure that it is searched from `initialLocation`.
175128
+ // The easiest way to do this is to search it first.
175129
+ queue.push({ project: defaultProject, location: initialLocation });
175130
+ // This will queue `defaultProject` a second time, but it will be dropped
175131
+ // as a dup when it is dequeued.
175132
+ forEachProjectInProjects(projects, initialLocation.fileName, function (project, path) {
175133
+ var location = { fileName: path, pos: initialLocation.pos };
175134
+ queue.push({ project: project, location: location });
175016
175135
  });
175017
- // After initial references are collected, go over every other project and see if it has a reference for the symbol definition.
175018
- if (initialLocation) {
175019
- var defaultDefinition_1 = getDefinitionLocation(defaultProject, initialLocation, isForRename);
175020
- if (defaultDefinition_1) {
175021
- var getGeneratedDefinition_1 = ts.memoize(function () { return defaultProject.isSourceOfProjectReferenceRedirect(defaultDefinition_1.fileName) ?
175022
- defaultDefinition_1 :
175023
- defaultProject.getLanguageService().getSourceMapper().tryGetGeneratedPosition(defaultDefinition_1); });
175024
- var getSourceDefinition_1 = ts.memoize(function () { return defaultProject.isSourceOfProjectReferenceRedirect(defaultDefinition_1.fileName) ?
175025
- defaultDefinition_1 :
175026
- defaultProject.getLanguageService().getSourceMapper().tryGetSourcePosition(defaultDefinition_1); });
175027
- projectService.loadAncestorProjectTree(seenProjects);
175136
+ var projectService = defaultProject.projectService;
175137
+ var cancellationToken = defaultProject.getCancellationToken();
175138
+ var defaultDefinition = getDefinitionLocation(defaultProject, initialLocation, isForRename);
175139
+ // Don't call these unless !!defaultDefinition
175140
+ var getGeneratedDefinition = ts.memoize(function () { return defaultProject.isSourceOfProjectReferenceRedirect(defaultDefinition.fileName) ?
175141
+ defaultDefinition :
175142
+ defaultProject.getLanguageService().getSourceMapper().tryGetGeneratedPosition(defaultDefinition); });
175143
+ var getSourceDefinition = ts.memoize(function () { return defaultProject.isSourceOfProjectReferenceRedirect(defaultDefinition.fileName) ?
175144
+ defaultDefinition :
175145
+ defaultProject.getLanguageService().getSourceMapper().tryGetSourcePosition(defaultDefinition); });
175146
+ // Track which projects we have already searched so that we don't repeat searches.
175147
+ // We store the project key, rather than the project, because that's what `loadAncestorProjectTree` wants.
175148
+ // (For that same reason, we don't use `resultsMap` for this check.)
175149
+ var searchedProjects = new ts.Set();
175150
+ onCancellation: while (queue.length) {
175151
+ while (queue.length) {
175152
+ if (cancellationToken.isCancellationRequested())
175153
+ break onCancellation;
175154
+ var _a = queue.shift(), project = _a.project, location = _a.location;
175155
+ if (isLocationProjectReferenceRedirect(project, location))
175156
+ continue;
175157
+ if (!ts.tryAddToSet(searchedProjects, getProjectKey(project)))
175158
+ continue;
175159
+ var projectResults = searchPosition(project, location);
175160
+ if (projectResults) {
175161
+ resultsMap.set(project, projectResults);
175162
+ }
175163
+ }
175164
+ // At this point, we know about all projects passed in as arguments and any projects in which
175165
+ // `getResultsForPosition` has returned results. We expand that set to include any projects
175166
+ // downstream from any of these and then queue new initial-position searches for any new project
175167
+ // containing `initialLocation`.
175168
+ if (defaultDefinition) {
175169
+ // This seems to mean "load all projects downstream from any member of `seenProjects`".
175170
+ projectService.loadAncestorProjectTree(searchedProjects);
175028
175171
  projectService.forEachEnabledProject(function (project) {
175029
- if (!addToSeen(seenProjects, project))
175030
- return;
175031
- var definition = mapDefinitionInProject(defaultDefinition_1, project, getGeneratedDefinition_1, getSourceDefinition_1);
175032
- if (definition) {
175033
- toDo = callbackProjectAndLocation(project, definition, projectService, toDo, seenProjects, cb);
175172
+ if (cancellationToken.isCancellationRequested())
175173
+ return; // There's no mechanism for skipping the remaining projects
175174
+ if (searchedProjects.has(getProjectKey(project)))
175175
+ return; // Can loop forever without this (enqueue here, dequeue above, repeat)
175176
+ var location = mapDefinitionInProject(defaultDefinition, project, getGeneratedDefinition, getSourceDefinition);
175177
+ if (location) {
175178
+ queue.push({ project: project, location: location });
175034
175179
  }
175035
175180
  });
175036
175181
  }
175037
175182
  }
175038
- while (toDo && toDo.length) {
175039
- var next = toDo.pop();
175040
- ts.Debug.assertIsDefined(next);
175041
- toDo = callbackProjectAndLocation(next.project, next.location, projectService, toDo, seenProjects, cb);
175183
+ // In the common case where there's only one project, return a simpler result to make
175184
+ // it easier for the caller to skip post-processing.
175185
+ if (searchedProjects.size === 1) {
175186
+ var it = resultsMap.values().next();
175187
+ ts.Debug.assert(!it.done);
175188
+ return it.value;
175189
+ }
175190
+ return resultsMap;
175191
+ // May enqueue to otherPositionQueue
175192
+ function searchPosition(project, location) {
175193
+ var projectResults = getResultsForPosition(project, location);
175194
+ if (!projectResults)
175195
+ return undefined;
175196
+ for (var _i = 0, projectResults_4 = projectResults; _i < projectResults_4.length; _i++) {
175197
+ var result = projectResults_4[_i];
175198
+ forPositionInResult(result, function (position) {
175199
+ // This may trigger a search for a tsconfig, but there are several layers of caching that make it inexpensive
175200
+ var originalLocation = projectService.getOriginalLocationEnsuringConfiguredProject(project, position);
175201
+ if (!originalLocation)
175202
+ return;
175203
+ var originalScriptInfo = projectService.getScriptInfo(originalLocation.fileName);
175204
+ for (var _i = 0, _a = originalScriptInfo.containingProjects; _i < _a.length; _i++) {
175205
+ var project_1 = _a[_i];
175206
+ if (!project_1.isOrphan()) {
175207
+ queue.push({ project: project_1, location: originalLocation });
175208
+ }
175209
+ }
175210
+ var symlinkedProjectsMap = projectService.getSymlinkedProjects(originalScriptInfo);
175211
+ if (symlinkedProjectsMap) {
175212
+ symlinkedProjectsMap.forEach(function (symlinkedProjects, symlinkedPath) {
175213
+ for (var _i = 0, symlinkedProjects_2 = symlinkedProjects; _i < symlinkedProjects_2.length; _i++) {
175214
+ var symlinkedProject = symlinkedProjects_2[_i];
175215
+ if (!symlinkedProject.isOrphan()) {
175216
+ queue.push({ project: symlinkedProject, location: { fileName: symlinkedPath, pos: originalLocation.pos } });
175217
+ }
175218
+ }
175219
+ });
175220
+ }
175221
+ });
175222
+ }
175223
+ return projectResults;
175042
175224
  }
175043
175225
  }
175044
175226
  function mapDefinitionInProject(definition, project, getGeneratedDefinition, getSourceDefinition) {
@@ -175069,43 +175251,6 @@ var ts;
175069
175251
  sourceFile.resolvedPath !== sourceFile.path &&
175070
175252
  sourceFile.resolvedPath !== project.toPath(location.fileName);
175071
175253
  }
175072
- function callbackProjectAndLocation(project, location, projectService, toDo, seenProjects, cb) {
175073
- if (project.getCancellationToken().isCancellationRequested())
175074
- return undefined; // Skip rest of toDo if cancelled
175075
- // If this is not the file we were actually looking, return rest of the toDo
175076
- if (isLocationProjectReferenceRedirect(project, location))
175077
- return toDo;
175078
- cb(project, location, function (innerProject, location) {
175079
- addToSeen(seenProjects, project);
175080
- var originalLocation = projectService.getOriginalLocationEnsuringConfiguredProject(innerProject, location);
175081
- if (!originalLocation)
175082
- return undefined;
175083
- var originalScriptInfo = projectService.getScriptInfo(originalLocation.fileName);
175084
- toDo = toDo || [];
175085
- for (var _i = 0, _a = originalScriptInfo.containingProjects; _i < _a.length; _i++) {
175086
- var project_1 = _a[_i];
175087
- addToTodo(project_1, originalLocation, toDo, seenProjects);
175088
- }
175089
- var symlinkedProjectsMap = projectService.getSymlinkedProjects(originalScriptInfo);
175090
- if (symlinkedProjectsMap) {
175091
- symlinkedProjectsMap.forEach(function (symlinkedProjects, symlinkedPath) {
175092
- for (var _i = 0, symlinkedProjects_2 = symlinkedProjects; _i < symlinkedProjects_2.length; _i++) {
175093
- var symlinkedProject = symlinkedProjects_2[_i];
175094
- addToTodo(symlinkedProject, { fileName: symlinkedPath, pos: originalLocation.pos }, toDo, seenProjects);
175095
- }
175096
- });
175097
- }
175098
- return originalLocation === location ? undefined : originalLocation;
175099
- });
175100
- return toDo;
175101
- }
175102
- function addToTodo(project, location, toDo, seenProjects) {
175103
- if (!project.isOrphan() && addToSeen(seenProjects, project))
175104
- toDo.push({ project: project, location: location });
175105
- }
175106
- function addToSeen(seenProjects, project) {
175107
- return ts.tryAddToSet(seenProjects, getProjectKey(project));
175108
- }
175109
175254
  function getProjectKey(project) {
175110
175255
  return server.isConfiguredProject(project) ? project.canonicalConfigFilePath : project.getProjectName();
175111
175256
  }
@@ -175113,32 +175258,14 @@ var ts;
175113
175258
  var fileName = _a.fileName, textSpan = _a.textSpan;
175114
175259
  return { fileName: fileName, pos: textSpan.start };
175115
175260
  }
175116
- function getMappedLocation(location, project) {
175117
- var mapsTo = project.getSourceMapper().tryGetSourcePosition(location);
175118
- return mapsTo && project.projectService.fileExists(server.toNormalizedPath(mapsTo.fileName)) ? mapsTo : undefined;
175261
+ function getMappedLocationForProject(location, project) {
175262
+ return ts.getMappedLocation(location, project.getSourceMapper(), function (p) { return project.projectService.fileExists(p); });
175119
175263
  }
175120
- function getMappedDocumentSpan(documentSpan, project) {
175121
- var newPosition = getMappedLocation(documentSpanLocation(documentSpan), project);
175122
- if (!newPosition)
175123
- return undefined;
175124
- return {
175125
- fileName: newPosition.fileName,
175126
- textSpan: {
175127
- start: newPosition.pos,
175128
- length: documentSpan.textSpan.length
175129
- },
175130
- originalFileName: documentSpan.fileName,
175131
- originalTextSpan: documentSpan.textSpan,
175132
- contextSpan: getMappedContextSpan(documentSpan, project),
175133
- originalContextSpan: documentSpan.contextSpan
175134
- };
175264
+ function getMappedDocumentSpanForProject(documentSpan, project) {
175265
+ return ts.getMappedDocumentSpan(documentSpan, project.getSourceMapper(), function (p) { return project.projectService.fileExists(p); });
175135
175266
  }
175136
- function getMappedContextSpan(documentSpan, project) {
175137
- var contextSpanStart = documentSpan.contextSpan && getMappedLocation({ fileName: documentSpan.fileName, pos: documentSpan.contextSpan.start }, project);
175138
- var contextSpanEnd = documentSpan.contextSpan && getMappedLocation({ fileName: documentSpan.fileName, pos: documentSpan.contextSpan.start + documentSpan.contextSpan.length }, project);
175139
- return contextSpanStart && contextSpanEnd ?
175140
- { start: contextSpanStart.pos, length: contextSpanEnd.pos - contextSpanStart.pos } :
175141
- undefined;
175267
+ function getMappedContextSpanForProject(documentSpan, project) {
175268
+ return ts.getMappedContextSpan(documentSpan, project.getSourceMapper(), function (p) { return project.projectService.fileExists(p); });
175142
175269
  }
175143
175270
  var invalidPartialSemanticModeCommands = [
175144
175271
  server.CommandNames.OpenExternalProject,
@@ -176031,7 +176158,7 @@ var ts;
176031
176158
  };
176032
176159
  Session.prototype.mapDefinitionInfoLocations = function (definitions, project) {
176033
176160
  return definitions.map(function (info) {
176034
- var newDocumentSpan = getMappedDocumentSpan(info, project);
176161
+ var newDocumentSpan = getMappedDocumentSpanForProject(info, project);
176035
176162
  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 });
176036
176163
  });
176037
176164
  };
@@ -176276,7 +176403,7 @@ var ts;
176276
176403
  };
176277
176404
  Session.prototype.mapImplementationLocations = function (implementations, project) {
176278
176405
  return implementations.map(function (info) {
176279
- var newDocumentSpan = getMappedDocumentSpan(info, project);
176406
+ var newDocumentSpan = getMappedDocumentSpanForProject(info, project);
176280
176407
  return !newDocumentSpan ? info : __assign(__assign({}, newDocumentSpan), { kind: info.kind, displayParts: info.displayParts });
176281
176408
  });
176282
176409
  };
@@ -176433,7 +176560,7 @@ var ts;
176433
176560
  var renameInfo = this.mapRenameInfo(defaultProject.getLanguageService().getRenameInfo(file, position, { allowRenameOfImportPath: this.getPreferences(file).allowRenameOfImportPath }), ts.Debug.checkDefined(this.projectService.getScriptInfo(file)));
176434
176561
  if (!renameInfo.canRename)
176435
176562
  return simplifiedResult ? { info: renameInfo, locs: [] } : [];
176436
- var locations = combineProjectOutputForRenameLocations(projects, defaultProject, { fileName: args.file, pos: position }, !!args.findInStrings, !!args.findInComments, this.getPreferences(file));
176563
+ var locations = getRenameLocationsWorker(projects, defaultProject, { fileName: args.file, pos: position }, !!args.findInStrings, !!args.findInComments, this.getPreferences(file));
176437
176564
  if (!simplifiedResult)
176438
176565
  return locations;
176439
176566
  return { info: renameInfo, locs: this.toSpanGroups(locations) };
@@ -176465,7 +176592,7 @@ var ts;
176465
176592
  var file = server.toNormalizedPath(args.file);
176466
176593
  var projects = this.getProjects(args);
176467
176594
  var position = this.getPositionInFile(args, file);
176468
- var references = combineProjectOutputForReferences(projects, this.getDefaultProject(args), { fileName: args.file, pos: position }, this.logger);
176595
+ var references = getReferencesWorker(projects, this.getDefaultProject(args), { fileName: args.file, pos: position }, this.logger);
176469
176596
  if (!simplifiedResult)
176470
176597
  return references;
176471
176598
  var defaultProject = this.getDefaultProject(args);
@@ -176491,8 +176618,8 @@ var ts;
176491
176618
  return;
176492
176619
  var projectOutputs = project.getLanguageService().getFileReferences(fileName);
176493
176620
  if (projectOutputs) {
176494
- for (var _i = 0, projectOutputs_3 = projectOutputs; _i < projectOutputs_3.length; _i++) {
176495
- var referenceEntry = projectOutputs_3[_i];
176621
+ for (var _i = 0, projectOutputs_1 = projectOutputs; _i < projectOutputs_1.length; _i++) {
176622
+ var referenceEntry = projectOutputs_1[_i];
176496
176623
  if (!seen.has(referenceEntry)) {
176497
176624
  references.push(referenceEntry);
176498
176625
  seen.add(referenceEntry);
@@ -176957,7 +177084,8 @@ var ts;
176957
177084
  // `name` is a very cheap hash function, but we could incorporate other properties to reduce collisions.
176958
177085
  var seenItems = new ts.Map(); // name to items with that name
176959
177086
  if (!args.file && !projectFileName) {
176960
- // VS Code's `Go to symbol in workspaces` sends request like this
177087
+ // VS Code's `Go to symbol in workspaces` sends request like this by default.
177088
+ // There's a setting to have it send a file name (reverting to older behavior).
176961
177089
  // TODO (https://github.com/microsoft/TypeScript/issues/47839)
176962
177090
  // This appears to have been intended to search all projects but, in practice, it seems to only search
176963
177091
  // those that are downstream from already-loaded projects.
@@ -176978,7 +177106,7 @@ var ts;
176978
177106
  // Mutates `outputs`
176979
177107
  function addItemsForProject(project) {
176980
177108
  var projectItems = project.getLanguageService().getNavigateToItems(searchValue, maxResultCount, /*filename*/ undefined, /*excludeDts*/ project.isNonTsProject());
176981
- var unseenItems = ts.filter(projectItems, function (item) { return tryAddSeenItem(item) && !getMappedLocation(documentSpanLocation(item), project); });
177109
+ var unseenItems = ts.filter(projectItems, function (item) { return tryAddSeenItem(item) && !getMappedLocationForProject(documentSpanLocation(item), project); });
176982
177110
  if (unseenItems.length) {
176983
177111
  outputs.push({ project: project, navigateToItems: unseenItems });
176984
177112
  }