mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-22 22:55:36 -05:00
Resolve only relative references in open files on syntax server (#39476)
* Resolve only relative references in open files on syntax server * Support resolving tripleslash references only in the open file * Apply suggestions from code review Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com> Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
This commit is contained in:
@@ -807,6 +807,8 @@ namespace ts {
|
||||
let mapFromFileToProjectReferenceRedirects: ESMap<Path, Path> | undefined;
|
||||
let mapFromToProjectReferenceRedirectSource: ESMap<Path, SourceOfProjectReferenceRedirect> | undefined;
|
||||
|
||||
let skippedTrippleSlashReferences: Set<Path> | undefined;
|
||||
|
||||
const useSourceOfProjectReferenceRedirect = !!host.useSourceOfProjectReferenceRedirect?.() &&
|
||||
!options.disableSourceOfProjectReferenceRedirect;
|
||||
const { onProgramCreateComplete, fileExists } = updateHostForUseSourceOfProjectReferenceRedirect({
|
||||
@@ -928,6 +930,7 @@ namespace ts {
|
||||
getSourceFiles: () => files,
|
||||
getMissingFilePaths: () => missingFilePaths!, // TODO: GH#18217
|
||||
getRefFileMap: () => refFileMap,
|
||||
getSkippedTrippleSlashReferences: () => skippedTrippleSlashReferences,
|
||||
getFilesByNameMap: () => filesByName,
|
||||
getCompilerOptions: () => options,
|
||||
getSyntacticDiagnostics,
|
||||
@@ -1269,6 +1272,7 @@ namespace ts {
|
||||
const oldSourceFiles = oldProgram.getSourceFiles();
|
||||
const enum SeenPackageName { Exists, Modified }
|
||||
const seenPackageNames = new Map<string, SeenPackageName>();
|
||||
const oldSkippedTrippleSlashReferences = oldProgram.getSkippedTrippleSlashReferences();
|
||||
|
||||
for (const oldSourceFile of oldSourceFiles) {
|
||||
let newSourceFile = host.getSourceFileByPath
|
||||
@@ -1341,6 +1345,11 @@ namespace ts {
|
||||
oldProgram.structureIsReused = StructureIsReused.SafeModules;
|
||||
}
|
||||
|
||||
if (oldSkippedTrippleSlashReferences?.has(oldSourceFile.path) && includeTripleslashReferencesFrom(newSourceFile)) {
|
||||
// tripleslash reference resolution is now allowed
|
||||
oldProgram.structureIsReused = StructureIsReused.SafeModules;
|
||||
}
|
||||
|
||||
// check imports and module augmentations
|
||||
collectExternalModuleReferences(newSourceFile);
|
||||
if (!arrayIsEqualTo(oldSourceFile.imports, newSourceFile.imports, moduleNameIsEqualTo)) {
|
||||
@@ -1428,6 +1437,7 @@ namespace ts {
|
||||
|
||||
missingFilePaths = oldProgram.getMissingFilePaths();
|
||||
refFileMap = oldProgram.getRefFileMap();
|
||||
skippedTrippleSlashReferences = oldSkippedTrippleSlashReferences;
|
||||
|
||||
// update fileName -> file mapping
|
||||
Debug.assert(newSourceFiles.length === oldProgram.getSourceFiles().length);
|
||||
@@ -2647,7 +2657,15 @@ namespace ts {
|
||||
return projectReferenceRedirects.get(projectReferencePath) || undefined;
|
||||
}
|
||||
|
||||
function includeTripleslashReferencesFrom(file: SourceFile) {
|
||||
return !host.includeTripleslashReferencesFrom || host.includeTripleslashReferencesFrom(file.originalFileName);
|
||||
}
|
||||
|
||||
function processReferencedFiles(file: SourceFile, isDefaultLib: boolean) {
|
||||
if (!includeTripleslashReferencesFrom(file)) {
|
||||
(skippedTrippleSlashReferences ||= new Set()).add(file.path);
|
||||
return;
|
||||
}
|
||||
forEach(file.referencedFiles, (ref, index) => {
|
||||
const referencedFileName = resolveTripleslashReference(ref.fileName, file.originalFileName);
|
||||
processSourceFile(
|
||||
|
||||
Reference in New Issue
Block a user