Skip to content

Commit 38f3a2b

Browse files
committed
Renamed PartialSystem as DirectoryStructureHost and CachedPartialSystem as CachedDirectoryStructureHost
1 parent 14febe2 commit 38f3a2b

File tree

7 files changed

+60
-66
lines changed

7 files changed

+60
-66
lines changed

src/compiler/core.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2668,21 +2668,18 @@ namespace ts {
26682668

26692669
export function assertTypeIsNever(_: never): void { }
26702670

2671-
export interface CachedHost {
2671+
export interface CachedDirectoryStructureHost extends DirectoryStructureHost {
26722672
addOrDeleteFileOrFolder(fileOrFolder: string, fileOrFolderPath: Path): void;
26732673
addOrDeleteFile(fileName: string, filePath: Path, eventKind: FileWatcherEventKind): void;
26742674
clearCache(): void;
26752675
}
26762676

2677-
export interface CachedPartialSystem extends PartialSystem, CachedHost {
2678-
}
2679-
26802677
interface MutableFileSystemEntries {
26812678
readonly files: string[];
26822679
readonly directories: string[];
26832680
}
26842681

2685-
export function createCachedPartialSystem(host: PartialSystem): CachedPartialSystem {
2682+
export function createCachedDirectoryStructureHost(host: DirectoryStructureHost): CachedDirectoryStructureHost {
26862683
const cachedReadDirectoryResult = createMap<MutableFileSystemEntries>();
26872684
const getCurrentDirectory = memoize(() => host.getCurrentDirectory());
26882685
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames);

src/compiler/resolutionCache.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace ts {
4242
onInvalidatedResolution(): void;
4343
watchTypeRootsDirectory(directory: string, cb: DirectoryWatcherCallback, flags: WatchDirectoryFlags): FileWatcher;
4444
onChangedAutomaticTypeDirectiveNames(): void;
45-
getCachedPartialSystem?(): CachedPartialSystem;
45+
getCachedDirectoryStructureHost?(): CachedDirectoryStructureHost;
4646
projectName?: string;
4747
getGlobalCache?(): string | undefined;
4848
writeLog(s: string): void;
@@ -396,9 +396,9 @@ namespace ts {
396396
function createDirectoryWatcher(directory: string, dirPath: Path) {
397397
return resolutionHost.watchDirectoryOfFailedLookupLocation(directory, fileOrFolder => {
398398
const fileOrFolderPath = resolutionHost.toPath(fileOrFolder);
399-
if (resolutionHost.getCachedPartialSystem) {
399+
if (resolutionHost.getCachedDirectoryStructureHost) {
400400
// Since the file existance changed, update the sourceFiles cache
401-
resolutionHost.getCachedPartialSystem().addOrDeleteFileOrFolder(fileOrFolder, fileOrFolderPath);
401+
resolutionHost.getCachedDirectoryStructureHost().addOrDeleteFileOrFolder(fileOrFolder, fileOrFolderPath);
402402
}
403403

404404
// If the files are added to project root or node_modules directory, always run through the invalidation process
@@ -515,9 +515,9 @@ namespace ts {
515515
// Create new watch and recursive info
516516
return resolutionHost.watchTypeRootsDirectory(typeRoot, fileOrFolder => {
517517
const fileOrFolderPath = resolutionHost.toPath(fileOrFolder);
518-
if (resolutionHost.getCachedPartialSystem) {
518+
if (resolutionHost.getCachedDirectoryStructureHost) {
519519
// Since the file existance changed, update the sourceFiles cache
520-
resolutionHost.getCachedPartialSystem().addOrDeleteFileOrFolder(fileOrFolder, fileOrFolderPath);
520+
resolutionHost.getCachedDirectoryStructureHost().addOrDeleteFileOrFolder(fileOrFolder, fileOrFolderPath);
521521
}
522522

523523
// For now just recompile

src/compiler/sys.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace ts {
3333
/**
3434
* Partial interface of the System thats needed to support the caching of directory structure
3535
*/
36-
export interface PartialSystem {
36+
export interface DirectoryStructureHost {
3737
newLine: string;
3838
useCaseSensitiveFileNames: boolean;
3939
write(s: string): void;
@@ -48,11 +48,8 @@ namespace ts {
4848
exit(exitCode?: number): void;
4949
}
5050

51-
export interface System extends PartialSystem {
51+
export interface System extends DirectoryStructureHost {
5252
args: string[];
53-
newLine: string;
54-
useCaseSensitiveFileNames: boolean;
55-
write(s: string): void;
5653
getFileSize?(path: string): number;
5754
/**
5855
* @pollingInterval - this parameter is used in polling-based watchers and ignored in watchers that

src/compiler/watch.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace ts {
66
export type DiagnosticReporter = (diagnostic: Diagnostic) => void;
7-
export type ParseConfigFile = (configFileName: string, optionsToExtend: CompilerOptions, system: PartialSystem, reportDiagnostic: DiagnosticReporter, reportWatchDiagnostic: DiagnosticReporter) => ParsedCommandLine;
7+
export type ParseConfigFile = (configFileName: string, optionsToExtend: CompilerOptions, system: DirectoryStructureHost, reportDiagnostic: DiagnosticReporter, reportWatchDiagnostic: DiagnosticReporter) => ParsedCommandLine;
88
export interface WatchingSystemHost {
99
// FS system to use
1010
system: System;
@@ -18,7 +18,7 @@ namespace ts {
1818

1919
// Callbacks to do custom action before creating program and after creating program
2020
beforeCompile(compilerOptions: CompilerOptions): void;
21-
afterCompile(host: PartialSystem, program: Program, builder: Builder): void;
21+
afterCompile(host: DirectoryStructureHost, program: Program, builder: Builder): void;
2222
}
2323

2424
const defaultFormatDiagnosticsHost: FormatDiagnosticsHost = sys ? {
@@ -61,7 +61,7 @@ namespace ts {
6161
system.write(ts.formatDiagnosticsWithColorAndContext([diagnostic], host) + host.getNewLine());
6262
}
6363

64-
export function parseConfigFile(configFileName: string, optionsToExtend: CompilerOptions, system: PartialSystem, reportDiagnostic: DiagnosticReporter, reportWatchDiagnostic: DiagnosticReporter): ParsedCommandLine {
64+
export function parseConfigFile(configFileName: string, optionsToExtend: CompilerOptions, system: DirectoryStructureHost, reportDiagnostic: DiagnosticReporter, reportWatchDiagnostic: DiagnosticReporter): ParsedCommandLine {
6565
let configFileText: string;
6666
try {
6767
configFileText = system.readFile(configFileName);
@@ -89,7 +89,7 @@ namespace ts {
8989
return configParseResult;
9090
}
9191

92-
function reportEmittedFiles(files: string[], system: PartialSystem): void {
92+
function reportEmittedFiles(files: string[], system: DirectoryStructureHost): void {
9393
if (!files || files.length === 0) {
9494
return;
9595
}
@@ -100,7 +100,7 @@ namespace ts {
100100
}
101101
}
102102

103-
export function handleEmitOutputAndReportErrors(system: PartialSystem, program: Program,
103+
export function handleEmitOutputAndReportErrors(system: DirectoryStructureHost, program: Program,
104104
emittedFiles: string[], emitSkipped: boolean,
105105
diagnostics: Diagnostic[], reportDiagnostic: DiagnosticReporter
106106
): ExitStatus {
@@ -141,7 +141,7 @@ namespace ts {
141141
afterCompile: compileWatchedProgram,
142142
};
143143

144-
function compileWatchedProgram(host: PartialSystem, program: Program, builder: Builder) {
144+
function compileWatchedProgram(host: DirectoryStructureHost, program: Program, builder: Builder) {
145145
// First get and report any syntactic errors.
146146
let diagnostics = program.getSyntacticDiagnostics().slice();
147147
let reportSemanticDiagnostics = false;
@@ -256,14 +256,14 @@ namespace ts {
256256
watchingHost = watchingHost || createWatchingSystemHost(compilerOptions.pretty);
257257
const { system, parseConfigFile, reportDiagnostic, reportWatchDiagnostic, beforeCompile, afterCompile } = watchingHost;
258258

259-
const partialSystem = configFileName ? createCachedPartialSystem(system) : system;
259+
const directoryStructureHost = configFileName ? createCachedDirectoryStructureHost(system) : system;
260260
if (configFileName) {
261261
watchFile(system, configFileName, scheduleProgramReload, writeLog);
262262
}
263263

264-
const getCurrentDirectory = memoize(() => partialSystem.getCurrentDirectory());
264+
const getCurrentDirectory = memoize(() => directoryStructureHost.getCurrentDirectory());
265265
const realpath = system.realpath && ((path: string) => system.realpath(path));
266-
const getCachedPartialSystem = configFileName && (() => partialSystem as CachedPartialSystem);
266+
const getCachedDirectoryStructureHost = configFileName && (() => directoryStructureHost as CachedDirectoryStructureHost);
267267
const getCanonicalFileName = createGetCanonicalFileName(system.useCaseSensitiveFileNames);
268268
let newLine = getNewLineCharacter(compilerOptions, system);
269269

@@ -294,7 +294,7 @@ namespace ts {
294294
getCompilationSettings: () => compilerOptions,
295295
watchDirectoryOfFailedLookupLocation: watchDirectory,
296296
watchTypeRootsDirectory: watchDirectory,
297-
getCachedPartialSystem,
297+
getCachedDirectoryStructureHost,
298298
onInvalidatedResolution: scheduleProgramUpdate,
299299
onChangedAutomaticTypeDirectiveNames,
300300
writeLog
@@ -361,7 +361,7 @@ namespace ts {
361361
missingFilePathsRequestedForRelease = undefined;
362362
}
363363

364-
afterCompile(partialSystem, program, builder);
364+
afterCompile(directoryStructureHost, program, builder);
365365
reportWatchDiagnostic(createCompilerDiagnostic(Diagnostics.Compilation_complete_Watching_for_file_changes));
366366
}
367367

@@ -376,11 +376,11 @@ namespace ts {
376376
return !isString(hostSourceFileInfo);
377377
}
378378

379-
return partialSystem.fileExists(fileName);
379+
return directoryStructureHost.fileExists(fileName);
380380
}
381381

382382
function directoryExists(directoryName: string) {
383-
return partialSystem.directoryExists(directoryName);
383+
return directoryStructureHost.directoryExists(directoryName);
384384
}
385385

386386
function readFile(fileName: string) {
@@ -392,7 +392,7 @@ namespace ts {
392392
}
393393

394394
function getDirectories(path: string) {
395-
return partialSystem.getDirectories(path);
395+
return directoryStructureHost.getDirectories(path);
396396
}
397397

398398
function resolveModuleNames(moduleNames: string[], containingFile: string, reusedNames?: string[]) {
@@ -541,7 +541,7 @@ namespace ts {
541541
writeLog(`Reloading config file: ${configFileName}`);
542542
needsReload = false;
543543

544-
const cachedHost = partialSystem as CachedPartialSystem;
544+
const cachedHost = directoryStructureHost as CachedDirectoryStructureHost;
545545
cachedHost.clearCache();
546546
const configParseResult = parseConfigFile(configFileName, optionsToExtendForConfigFile, cachedHost, reportDiagnostic, reportWatchDiagnostic);
547547
rootFileNames = configParseResult.fileNames;
@@ -586,7 +586,7 @@ namespace ts {
586586

587587
function updateCachedSystemWithFile(fileName: string, path: Path, eventKind: FileWatcherEventKind) {
588588
if (configFileName) {
589-
(partialSystem as CachedPartialSystem).addOrDeleteFile(fileName, path, eventKind);
589+
(directoryStructureHost as CachedDirectoryStructureHost).addOrDeleteFile(fileName, path, eventKind);
590590
}
591591
}
592592

@@ -639,7 +639,7 @@ namespace ts {
639639
const fileOrFolderPath = toPath(fileOrFolder);
640640

641641
// Since the file existance changed, update the sourceFiles cache
642-
(partialSystem as CachedPartialSystem).addOrDeleteFileOrFolder(fileOrFolder, fileOrFolderPath);
642+
(directoryStructureHost as CachedDirectoryStructureHost).addOrDeleteFileOrFolder(fileOrFolder, fileOrFolderPath);
643643
removeSourceFile(fileOrFolderPath);
644644

645645
// If the the added or created file or folder is not supported file name, ignore the file
@@ -651,7 +651,7 @@ namespace ts {
651651

652652
// Reload is pending, do the reload
653653
if (!needsReload) {
654-
const result = getFileNamesFromConfigSpecs(configFileSpecs, getDirectoryPath(configFileName), compilerOptions, partialSystem);
654+
const result = getFileNamesFromConfigSpecs(configFileSpecs, getDirectoryPath(configFileName), compilerOptions, directoryStructureHost);
655655
if (!configFileSpecs.filesSpecs && result.fileNames.length === 0) {
656656
reportDiagnostic(getErrorForNoInputFiles(configFileSpecs, configFileName));
657657
}

src/server/editorServices.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ namespace ts.server {
755755
directory,
756756
fileOrFolder => {
757757
const fileOrFolderPath = this.toPath(fileOrFolder);
758-
project.getCachedPartialSystem().addOrDeleteFileOrFolder(fileOrFolder, fileOrFolderPath);
758+
project.getCachedDirectoryStructureHost().addOrDeleteFileOrFolder(fileOrFolder, fileOrFolderPath);
759759
const configFilename = project.getConfigFilePath();
760760

761761
// If the the added or created file or folder is not supported file name, ignore the file
@@ -768,7 +768,7 @@ namespace ts.server {
768768
// Reload is pending, do the reload
769769
if (!project.pendingReload) {
770770
const configFileSpecs = project.configFileSpecs;
771-
const result = getFileNamesFromConfigSpecs(configFileSpecs, getDirectoryPath(configFilename), project.getCompilationSettings(), project.getCachedPartialSystem(), this.hostConfiguration.extraFileExtensions);
771+
const result = getFileNamesFromConfigSpecs(configFileSpecs, getDirectoryPath(configFilename), project.getCompilationSettings(), project.getCachedDirectoryStructureHost(), this.hostConfiguration.extraFileExtensions);
772772
project.updateErrorOnNoInputFiles(result.fileNames.length !== 0);
773773
this.updateNonInferredProjectFiles(project, result.fileNames, fileNamePropertyReader);
774774
this.delayUpdateProjectGraphAndInferredProjectsRefresh(project);
@@ -1292,7 +1292,7 @@ namespace ts.server {
12921292
return findProjectByName(projectFileName, this.externalProjects);
12931293
}
12941294

1295-
private convertConfigFileContentToProjectOptions(configFilename: string, cachedPartialSystem: CachedPartialSystem) {
1295+
private convertConfigFileContentToProjectOptions(configFilename: string, cachedDirectoryStructureHost: CachedDirectoryStructureHost) {
12961296
configFilename = normalizePath(configFilename);
12971297

12981298
const configFileContent = this.host.readFile(configFilename);
@@ -1304,7 +1304,7 @@ namespace ts.server {
13041304
const errors = result.parseDiagnostics;
13051305
const parsedCommandLine = parseJsonSourceFileConfigFileContent(
13061306
result,
1307-
cachedPartialSystem,
1307+
cachedDirectoryStructureHost,
13081308
getDirectoryPath(configFilename),
13091309
/*existingOptions*/ {},
13101310
configFilename,
@@ -1429,8 +1429,8 @@ namespace ts.server {
14291429
}
14301430

14311431
private createConfiguredProject(configFileName: NormalizedPath) {
1432-
const cachedPartialSystem = createCachedPartialSystem(this.host);
1433-
const { projectOptions, configFileErrors, configFileSpecs } = this.convertConfigFileContentToProjectOptions(configFileName, cachedPartialSystem);
1432+
const cachedDirectoryStructureHost = createCachedDirectoryStructureHost(this.host);
1433+
const { projectOptions, configFileErrors, configFileSpecs } = this.convertConfigFileContentToProjectOptions(configFileName, cachedDirectoryStructureHost);
14341434
this.logger.info(`Opened configuration file ${configFileName}`);
14351435
const languageServiceEnabled = !this.exceededTotalSizeLimitForNonTsFiles(configFileName, projectOptions.compilerOptions, projectOptions.files, fileNamePropertyReader);
14361436
const project = new ConfiguredProject(
@@ -1441,7 +1441,7 @@ namespace ts.server {
14411441
projectOptions.compilerOptions,
14421442
languageServiceEnabled,
14431443
projectOptions.compileOnSave === undefined ? false : projectOptions.compileOnSave,
1444-
cachedPartialSystem);
1444+
cachedDirectoryStructureHost);
14451445

14461446
project.configFileSpecs = configFileSpecs;
14471447
// TODO: We probably should also watch the configFiles that are extended
@@ -1488,7 +1488,7 @@ namespace ts.server {
14881488
else {
14891489
const scriptKind = propertyReader.getScriptKind(f);
14901490
const hasMixedContent = propertyReader.hasMixedContent(f, this.hostConfiguration.extraFileExtensions);
1491-
scriptInfo = this.getOrCreateScriptInfoNotOpenedByClientForNormalizedPath(normalizedPath, scriptKind, hasMixedContent, project.partialSystem);
1491+
scriptInfo = this.getOrCreateScriptInfoNotOpenedByClientForNormalizedPath(normalizedPath, scriptKind, hasMixedContent, project.directoryStructureHost);
14921492
path = scriptInfo.path;
14931493
// If this script info is not already a root add it
14941494
if (!project.isRoot(scriptInfo)) {
@@ -1539,7 +1539,7 @@ namespace ts.server {
15391539
/* @internal */
15401540
reloadConfiguredProject(project: ConfiguredProject) {
15411541
// At this point, there is no reason to not have configFile in the host
1542-
const host = project.getCachedPartialSystem();
1542+
const host = project.getCachedDirectoryStructureHost();
15431543

15441544
// Clear the cache since we are reloading the project from disk
15451545
host.clearCache();
@@ -1637,7 +1637,7 @@ namespace ts.server {
16371637
}
16381638

16391639
/*@internal*/
1640-
getOrCreateScriptInfoNotOpenedByClient(uncheckedFileName: string, hostToQueryFileExistsOn: PartialSystem) {
1640+
getOrCreateScriptInfoNotOpenedByClient(uncheckedFileName: string, hostToQueryFileExistsOn: DirectoryStructureHost) {
16411641
return this.getOrCreateScriptInfoNotOpenedByClientForNormalizedPath(
16421642
toNormalizedPath(uncheckedFileName), /*scriptKind*/ undefined,
16431643
/*hasMixedContent*/ undefined, hostToQueryFileExistsOn
@@ -1669,15 +1669,15 @@ namespace ts.server {
16691669
}
16701670
}
16711671

1672-
getOrCreateScriptInfoNotOpenedByClientForNormalizedPath(fileName: NormalizedPath, scriptKind?: ScriptKind, hasMixedContent?: boolean, hostToQueryFileExistsOn?: PartialSystem) {
1672+
getOrCreateScriptInfoNotOpenedByClientForNormalizedPath(fileName: NormalizedPath, scriptKind?: ScriptKind, hasMixedContent?: boolean, hostToQueryFileExistsOn?: DirectoryStructureHost) {
16731673
return this.getOrCreateScriptInfoForNormalizedPath(fileName, /*openedByClient*/ false, /*fileContent*/ undefined, scriptKind, hasMixedContent, hostToQueryFileExistsOn);
16741674
}
16751675

1676-
getOrCreateScriptInfoOpenedByClientForNormalizedPath(fileName: NormalizedPath, fileContent?: string, scriptKind?: ScriptKind, hasMixedContent?: boolean, hostToQueryFileExistsOn?: PartialSystem) {
1676+
getOrCreateScriptInfoOpenedByClientForNormalizedPath(fileName: NormalizedPath, fileContent?: string, scriptKind?: ScriptKind, hasMixedContent?: boolean, hostToQueryFileExistsOn?: DirectoryStructureHost) {
16771677
return this.getOrCreateScriptInfoForNormalizedPath(fileName, /*openedByClient*/ true, fileContent, scriptKind, hasMixedContent, hostToQueryFileExistsOn);
16781678
}
16791679

1680-
getOrCreateScriptInfoForNormalizedPath(fileName: NormalizedPath, openedByClient: boolean, fileContent?: string, scriptKind?: ScriptKind, hasMixedContent?: boolean, hostToQueryFileExistsOn?: PartialSystem) {
1680+
getOrCreateScriptInfoForNormalizedPath(fileName: NormalizedPath, openedByClient: boolean, fileContent?: string, scriptKind?: ScriptKind, hasMixedContent?: boolean, hostToQueryFileExistsOn?: DirectoryStructureHost) {
16811681
Debug.assert(fileContent === undefined || openedByClient, "ScriptInfo needs to be opened by client to be able to set its user defined content");
16821682
const path = normalizedPathToPath(fileName, this.currentDirectory, this.toCanonicalFileName);
16831683
let info = this.getScriptInfoForPath(path);

0 commit comments

Comments
 (0)