diff --git a/src/compiler/watch.ts b/src/compiler/watch.ts index 9ec362a12c0..6b3adfcf3a4 100644 --- a/src/compiler/watch.ts +++ b/src/compiler/watch.ts @@ -531,13 +531,13 @@ namespace ts { const watchLogLevel = trace ? compilerOptions.extendedDiagnostics ? WatchLogLevel.Verbose : compilerOptions.diagnostis ? WatchLogLevel.TriggerOnly : WatchLogLevel.None : WatchLogLevel.None; const writeLog: (s: string) => void = watchLogLevel !== WatchLogLevel.None ? trace : noop; - const { watchFile, watchFilePath, watchDirectory: watchDirectoryWorker } = getWatchFactory(watchLogLevel, writeLog); + const { watchFile, watchFilePath, watchDirectory } = getWatchFactory(watchLogLevel, writeLog); const getCanonicalFileName = createGetCanonicalFileName(useCaseSensitiveFileNames); writeLog(`Current directory: ${currentDirectory} CaseSensitiveFileNames: ${useCaseSensitiveFileNames}`); if (configFileName) { - watchFile(host, configFileName, scheduleProgramReload, PollingInterval.High); + watchFile(host, configFileName, scheduleProgramReload, PollingInterval.High, "Config file"); } const compilerHost: CompilerHost & ResolutionCacheHost = { @@ -563,8 +563,8 @@ namespace ts { // Members for ResolutionCacheHost toPath, getCompilationSettings: () => compilerOptions, - watchDirectoryOfFailedLookupLocation: watchDirectory, - watchTypeRootsDirectory: watchDirectory, + watchDirectoryOfFailedLookupLocation: (dir, cb, flags) => watchDirectory(host, dir, cb, flags, "Failed Lookup Locations"), + watchTypeRootsDirectory: (dir, cb, flags) => watchDirectory(host, dir, cb, flags, "Type roots"), getCachedDirectoryStructureHost: () => cachedDirectoryStructureHost, onInvalidatedResolution: scheduleProgramUpdate, onChangedAutomaticTypeDirectiveNames: () => { @@ -728,7 +728,7 @@ namespace ts { (hostSourceFile as FilePresentOnHost).sourceFile = sourceFile; sourceFile.version = hostSourceFile.version.toString(); if (!(hostSourceFile as FilePresentOnHost).fileWatcher) { - (hostSourceFile as FilePresentOnHost).fileWatcher = watchFilePath(host, fileName, onSourceFileChange, PollingInterval.Low, path); + (hostSourceFile as FilePresentOnHost).fileWatcher = watchFilePath(host, fileName, onSourceFileChange, PollingInterval.Low, path, "Source file"); } } else { @@ -742,7 +742,7 @@ namespace ts { else { if (sourceFile) { sourceFile.version = initialVersion.toString(); - const fileWatcher = watchFilePath(host, fileName, onSourceFileChange, PollingInterval.Low, path); + const fileWatcher = watchFilePath(host, fileName, onSourceFileChange, PollingInterval.Low, path, "Source file"); sourceFilesCache.set(path, { sourceFile, version: initialVersion, fileWatcher }); } else { @@ -827,6 +827,7 @@ namespace ts { if (timerToUpdateProgram) { host.clearTimeout(timerToUpdateProgram); } + writeLog("Scheduling update"); timerToUpdateProgram = host.setTimeout(updateProgram, 250); } @@ -852,6 +853,7 @@ namespace ts { } function reloadFileNamesFromConfigFile() { + writeLog("Reloading new file names and options"); const result = getFileNamesFromConfigSpecs(configFileSpecs, getDirectoryPath(configFileName), compilerOptions, parseConfigFileHost); if (result.fileNames.length) { configFileParsingDiagnostics = filter(configFileParsingDiagnostics, error => !isErrorNoInputFiles(error)); @@ -913,12 +915,8 @@ namespace ts { } } - function watchDirectory(directory: string, cb: DirectoryWatcherCallback, flags: WatchDirectoryFlags) { - return watchDirectoryWorker(host, directory, cb, flags); - } - function watchMissingFilePath(missingFilePath: Path) { - return watchFilePath(host, missingFilePath, onMissingFileChange, PollingInterval.Medium, missingFilePath); + return watchFilePath(host, missingFilePath, onMissingFileChange, PollingInterval.Medium, missingFilePath, "Missing file"); } function onMissingFileChange(fileName: string, eventKind: FileWatcherEventKind, missingFilePath: Path) { @@ -951,6 +949,7 @@ namespace ts { function watchWildcardDirectory(directory: string, flags: WatchDirectoryFlags) { return watchDirectory( + host, directory, fileOrDirectory => { Debug.assert(!!configFileName); @@ -978,7 +977,8 @@ namespace ts { scheduleProgramUpdate(); } }, - flags + flags, + "Wild card directories" ); } diff --git a/src/compiler/watchUtilities.ts b/src/compiler/watchUtilities.ts index 4fa9b28e162..fca4f858e16 100644 --- a/src/compiler/watchUtilities.ts +++ b/src/compiler/watchUtilities.ts @@ -352,11 +352,11 @@ namespace ts { watchDirectory: WatchDirectory; } - export function getWatchFactory(watchLogLevel: WatchLogLevel, log: (s: string) => void, getDetailWatchInfo?: GetDetailWatchInfo): WatchFactory { + export function getWatchFactory(watchLogLevel: WatchLogLevel, log: (s: string) => void, getDetailWatchInfo?: GetDetailWatchInfo): WatchFactory { return getWatchFactoryWith(watchLogLevel, log, getDetailWatchInfo, watchFile, watchDirectory); } - function getWatchFactoryWith(watchLogLevel: WatchLogLevel, log: (s: string) => void, getDetailWatchInfo: GetDetailWatchInfo | undefined, + function getWatchFactoryWith(watchLogLevel: WatchLogLevel, log: (s: string) => void, getDetailWatchInfo: GetDetailWatchInfo | undefined, watchFile: (host: WatchFileHost, file: string, callback: FileWatcherCallback, watchPriority: PollingInterval) => FileWatcher, watchDirectory: (host: WatchDirectoryHost, directory: string, callback: DirectoryWatcherCallback, flags: WatchDirectoryFlags) => FileWatcher): WatchFactory { const createFileWatcher: CreateFileWatcher = getCreateFileWatcher(watchLogLevel, watchFile); @@ -422,8 +422,8 @@ namespace ts { }, flags); } - function getWatchInfo(file: string, flags: T, detailInfo1: X | undefined, detailInfo2: Y | undefined, getDetailWatchInfo: GetDetailWatchInfo | undefined) { - return `WatchInfo: ${file} ${flags} ${getDetailWatchInfo ? getDetailWatchInfo(detailInfo1, detailInfo2) : ""}`; + function getWatchInfo(file: string, flags: T, detailInfo1: X, detailInfo2: Y | undefined, getDetailWatchInfo: GetDetailWatchInfo | undefined) { + return `WatchInfo: ${file} ${flags} ${getDetailWatchInfo ? getDetailWatchInfo(detailInfo1, detailInfo2) : detailInfo1}`; } export function closeFileWatcherOf(objWithWatcher: T) { diff --git a/src/harness/unittests/tscWatchMode.ts b/src/harness/unittests/tscWatchMode.ts index ca681a8f8ce..b64b02e301a 100644 --- a/src/harness/unittests/tscWatchMode.ts +++ b/src/harness/unittests/tscWatchMode.ts @@ -2257,16 +2257,17 @@ declare module "fs" { "CreatingProgramWith::\n", " roots: [\"f.ts\"]\n", " options: {\"extendedDiagnostics\":true}\n", - "FileWatcher:: Added:: WatchInfo: f.ts 250 \n", - "FileWatcher:: Added:: WatchInfo: /a/lib/lib.d.ts 250 \n" + "FileWatcher:: Added:: WatchInfo: f.ts 250 Source file\n", + "FileWatcher:: Added:: WatchInfo: /a/lib/lib.d.ts 250 Source file\n" ]); file.content = "//"; host.reloadFS(files); host.runQueuedTimeoutCallbacks(); checkOutputErrorsIncremental(host, emptyArray, disableConsoleClear, options.extendedDiagnostics && [ - "FileWatcher:: Triggered with /f.ts1:: WatchInfo: f.ts 250 \n", - "Elapsed:: 0ms FileWatcher:: Triggered with /f.ts1:: WatchInfo: f.ts 250 \n" + "FileWatcher:: Triggered with /f.ts1:: WatchInfo: f.ts 250 Source file\n", + "Scheduling update\n", + "Elapsed:: 0ms FileWatcher:: Triggered with /f.ts1:: WatchInfo: f.ts 250 Source file\n" ], options.extendedDiagnostics && [ "Synchronizing program\n", "CreatingProgramWith::\n",