Skip to content

Commit 8f442ba

Browse files
committed
Revert to including only open files in partial semantic server mode
1 parent 620e260 commit 8f442ba

File tree

9 files changed

+13
-169
lines changed

9 files changed

+13
-169
lines changed

src/compiler/program.ts

-18
Original file line numberDiff line numberDiff line change
@@ -807,8 +807,6 @@ namespace ts {
807807
let mapFromFileToProjectReferenceRedirects: ESMap<Path, Path> | undefined;
808808
let mapFromToProjectReferenceRedirectSource: ESMap<Path, SourceOfProjectReferenceRedirect> | undefined;
809809

810-
let skippedTrippleSlashReferences: Set<Path> | undefined;
811-
812810
const useSourceOfProjectReferenceRedirect = !!host.useSourceOfProjectReferenceRedirect?.() &&
813811
!options.disableSourceOfProjectReferenceRedirect;
814812
const { onProgramCreateComplete, fileExists, directoryExists } = updateHostForUseSourceOfProjectReferenceRedirect({
@@ -931,7 +929,6 @@ namespace ts {
931929
getSourceFiles: () => files,
932930
getMissingFilePaths: () => missingFilePaths!, // TODO: GH#18217
933931
getRefFileMap: () => refFileMap,
934-
getSkippedTrippleSlashReferences: () => skippedTrippleSlashReferences,
935932
getFilesByNameMap: () => filesByName,
936933
getCompilerOptions: () => options,
937934
getSyntacticDiagnostics,
@@ -1275,7 +1272,6 @@ namespace ts {
12751272
const oldSourceFiles = oldProgram.getSourceFiles();
12761273
const enum SeenPackageName { Exists, Modified }
12771274
const seenPackageNames = new Map<string, SeenPackageName>();
1278-
const oldSkippedTrippleSlashReferences = oldProgram.getSkippedTrippleSlashReferences();
12791275

12801276
for (const oldSourceFile of oldSourceFiles) {
12811277
let newSourceFile = host.getSourceFileByPath
@@ -1348,11 +1344,6 @@ namespace ts {
13481344
oldProgram.structureIsReused = StructureIsReused.SafeModules;
13491345
}
13501346

1351-
if (oldSkippedTrippleSlashReferences?.has(oldSourceFile.path) && includeTripleslashReferencesFrom(newSourceFile)) {
1352-
// tripleslash reference resolution is now allowed
1353-
oldProgram.structureIsReused = StructureIsReused.SafeModules;
1354-
}
1355-
13561347
// check imports and module augmentations
13571348
collectExternalModuleReferences(newSourceFile);
13581349
if (!arrayIsEqualTo(oldSourceFile.imports, newSourceFile.imports, moduleNameIsEqualTo)) {
@@ -1440,7 +1431,6 @@ namespace ts {
14401431

14411432
missingFilePaths = oldProgram.getMissingFilePaths();
14421433
refFileMap = oldProgram.getRefFileMap();
1443-
skippedTrippleSlashReferences = oldSkippedTrippleSlashReferences;
14441434

14451435
// update fileName -> file mapping
14461436
Debug.assert(newSourceFiles.length === oldProgram.getSourceFiles().length);
@@ -2660,15 +2650,7 @@ namespace ts {
26602650
return projectReferenceRedirects.get(projectReferencePath) || undefined;
26612651
}
26622652

2663-
function includeTripleslashReferencesFrom(file: SourceFile) {
2664-
return !host.includeTripleslashReferencesFrom || host.includeTripleslashReferencesFrom(file.originalFileName);
2665-
}
2666-
26672653
function processReferencedFiles(file: SourceFile, isDefaultLib: boolean) {
2668-
if (!includeTripleslashReferencesFrom(file)) {
2669-
(skippedTrippleSlashReferences ||= new Set()).add(file.path);
2670-
return;
2671-
}
26722654
forEach(file.referencedFiles, (ref, index) => {
26732655
const referencedFileName = resolveTripleslashReference(ref.fileName, file.fileName);
26742656
processSourceFile(

src/compiler/resolutionCache.ts

+3-50
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ namespace ts {
1111

1212
invalidateResolutionsOfFailedLookupLocations(): boolean;
1313
invalidateResolutionOfFile(filePath: Path): void;
14-
removeRelativeNoResolveResolutionsOfFile(filePath: Path): boolean;
1514
removeResolutionsOfFile(filePath: Path): void;
1615
removeResolutionsFromProjectReferenceRedirects(filePath: Path): void;
1716
setFilesWithInvalidatedNonRelativeUnresolvedImports(filesWithUnresolvedImports: ESMap<Path, readonly string[]>): void;
@@ -142,21 +141,7 @@ namespace ts {
142141
type GetResolutionWithResolvedFileName<T extends ResolutionWithFailedLookupLocations = ResolutionWithFailedLookupLocations, R extends ResolutionWithResolvedFileName = ResolutionWithResolvedFileName> =
143142
(resolution: T) => R | undefined;
144143

145-
export enum ResolutionKind {
146-
All,
147-
RelativeReferencesInOpenFileOnly
148-
}
149-
150-
const noResolveResolvedModule: ResolvedModuleWithFailedLookupLocations = {
151-
resolvedModule: undefined,
152-
failedLookupLocations: []
153-
};
154-
const noResolveResolvedTypeReferenceDirective: ResolvedTypeReferenceDirectiveWithFailedLookupLocations = {
155-
resolvedTypeReferenceDirective: undefined,
156-
failedLookupLocations: []
157-
};
158-
159-
export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootDirForResolution: string | undefined, resolutionKind: ResolutionKind, logChangesWhenResolvingModule: boolean): ResolutionCache {
144+
export function createResolutionCache(resolutionHost: ResolutionCacheHost, rootDirForResolution: string | undefined, logChangesWhenResolvingModule: boolean): ResolutionCache {
160145
let filesWithChangedSetOfUnresolvedImports: Path[] | undefined;
161146
let filesWithInvalidatedResolutions: Set<Path> | undefined;
162147
let filesWithInvalidatedNonRelativeUnresolvedImports: ReadonlyESMap<Path, readonly string[]> | undefined;
@@ -221,7 +206,6 @@ namespace ts {
221206
hasChangedAutomaticTypeDirectiveNames: () => hasChangedAutomaticTypeDirectiveNames,
222207
invalidateResolutionOfFile,
223208
invalidateResolutionsOfFailedLookupLocations,
224-
removeRelativeNoResolveResolutionsOfFile,
225209
setFilesWithInvalidatedNonRelativeUnresolvedImports,
226210
createHasInvalidatedResolution,
227211
updateTypeRootsWatch,
@@ -357,12 +341,11 @@ namespace ts {
357341
shouldRetryResolution: (t: T) => boolean;
358342
reusedNames?: readonly string[];
359343
logChanges?: boolean;
360-
noResolveResolution: T;
361344
}
362345
function resolveNamesWithLocalCache<T extends ResolutionWithFailedLookupLocations, R extends ResolutionWithResolvedFileName>({
363346
names, containingFile, redirectedReference,
364347
cache, perDirectoryCacheWithRedirects,
365-
loader, getResolutionWithResolvedFileName, noResolveResolution,
348+
loader, getResolutionWithResolvedFileName,
366349
shouldRetryResolution, reusedNames, logChanges
367350
}: ResolveNamesWithLocalCacheInput<T, R>): (R | undefined)[] {
368351
const path = resolutionHost.toPath(containingFile);
@@ -399,10 +382,7 @@ namespace ts {
399382
resolution = resolutionInDirectory;
400383
}
401384
else {
402-
resolution = resolutionKind === ResolutionKind.All ||
403-
(isExternalModuleNameRelative(name) && resolutionHost.fileIsOpen(path)) ?
404-
loader(name, containingFile, compilerOptions, resolutionHost.getCompilerHost?.() || resolutionHost, redirectedReference) :
405-
noResolveResolution;
385+
resolution = loader(name, containingFile, compilerOptions, resolutionHost.getCompilerHost?.() || resolutionHost, redirectedReference);
406386
perDirectoryResolution.set(name, resolution);
407387
}
408388
resolutionsInFile.set(name, resolution);
@@ -461,7 +441,6 @@ namespace ts {
461441
loader: resolveTypeReferenceDirective,
462442
getResolutionWithResolvedFileName: getResolvedTypeReferenceDirective,
463443
shouldRetryResolution: resolution => resolution.resolvedTypeReferenceDirective === undefined,
464-
noResolveResolution: noResolveResolvedTypeReferenceDirective,
465444
});
466445
}
467446

@@ -477,7 +456,6 @@ namespace ts {
477456
shouldRetryResolution: resolution => !resolution.resolvedModule || !resolutionExtensionIsTSOrJson(resolution.resolvedModule.extension),
478457
reusedNames,
479458
logChanges: logChangesWhenResolvingModule,
480-
noResolveResolution: noResolveResolvedModule,
481459
});
482460
}
483461

@@ -763,31 +741,6 @@ namespace ts {
763741
}
764742
}
765743

766-
function removeRelativeNoResolveResolutionsOfFileFromCache<T extends ResolutionWithFailedLookupLocations>(
767-
cache: ESMap<Path, ESMap<string, T>>,
768-
filePath: Path,
769-
noResolveResolution: T,
770-
) {
771-
Debug.assert(resolutionKind === ResolutionKind.RelativeReferencesInOpenFileOnly);
772-
// Deleted file, stop watching failed lookups for all the resolutions in the file
773-
const resolutions = cache.get(filePath);
774-
if (!resolutions) return false;
775-
let invalidated = false;
776-
resolutions.forEach((resolution, name) => {
777-
if (resolution === noResolveResolution && isExternalModuleNameRelative(name)) {
778-
resolutions.delete(name);
779-
invalidated = true;
780-
}
781-
});
782-
return invalidated;
783-
}
784-
785-
function removeRelativeNoResolveResolutionsOfFile(filePath: Path) {
786-
let invalidated = removeRelativeNoResolveResolutionsOfFileFromCache(resolvedModuleNames, filePath, noResolveResolvedModule);
787-
invalidated = removeRelativeNoResolveResolutionsOfFileFromCache(resolvedTypeReferenceDirectives, filePath, noResolveResolvedTypeReferenceDirective) || invalidated;
788-
return invalidated;
789-
}
790-
791744
function setFilesWithInvalidatedNonRelativeUnresolvedImports(filesMap: ReadonlyESMap<Path, readonly string[]>) {
792745
Debug.assert(filesWithInvalidatedNonRelativeUnresolvedImports === filesMap || filesWithInvalidatedNonRelativeUnresolvedImports === undefined);
793746
filesWithInvalidatedNonRelativeUnresolvedImports = filesMap;

src/compiler/types.ts

-3
Original file line numberDiff line numberDiff line change
@@ -3687,8 +3687,6 @@ namespace ts {
36873687
/* @internal */
36883688
getRefFileMap(): MultiMap<Path, RefFile> | undefined;
36893689
/* @internal */
3690-
getSkippedTrippleSlashReferences(): Set<Path> | undefined;
3691-
/* @internal */
36923690
getFilesByNameMap(): ESMap<string, SourceFile | false | undefined>;
36933691

36943692
/**
@@ -6232,7 +6230,6 @@ namespace ts {
62326230
* This method is a companion for 'resolveModuleNames' and is used to resolve 'types' references to actual type declaration files
62336231
*/
62346232
resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedTypeReferenceDirective | undefined)[];
6235-
/* @internal */ includeTripleslashReferencesFrom?(containingFile: string): boolean;
62366233
getEnvironmentVariable?(name: string): string | undefined;
62376234
/* @internal */ onReleaseOldSourceFile?(oldSourceFile: SourceFile, oldOptions: CompilerOptions, hasSourceFileByPath: boolean): void;
62386235
/* @internal */ hasInvalidatedResolution?: HasInvalidatedResolution;

src/compiler/watchPublic.ts

-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ namespace ts {
320320
configFileName ?
321321
getDirectoryPath(getNormalizedAbsolutePath(configFileName, currentDirectory)) :
322322
currentDirectory,
323-
ResolutionKind.All,
324323
/*logChangesWhenResolvingModule*/ false
325324
);
326325
// Resolve module using host module resolution strategy if provided otherwise use resolution cache to resolve module names

src/server/editorServices.ts

+1-13
Original file line numberDiff line numberDiff line change
@@ -3029,15 +3029,7 @@ namespace ts.server {
30293029
let retainProjects: ConfiguredProject[] | ConfiguredProject | undefined;
30303030
let projectForConfigFileDiag: ConfiguredProject | undefined;
30313031
let defaultConfigProjectIsCreated = false;
3032-
if (this.serverMode === LanguageServiceMode.PartialSemantic) {
3033-
// Invalidate resolutions in the file since this file is now open
3034-
info.containingProjects.forEach(project => {
3035-
if (project.resolutionCache.removeRelativeNoResolveResolutionsOfFile(info.path)) {
3036-
project.markAsDirty();
3037-
}
3038-
});
3039-
}
3040-
else if (!project && this.serverMode === LanguageServiceMode.Semantic) { // Checking semantic mode is an optimization
3032+
if (!project && this.serverMode === LanguageServiceMode.Semantic) { // Checking semantic mode is an optimization
30413033
configFileName = this.getConfigFileNameForFile(info);
30423034
if (configFileName) {
30433035
project = this.findConfiguredProjectByProjectName(configFileName);
@@ -3124,10 +3116,6 @@ namespace ts.server {
31243116
Debug.assert(this.openFiles.has(info.path));
31253117
this.assignOrphanScriptInfoToInferredProject(info, this.openFiles.get(info.path));
31263118
}
3127-
else if (this.serverMode === LanguageServiceMode.PartialSemantic && info.cacheSourceFile?.sourceFile.referencedFiles.length) {
3128-
// This file was just opened and references in this file will previously not been resolved so schedule update
3129-
info.containingProjects.forEach(project => project.markAsDirty());
3130-
}
31313119
Debug.assert(!info.isOrphan());
31323120
return { configFileName, configFileErrors, retainProjects };
31333121
}

src/server/project.ts

+1-15
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ namespace ts.server {
285285
break;
286286
case LanguageServiceMode.PartialSemantic:
287287
this.languageServiceEnabled = true;
288+
this.compilerOptions.noResolve = true;
288289
this.compilerOptions.types = [];
289290
break;
290291
case LanguageServiceMode.Syntactic:
@@ -310,7 +311,6 @@ namespace ts.server {
310311
this.resolutionCache = createResolutionCache(
311312
this,
312313
currentDirectory && this.currentDirectory,
313-
projectService.serverMode === LanguageServiceMode.Semantic ? ResolutionKind.All : ResolutionKind.RelativeReferencesInOpenFileOnly,
314314
/*logChangesWhenResolvingModule*/ true
315315
);
316316
this.languageService = createLanguageService(this, this.documentRegistry, this.projectService.serverMode);
@@ -466,20 +466,6 @@ namespace ts.server {
466466
return this.resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference);
467467
}
468468

469-
/*@internal*/
470-
includeTripleslashReferencesFrom(containingFile: string) {
471-
switch (this.projectService.serverMode) {
472-
case LanguageServiceMode.Semantic:
473-
return true;
474-
case LanguageServiceMode.PartialSemantic:
475-
return this.fileIsOpen(this.toPath(containingFile));
476-
case LanguageServiceMode.Syntactic:
477-
return false;
478-
default:
479-
Debug.assertNever(this.projectService.serverMode);
480-
}
481-
}
482-
483469
directoryExists(path: string): boolean {
484470
return this.directoryStructureHost.directoryExists!(path); // TODO: GH#18217
485471
}

src/services/services.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,6 @@ namespace ts {
13441344
onReleaseOldSourceFile,
13451345
hasInvalidatedResolution,
13461346
hasChangedAutomaticTypeDirectiveNames,
1347-
includeTripleslashReferencesFrom: maybeBind(host, host.includeTripleslashReferencesFrom),
13481347
trace: maybeBind(host, host.trace),
13491348
resolveModuleNames: maybeBind(host, host.resolveModuleNames),
13501349
resolveTypeReferenceDirectives: maybeBind(host, host.resolveTypeReferenceDirectives),

src/services/types.ts

-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ namespace ts {
272272
resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames: string[] | undefined, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedModule | undefined)[];
273273
getResolvedModuleWithFailedLookupLocationsFromCache?(modulename: string, containingFile: string): ResolvedModuleWithFailedLookupLocations | undefined;
274274
resolveTypeReferenceDirectives?(typeDirectiveNames: string[], containingFile: string, redirectedReference: ResolvedProjectReference | undefined, options: CompilerOptions): (ResolvedTypeReferenceDirective | undefined)[];
275-
/* @internal */ includeTripleslashReferencesFrom?(containingFile: string): boolean;
276275
/* @internal */ hasInvalidatedResolution?: HasInvalidatedResolution;
277276
/* @internal */ hasChangedAutomaticTypeDirectiveNames?: HasChangedAutomaticTypeDirectiveNames;
278277
/* @internal */

0 commit comments

Comments
 (0)