Skip to content

Commit 8db05c2

Browse files
committed
More work on PR feedback update
1 parent b071a86 commit 8db05c2

6 files changed

Lines changed: 43 additions & 38 deletions

File tree

src/compiler/commandLineParser.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,7 @@ namespace ts {
14821482
return error.code === Diagnostics.No_inputs_were_found_in_config_file_0_Specified_include_paths_were_1_and_exclude_paths_were_2.code;
14831483
}
14841484

1485+
/*@internal*/
14851486
export function getErrorForNoInputFiles({ includeSpecs, excludeSpecs }: ConfigFileSpecs, configFileName: string | undefined) {
14861487
return createCompilerDiagnostic(
14871488
Diagnostics.No_inputs_were_found_in_config_file_0_Specified_include_paths_were_1_and_exclude_paths_were_2,
@@ -1928,9 +1929,9 @@ namespace ts {
19281929
/**
19291930
* Expands an array of file specifications.
19301931
*
1931-
* @param fileNames The literal file names to include.
1932-
* @param include The wildcard file specifications to include.
1933-
* @param exclude The wildcard file specifications to exclude.
1932+
* @param filesSpecs The literal file names to include.
1933+
* @param includeSpecs The wildcard file specifications to include.
1934+
* @param excludeSpecs The wildcard file specifications to exclude.
19341935
* @param basePath The base path for any relative file specifications.
19351936
* @param options Compiler options.
19361937
* @param host The host used to resolve files and directories.

src/compiler/utilities.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3607,10 +3607,6 @@ namespace ts {
36073607
export function getCombinedLocalAndExportSymbolFlags(symbol: Symbol): SymbolFlags {
36083608
return symbol.exportSymbol ? symbol.exportSymbol.flags | symbol.flags : symbol.flags;
36093609
}
3610-
3611-
export function isRecursiveDirectoryWatch(flags: WatchDirectoryFlags) {
3612-
return (flags & WatchDirectoryFlags.Recursive) !== 0;
3613-
}
36143610
}
36153611

36163612
namespace ts {

src/harness/unittests/tsserverProjectSystem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ namespace ts.projectSystem {
534534
}
535535

536536
/**
537-
* This will call the directory watcher for the foldeFullPath and recursive directory watchers for this and base folders
537+
* This will call the directory watcher for the folderFullPath and recursive directory watchers for this and base folders
538538
*/
539539
private invokeDirectoryWatcher(folderFullPath: string, fileName: string) {
540540
const relativePath = this.getRelativePathToDirectory(folderFullPath, fileName);

src/server/editorServices.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ namespace ts.server {
246246
export const enum WatchType {
247247
ConfigFilePath = "Config file for the program",
248248
MissingFilePath = "Missing file from program",
249-
WildCardDirectories = "Wild card directory",
249+
WildcardDirectories = "Wild card directory",
250250
TypeRoot = "Type root of the project",
251251
ClosedScriptInfo = "Closed Script info",
252252
ConfigFileForInferredRoot = "Config file for the inferred project root"
@@ -363,7 +363,7 @@ namespace ts.server {
363363
* - Or it is present if we have configured project open with config file at that location
364364
* In this case the exists property is always true
365365
*/
366-
private readonly mapOfConfigFileExistenceInfo = createMap<ConfigFileExistenceInfo>();
366+
private readonly configFileExistenceInfoCache = createMap<ConfigFileExistenceInfo>();
367367
private readonly throttledOperations: ThrottledOperations;
368368

369369
private readonly hostConfiguration: HostConfiguration;
@@ -693,7 +693,7 @@ namespace ts.server {
693693
}
694694

695695
private onConfigChangedForConfiguredProject(project: ConfiguredProject, eventKind: FileWatcherEventKind) {
696-
const configFileExistenceInfo = this.mapOfConfigFileExistenceInfo.get(project.canonicalConfigFilePath);
696+
const configFileExistenceInfo = this.configFileExistenceInfoCache.get(project.canonicalConfigFilePath);
697697
if (eventKind === FileWatcherEventKind.Deleted) {
698698
// Update the cached status
699699
// We arent updating or removing the cached config file presence info as that will be taken care of by
@@ -725,7 +725,7 @@ namespace ts.server {
725725
private onConfigFileChangeForOpenScriptInfo(configFileName: NormalizedPath, eventKind: FileWatcherEventKind) {
726726
// This callback is called only if we dont have config file project for this config file
727727
const canonicalConfigPath = normalizedPathToPath(configFileName, this.currentDirectory, this.toCanonicalFileName);
728-
const configFileExistenceInfo = this.mapOfConfigFileExistenceInfo.get(canonicalConfigPath);
728+
const configFileExistenceInfo = this.configFileExistenceInfoCache.get(canonicalConfigPath);
729729
configFileExistenceInfo.exists = (eventKind !== FileWatcherEventKind.Deleted);
730730
this.logConfigFileWatchUpdate(configFileName, canonicalConfigPath, configFileExistenceInfo, ConfigFileWatcherStatus.ReloadingFiles);
731731

@@ -852,7 +852,7 @@ namespace ts.server {
852852
}
853853

854854
private configFileExists(configFileName: NormalizedPath, canonicalConfigFilePath: string, info: ScriptInfo) {
855-
let configFileExistenceInfo = this.mapOfConfigFileExistenceInfo.get(canonicalConfigFilePath);
855+
let configFileExistenceInfo = this.configFileExistenceInfoCache.get(canonicalConfigFilePath);
856856
if (configFileExistenceInfo) {
857857
// By default the info would get impacted by presence of config file since its in the detection path
858858
// Only adding the info as a root to inferred project will need the existence to be watched by file watcher
@@ -877,13 +877,13 @@ namespace ts.server {
877877
openFilesImpactedByConfigFile.set(info.path, false);
878878
const exists = this.host.fileExists(configFileName);
879879
configFileExistenceInfo = { exists, openFilesImpactedByConfigFile };
880-
this.mapOfConfigFileExistenceInfo.set(canonicalConfigFilePath, configFileExistenceInfo);
880+
this.configFileExistenceInfoCache.set(canonicalConfigFilePath, configFileExistenceInfo);
881881
this.logConfigFileWatchUpdate(configFileName, canonicalConfigFilePath, configFileExistenceInfo, ConfigFileWatcherStatus.OpenFilesImpactedByConfigFileAdd);
882882
return exists;
883883
}
884884

885885
private setConfigFileExistenceByNewConfiguredProject(project: ConfiguredProject) {
886-
const configFileExistenceInfo = this.mapOfConfigFileExistenceInfo.get(project.canonicalConfigFilePath);
886+
const configFileExistenceInfo = this.configFileExistenceInfoCache.get(project.canonicalConfigFilePath);
887887
if (configFileExistenceInfo) {
888888
Debug.assert(configFileExistenceInfo.exists);
889889
// close existing watcher
@@ -900,7 +900,7 @@ namespace ts.server {
900900
else {
901901
// We could be in this scenario if project is the configured project tracked by external project
902902
// Since that route doesnt check if the config file is present or not
903-
this.mapOfConfigFileExistenceInfo.set(project.canonicalConfigFilePath, {
903+
this.configFileExistenceInfoCache.set(project.canonicalConfigFilePath, {
904904
exists: true,
905905
openFilesImpactedByConfigFile: createMap<boolean>()
906906
});
@@ -915,7 +915,7 @@ namespace ts.server {
915915
}
916916

917917
private setConfigFileExistenceInfoByClosedConfiguredProject(closedProject: ConfiguredProject) {
918-
const configFileExistenceInfo = this.mapOfConfigFileExistenceInfo.get(closedProject.canonicalConfigFilePath);
918+
const configFileExistenceInfo = this.configFileExistenceInfoCache.get(closedProject.canonicalConfigFilePath);
919919
Debug.assert(!!configFileExistenceInfo);
920920
if (configFileExistenceInfo.openFilesImpactedByConfigFile.size) {
921921
const configFileName = closedProject.getConfigFilePath();
@@ -933,7 +933,7 @@ namespace ts.server {
933933
}
934934
else {
935935
// There is not a single file open thats tracking the status of this config file. Remove from cache
936-
this.mapOfConfigFileExistenceInfo.delete(closedProject.canonicalConfigFilePath);
936+
this.configFileExistenceInfoCache.delete(closedProject.canonicalConfigFilePath);
937937
}
938938
}
939939

@@ -983,7 +983,7 @@ namespace ts.server {
983983
private stopWatchingConfigFilesForClosedScriptInfo(info: ScriptInfo) {
984984
Debug.assert(!info.isScriptOpen());
985985
this.forEachConfigFileLocation(info, (configFileName, canonicalConfigFilePath) => {
986-
const configFileExistenceInfo = this.mapOfConfigFileExistenceInfo.get(canonicalConfigFilePath);
986+
const configFileExistenceInfo = this.configFileExistenceInfoCache.get(canonicalConfigFilePath);
987987
if (configFileExistenceInfo) {
988988
const infoIsRootOfInferredProject = configFileExistenceInfo.openFilesImpactedByConfigFile.get(info.path);
989989

@@ -1006,7 +1006,7 @@ namespace ts.server {
10061006
if (!configFileExistenceInfo.openFilesImpactedByConfigFile.size &&
10071007
!this.getConfiguredProjectByCanonicalConfigFilePath(canonicalConfigFilePath)) {
10081008
Debug.assert(!configFileExistenceInfo.configFileWatcherForRootOfInferredProject);
1009-
this.mapOfConfigFileExistenceInfo.delete(canonicalConfigFilePath);
1009+
this.configFileExistenceInfoCache.delete(canonicalConfigFilePath);
10101010
}
10111011
}
10121012
});
@@ -1019,14 +1019,14 @@ namespace ts.server {
10191019
startWatchingConfigFilesForInferredProjectRoot(info: ScriptInfo) {
10201020
Debug.assert(info.isScriptOpen());
10211021
this.forEachConfigFileLocation(info, (configFileName, canonicalConfigFilePath) => {
1022-
let configFilePresenceInfo = this.mapOfConfigFileExistenceInfo.get(canonicalConfigFilePath);
1022+
let configFilePresenceInfo = this.configFileExistenceInfoCache.get(canonicalConfigFilePath);
10231023
if (!configFilePresenceInfo) {
10241024
// Create the cache
10251025
configFilePresenceInfo = {
10261026
exists: this.host.fileExists(configFileName),
10271027
openFilesImpactedByConfigFile: createMap<boolean>()
10281028
};
1029-
this.mapOfConfigFileExistenceInfo.set(canonicalConfigFilePath, configFilePresenceInfo);
1029+
this.configFileExistenceInfoCache.set(canonicalConfigFilePath, configFilePresenceInfo);
10301030
}
10311031

10321032
// Set this file as the root of inferred project
@@ -1050,7 +1050,7 @@ namespace ts.server {
10501050
/* @internal */
10511051
stopWatchingConfigFilesForInferredProjectRoot(info: ScriptInfo, reason: WatcherCloseReason) {
10521052
this.forEachConfigFileLocation(info, (configFileName, canonicalConfigFilePath) => {
1053-
const configFileExistenceInfo = this.mapOfConfigFileExistenceInfo.get(canonicalConfigFilePath);
1053+
const configFileExistenceInfo = this.configFileExistenceInfoCache.get(canonicalConfigFilePath);
10541054
if (configFileExistenceInfo && configFileExistenceInfo.openFilesImpactedByConfigFile.has(info.path)) {
10551055
Debug.assert(info.isScriptOpen());
10561056

@@ -1607,14 +1607,14 @@ namespace ts.server {
16071607

16081608
/* @internal */
16091609
closeDirectoryWatcher(watchType: WatchType, project: Project, directory: string, watcher: FileWatcher, flags: WatchDirectoryFlags, reason: WatcherCloseReason) {
1610-
const recursive = isRecursiveDirectoryWatch(flags);
1610+
const recursive = (flags & WatchDirectoryFlags.Recursive) !== 0;
16111611
this.logger.info(`DirectoryWatcher ${recursive ? "recursive" : ""}:: Close: ${directory} Project: ${project.getProjectName()} WatchType: ${watchType} Reason: ${reason}`);
16121612
watcher.close();
16131613
}
16141614

16151615
/* @internal */
16161616
addDirectoryWatcher(watchType: WatchType, project: Project, directory: string, cb: ServerDirectoryWatcherCallback, flags: WatchDirectoryFlags) {
1617-
const recursive = isRecursiveDirectoryWatch(flags);
1617+
const recursive = (flags & WatchDirectoryFlags.Recursive) !== 0;
16181618
this.logger.info(`DirectoryWatcher ${recursive ? "recursive" : ""}:: Added: ${directory} Project: ${project.getProjectName()} WatchType: ${watchType}`);
16191619
return this.host.watchDirectory(directory, fileName => {
16201620
const path = toNormalizedPath(getNormalizedAbsolutePath(fileName, directory));

src/server/project.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,22 +1153,25 @@ namespace ts.server {
11531153
createNewValue: (directory, flags) => {
11541154
return {
11551155
watcher: this.projectService.addDirectoryWatcher(
1156-
WatchType.WildCardDirectories, this, directory,
1156+
WatchType.WildcardDirectories, this, directory,
11571157
path => this.projectService.onFileAddOrRemoveInWatchedDirectoryOfProject(this, path),
11581158
flags
11591159
),
11601160
flags
11611161
};
11621162
},
1163-
// Close existing watch thats not needed any more or doesnt match recursive flags
1164-
onDeleteExistingValue: (directory, wildcardDirectoryWatcher, isNotSame) =>
1165-
this.closeWildcardDirectoryWatcher(directory, wildcardDirectoryWatcher, isNotSame ? WatcherCloseReason.RecursiveChanged : WatcherCloseReason.NotNeeded),
1163+
// Close existing watch thats not needed any more
1164+
onDeleteExistingValue: (directory, wildcardDirectoryWatcher) =>
1165+
this.closeWildcardDirectoryWatcher(directory, wildcardDirectoryWatcher, WatcherCloseReason.NotNeeded),
1166+
// Close existing watch that doesnt match in the recursive flags
1167+
onDeleteExistingMismatchValue: (directory, wildcardDirectoryWatcher) =>
1168+
this.closeWildcardDirectoryWatcher(directory, wildcardDirectoryWatcher, WatcherCloseReason.RecursiveChanged),
11661169
}
11671170
);
11681171
}
11691172

11701173
private closeWildcardDirectoryWatcher(directory: string, { watcher, flags }: WildcardDirectoryWatcher, closeReason: WatcherCloseReason) {
1171-
this.projectService.closeDirectoryWatcher(WatchType.WildCardDirectories, this, directory, watcher, flags, closeReason);
1174+
this.projectService.closeDirectoryWatcher(WatchType.WildcardDirectories, this, directory, watcher, flags, closeReason);
11721175
}
11731176

11741177
stopWatchingWildCards(reason: WatcherCloseReason) {

src/server/utilities.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,21 +299,22 @@ namespace ts.server {
299299
}
300300

301301
/**
302-
* clears already present map (!== undefined) by calling onDeleteExistingValue callback before deleting that key/value
302+
* clears already present map by calling onDeleteExistingValue callback before deleting that key/value
303303
*/
304304
export function clearMap<T>(map: Map<T>, onDeleteExistingValue: (key: string, existingValue: T) => void) {
305305
// Remove all
306306
map.forEach((existingValue, key) => {
307-
map.delete(key);
308307
onDeleteExistingValue(key, existingValue);
309308
});
309+
map.clear();
310310
}
311311

312312
export interface MutateMapOptions<T, U> {
313313
createNewValue(key: string, valueInNewMap: U): T;
314314
onDeleteExistingValue(key: string, existingValue: T, isNotSame?: boolean): void;
315315

316316
isSameValue?(existingValue: T, valueInNewMap: U): boolean;
317+
onDeleteExistingMismatchValue?(key: string, existingValue: T): void;
317318
}
318319

319320
/**
@@ -322,16 +323,20 @@ namespace ts.server {
322323
export function mutateMap<T, U>(map: Map<T>, newMap: ReadonlyMap<U>, options: MutateMapOptions<T, U>) {
323324
// If there are new values update them
324325
if (newMap) {
325-
const { isSameValue, createNewValue, onDeleteExistingValue } = options;
326+
const { isSameValue, createNewValue, onDeleteExistingValue, onDeleteExistingMismatchValue } = options;
326327
// Needs update
327328
map.forEach((existingValue, key) => {
328329
const valueInNewMap = newMap.get(key);
329-
if (valueInNewMap === undefined ||
330-
// different value - remove it
331-
(isSameValue && !isSameValue(existingValue, valueInNewMap))) {
332-
const isNotSame = valueInNewMap !== undefined;
330+
// Not present any more in new map, remove it
331+
if (valueInNewMap === undefined) {
333332
map.delete(key);
334-
onDeleteExistingValue(key, existingValue, isNotSame);
333+
onDeleteExistingValue(key, existingValue);
334+
}
335+
// different value - remove it
336+
else if (isSameValue && !isSameValue(existingValue, valueInNewMap)) {
337+
Debug.assert(!!onDeleteExistingMismatchValue);
338+
map.delete(key);
339+
onDeleteExistingMismatchValue(key, existingValue);
335340
}
336341
});
337342

0 commit comments

Comments
 (0)