Skip to content

Commit cec5aaf

Browse files
authored
Merge pull request microsoft#23783 from Microsoft/tscWatchInfo
More detailed log during watch in tsc showing what the watcher is invoked for.
2 parents 4be87e6 + 2e4f378 commit cec5aaf

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

src/compiler/watch.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -531,13 +531,13 @@ namespace ts {
531531
const watchLogLevel = trace ? compilerOptions.extendedDiagnostics ? WatchLogLevel.Verbose :
532532
compilerOptions.diagnostis ? WatchLogLevel.TriggerOnly : WatchLogLevel.None : WatchLogLevel.None;
533533
const writeLog: (s: string) => void = watchLogLevel !== WatchLogLevel.None ? trace : noop;
534-
const { watchFile, watchFilePath, watchDirectory: watchDirectoryWorker } = getWatchFactory(watchLogLevel, writeLog);
534+
const { watchFile, watchFilePath, watchDirectory } = getWatchFactory<string>(watchLogLevel, writeLog);
535535

536536
const getCanonicalFileName = createGetCanonicalFileName(useCaseSensitiveFileNames);
537537

538538
writeLog(`Current directory: ${currentDirectory} CaseSensitiveFileNames: ${useCaseSensitiveFileNames}`);
539539
if (configFileName) {
540-
watchFile(host, configFileName, scheduleProgramReload, PollingInterval.High);
540+
watchFile(host, configFileName, scheduleProgramReload, PollingInterval.High, "Config file");
541541
}
542542

543543
const compilerHost: CompilerHost & ResolutionCacheHost = {
@@ -563,8 +563,8 @@ namespace ts {
563563
// Members for ResolutionCacheHost
564564
toPath,
565565
getCompilationSettings: () => compilerOptions,
566-
watchDirectoryOfFailedLookupLocation: watchDirectory,
567-
watchTypeRootsDirectory: watchDirectory,
566+
watchDirectoryOfFailedLookupLocation: (dir, cb, flags) => watchDirectory(host, dir, cb, flags, "Failed Lookup Locations"),
567+
watchTypeRootsDirectory: (dir, cb, flags) => watchDirectory(host, dir, cb, flags, "Type roots"),
568568
getCachedDirectoryStructureHost: () => cachedDirectoryStructureHost,
569569
onInvalidatedResolution: scheduleProgramUpdate,
570570
onChangedAutomaticTypeDirectiveNames: () => {
@@ -728,7 +728,7 @@ namespace ts {
728728
(hostSourceFile as FilePresentOnHost).sourceFile = sourceFile;
729729
sourceFile.version = hostSourceFile.version.toString();
730730
if (!(hostSourceFile as FilePresentOnHost).fileWatcher) {
731-
(hostSourceFile as FilePresentOnHost).fileWatcher = watchFilePath(host, fileName, onSourceFileChange, PollingInterval.Low, path);
731+
(hostSourceFile as FilePresentOnHost).fileWatcher = watchFilePath(host, fileName, onSourceFileChange, PollingInterval.Low, path, "Source file");
732732
}
733733
}
734734
else {
@@ -742,7 +742,7 @@ namespace ts {
742742
else {
743743
if (sourceFile) {
744744
sourceFile.version = initialVersion.toString();
745-
const fileWatcher = watchFilePath(host, fileName, onSourceFileChange, PollingInterval.Low, path);
745+
const fileWatcher = watchFilePath(host, fileName, onSourceFileChange, PollingInterval.Low, path, "Source file");
746746
sourceFilesCache.set(path, { sourceFile, version: initialVersion, fileWatcher });
747747
}
748748
else {
@@ -827,6 +827,7 @@ namespace ts {
827827
if (timerToUpdateProgram) {
828828
host.clearTimeout(timerToUpdateProgram);
829829
}
830+
writeLog("Scheduling update");
830831
timerToUpdateProgram = host.setTimeout(updateProgram, 250);
831832
}
832833

@@ -852,6 +853,7 @@ namespace ts {
852853
}
853854

854855
function reloadFileNamesFromConfigFile() {
856+
writeLog("Reloading new file names and options");
855857
const result = getFileNamesFromConfigSpecs(configFileSpecs, getDirectoryPath(configFileName), compilerOptions, parseConfigFileHost);
856858
if (result.fileNames.length) {
857859
configFileParsingDiagnostics = filter(configFileParsingDiagnostics, error => !isErrorNoInputFiles(error));
@@ -913,12 +915,8 @@ namespace ts {
913915
}
914916
}
915917

916-
function watchDirectory(directory: string, cb: DirectoryWatcherCallback, flags: WatchDirectoryFlags) {
917-
return watchDirectoryWorker(host, directory, cb, flags);
918-
}
919-
920918
function watchMissingFilePath(missingFilePath: Path) {
921-
return watchFilePath(host, missingFilePath, onMissingFileChange, PollingInterval.Medium, missingFilePath);
919+
return watchFilePath(host, missingFilePath, onMissingFileChange, PollingInterval.Medium, missingFilePath, "Missing file");
922920
}
923921

924922
function onMissingFileChange(fileName: string, eventKind: FileWatcherEventKind, missingFilePath: Path) {
@@ -951,6 +949,7 @@ namespace ts {
951949

952950
function watchWildcardDirectory(directory: string, flags: WatchDirectoryFlags) {
953951
return watchDirectory(
952+
host,
954953
directory,
955954
fileOrDirectory => {
956955
Debug.assert(!!configFileName);
@@ -978,7 +977,8 @@ namespace ts {
978977
scheduleProgramUpdate();
979978
}
980979
},
981-
flags
980+
flags,
981+
"Wild card directories"
982982
);
983983
}
984984

src/compiler/watchUtilities.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,11 @@ namespace ts {
352352
watchDirectory: WatchDirectory<X, Y>;
353353
}
354354

355-
export function getWatchFactory<X = undefined, Y = undefined>(watchLogLevel: WatchLogLevel, log: (s: string) => void, getDetailWatchInfo?: GetDetailWatchInfo<X, Y>): WatchFactory<X, Y> {
355+
export function getWatchFactory<X, Y = undefined>(watchLogLevel: WatchLogLevel, log: (s: string) => void, getDetailWatchInfo?: GetDetailWatchInfo<X, Y>): WatchFactory<X, Y> {
356356
return getWatchFactoryWith(watchLogLevel, log, getDetailWatchInfo, watchFile, watchDirectory);
357357
}
358358

359-
function getWatchFactoryWith<X = undefined, Y = undefined>(watchLogLevel: WatchLogLevel, log: (s: string) => void, getDetailWatchInfo: GetDetailWatchInfo<X, Y> | undefined,
359+
function getWatchFactoryWith<X, Y = undefined>(watchLogLevel: WatchLogLevel, log: (s: string) => void, getDetailWatchInfo: GetDetailWatchInfo<X, Y> | undefined,
360360
watchFile: (host: WatchFileHost, file: string, callback: FileWatcherCallback, watchPriority: PollingInterval) => FileWatcher,
361361
watchDirectory: (host: WatchDirectoryHost, directory: string, callback: DirectoryWatcherCallback, flags: WatchDirectoryFlags) => FileWatcher): WatchFactory<X, Y> {
362362
const createFileWatcher: CreateFileWatcher<WatchFileHost, PollingInterval, FileWatcherEventKind, undefined, X, Y> = getCreateFileWatcher(watchLogLevel, watchFile);
@@ -422,8 +422,8 @@ namespace ts {
422422
}, flags);
423423
}
424424

425-
function getWatchInfo<T, X, Y>(file: string, flags: T, detailInfo1: X | undefined, detailInfo2: Y | undefined, getDetailWatchInfo: GetDetailWatchInfo<X, Y> | undefined) {
426-
return `WatchInfo: ${file} ${flags} ${getDetailWatchInfo ? getDetailWatchInfo(detailInfo1, detailInfo2) : ""}`;
425+
function getWatchInfo<T, X, Y>(file: string, flags: T, detailInfo1: X, detailInfo2: Y | undefined, getDetailWatchInfo: GetDetailWatchInfo<X, Y> | undefined) {
426+
return `WatchInfo: ${file} ${flags} ${getDetailWatchInfo ? getDetailWatchInfo(detailInfo1, detailInfo2) : detailInfo1}`;
427427
}
428428

429429
export function closeFileWatcherOf<T extends { watcher: FileWatcher; }>(objWithWatcher: T) {

src/harness/unittests/tscWatchMode.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,16 +2257,17 @@ declare module "fs" {
22572257
"CreatingProgramWith::\n",
22582258
" roots: [\"f.ts\"]\n",
22592259
" options: {\"extendedDiagnostics\":true}\n",
2260-
"FileWatcher:: Added:: WatchInfo: f.ts 250 \n",
2261-
"FileWatcher:: Added:: WatchInfo: /a/lib/lib.d.ts 250 \n"
2260+
"FileWatcher:: Added:: WatchInfo: f.ts 250 Source file\n",
2261+
"FileWatcher:: Added:: WatchInfo: /a/lib/lib.d.ts 250 Source file\n"
22622262
]);
22632263

22642264
file.content = "//";
22652265
host.reloadFS(files);
22662266
host.runQueuedTimeoutCallbacks();
22672267
checkOutputErrorsIncremental(host, emptyArray, disableConsoleClear, options.extendedDiagnostics && [
2268-
"FileWatcher:: Triggered with /f.ts1:: WatchInfo: f.ts 250 \n",
2269-
"Elapsed:: 0ms FileWatcher:: Triggered with /f.ts1:: WatchInfo: f.ts 250 \n"
2268+
"FileWatcher:: Triggered with /f.ts1:: WatchInfo: f.ts 250 Source file\n",
2269+
"Scheduling update\n",
2270+
"Elapsed:: 0ms FileWatcher:: Triggered with /f.ts1:: WatchInfo: f.ts 250 Source file\n"
22702271
], options.extendedDiagnostics && [
22712272
"Synchronizing program\n",
22722273
"CreatingProgramWith::\n",

0 commit comments

Comments
 (0)