@@ -96,43 +96,63 @@ namespace ts {
9696 Verbose
9797 }
9898
99- export type WatchFile < X , Y > = ( host : System , file : string , callback : FileWatcherCallback , pollingInterval ?: number , detailInfo1 ?: X , detailInfo2 ?: Y ) => FileWatcher ;
99+ export type WatchFile < X , Y > = ( host : System , file : string , callback : FileWatcherCallback , watchPriority : WatchPriority , detailInfo1 ?: X , detailInfo2 ?: Y ) => FileWatcher ;
100100 export type FilePathWatcherCallback = ( fileName : string , eventKind : FileWatcherEventKind , filePath : Path ) => void ;
101- export type WatchFilePath < X , Y > = ( host : System , file : string , callback : FilePathWatcherCallback , pollingInterval : number | undefined , path : Path , detailInfo1 ?: X , detailInfo2 ?: Y ) => FileWatcher ;
101+ export type WatchFilePath < X , Y > = ( host : System , file : string , callback : FilePathWatcherCallback , watchPriority : WatchPriority , path : Path , detailInfo1 ?: X , detailInfo2 ?: Y ) => FileWatcher ;
102102 export type WatchDirectory < X , Y > = ( host : System , directory : string , callback : DirectoryWatcherCallback , flags : WatchDirectoryFlags , detailInfo1 ?: X , detailInfo2 ?: Y ) => FileWatcher ;
103103
104- export function createWatchFile < X = undefined , Y = undefined > ( watchLogLevel : WatchLogLevel , log : ( s : string ) => void , getDetailWatchInfo ?: GetDetailWatchInfo < X , Y > ) : WatchFile < X , Y > {
105- const createFileWatcher : CreateFileWatcher < number | undefined , FileWatcherEventKind , undefined , X , Y > = getCreateFileWatcher ( watchLogLevel , watchFile ) ;
106- return ( host , file , callback , pollingInterval , detailInfo1 , detailInfo2 ) =>
107- createFileWatcher ( host , file , callback , pollingInterval , /*passThrough*/ undefined , detailInfo1 , detailInfo2 , watchFile , log , "FileWatcher" , getDetailWatchInfo ) ;
104+ export interface WatchFactory < X , Y > {
105+ watchFile : WatchFile < X , Y > ;
106+ watchFilePath : WatchFilePath < X , Y > ;
107+ watchDirectory : WatchDirectory < X , Y > ;
108108 }
109109
110- export function createWatchFilePath < X = undefined , Y = undefined > ( watchLogLevel : WatchLogLevel , log : ( s : string ) => void , getDetailWatchInfo ?: GetDetailWatchInfo < X , Y > ) : WatchFilePath < X , Y > {
111- const createFileWatcher : CreateFileWatcher < number | undefined , FileWatcherEventKind , Path , X , Y > = getCreateFileWatcher ( watchLogLevel , watchFilePath ) ;
112- return ( host , file , callback , pollingInterval , path , detailInfo1 , detailInfo2 ) =>
113- createFileWatcher ( host , file , callback , pollingInterval , path , detailInfo1 , detailInfo2 , watchFile , log , "FileWatcher" , getDetailWatchInfo ) ;
110+ export function getWatchFactory < X = undefined , Y = undefined > ( host : System , watchLogLevel : WatchLogLevel , log : ( s : string ) => void , getDetailWatchInfo ?: GetDetailWatchInfo < X , Y > ) : WatchFactory < X , Y > {
111+ const value = host . getEnvironmentVariable ( "TSC_WATCHFILE" ) ;
112+ switch ( value ) {
113+ case "PriorityPollingInterval" :
114+ // Use polling interval based on priority when create watch using host.watchFile
115+ return getWatchFactoryWith ( watchLogLevel , log , getDetailWatchInfo , watchFileUsingPriorityPollingInterval , watchDirectory ) ;
116+ default :
117+ return getDefaultWatchFactory ( watchLogLevel , log , getDetailWatchInfo ) ;
118+ }
114119 }
115120
116- export function createWatchDirectory < X = undefined , Y = undefined > ( watchLogLevel : WatchLogLevel , log : ( s : string ) => void , getDetailWatchInfo ?: GetDetailWatchInfo < X , Y > ) : WatchDirectory < X , Y > {
117- const createFileWatcher : CreateFileWatcher < WatchDirectoryFlags , undefined , undefined , X , Y > = getCreateFileWatcher ( watchLogLevel , watchDirectory ) ;
118- return ( host , directory , callback , flags , detailInfo1 , detailInfo2 ) =>
119- createFileWatcher ( host , directory , callback , flags , /*passThrough*/ undefined , detailInfo1 , detailInfo2 , watchDirectory , log , "DirectoryWatcher" , getDetailWatchInfo ) ;
121+ export function getDefaultWatchFactory < X = undefined , Y = undefined > ( watchLogLevel : WatchLogLevel , log : ( s : string ) => void , getDetailWatchInfo ?: GetDetailWatchInfo < X , Y > ) : WatchFactory < X , Y > {
122+ // Current behaviour in which polling interval is always 250 ms
123+ return getWatchFactoryWith ( watchLogLevel , log , getDetailWatchInfo , watchFile , watchDirectory ) ;
120124 }
121125
122- function watchFile ( host : System , file : string , callback : FileWatcherCallback , pollingInterval ?: number ) : FileWatcher {
123- return host . watchFile ( file , callback , pollingInterval ) ;
126+ function getWatchFactoryWith < X = undefined , Y = undefined > ( watchLogLevel : WatchLogLevel , log : ( s : string ) => void , getDetailWatchInfo : GetDetailWatchInfo < X , Y > | undefined ,
127+ watchFile : ( host : System , file : string , callback : FileWatcherCallback , watchPriority : WatchPriority ) => FileWatcher ,
128+ watchDirectory : ( host : System , directory : string , callback : DirectoryWatcherCallback , flags : WatchDirectoryFlags ) => FileWatcher ) : WatchFactory < X , Y > {
129+ const createFileWatcher : CreateFileWatcher < WatchPriority , FileWatcherEventKind , undefined , X , Y > = getCreateFileWatcher ( watchLogLevel , watchFile ) ;
130+ const createFilePathWatcher : CreateFileWatcher < WatchPriority , FileWatcherEventKind , Path , X , Y > = watchLogLevel === WatchLogLevel . None ? watchFilePath : createFileWatcher ;
131+ const createDirectoryWatcher : CreateFileWatcher < WatchDirectoryFlags , undefined , undefined , X , Y > = getCreateFileWatcher ( watchLogLevel , watchDirectory ) ;
132+ return {
133+ watchFile : ( host , file , callback , pollingInterval , detailInfo1 , detailInfo2 ) =>
134+ createFileWatcher ( host , file , callback , pollingInterval , /*passThrough*/ undefined , detailInfo1 , detailInfo2 , watchFile , log , "FileWatcher" , getDetailWatchInfo ) ,
135+ watchFilePath : ( host , file , callback , pollingInterval , path , detailInfo1 , detailInfo2 ) =>
136+ createFilePathWatcher ( host , file , callback , pollingInterval , path , detailInfo1 , detailInfo2 , watchFile , log , "FileWatcher" , getDetailWatchInfo ) ,
137+ watchDirectory : ( host , directory , callback , flags , detailInfo1 , detailInfo2 ) =>
138+ createDirectoryWatcher ( host , directory , callback , flags , /*passThrough*/ undefined , detailInfo1 , detailInfo2 , watchDirectory , log , "DirectoryWatcher" , getDetailWatchInfo )
139+ } ;
140+
141+ function watchFilePath ( host : System , file : string , callback : FilePathWatcherCallback , watchPriority : WatchPriority , path : Path ) : FileWatcher {
142+ return watchFile ( host , file , ( fileName , eventKind ) => callback ( fileName , eventKind , path ) , watchPriority ) ;
143+ }
124144 }
125145
126- function watchFilePath ( host : System , file : string , callback : FilePathWatcherCallback , pollingInterval : number | undefined , path : Path ) : FileWatcher {
127- return host . watchFile ( file , ( fileName , eventKind ) => callback ( fileName , eventKind , path ) , pollingInterval ) ;
146+ function watchFile ( host : System , file : string , callback : FileWatcherCallback , _watchPriority : WatchPriority ) : FileWatcher {
147+ return host . watchFile ( file , callback ) ;
128148 }
129149
130150 function watchDirectory ( host : System , directory : string , callback : DirectoryWatcherCallback , flags : WatchDirectoryFlags ) : FileWatcher {
131151 return host . watchDirectory ( directory , callback , ( flags & WatchDirectoryFlags . Recursive ) !== 0 ) ;
132152 }
133153
134- export type WatchCallback < T , U > = ( fileName : string , cbOptional ?: T , passThrough ?: U ) => void ;
135- export type AddWatch < T , U , V > = ( host : System , file : string , cb : WatchCallback < U , V > , flags : T , passThrough ?: V , detailInfo1 ?: undefined , detailInfo2 ?: undefined ) => FileWatcher ;
154+ type WatchCallback < T , U > = ( fileName : string , cbOptional ?: T , passThrough ?: U ) => void ;
155+ type AddWatch < T , U , V > = ( host : System , file : string , cb : WatchCallback < U , V > , flags : T , passThrough ?: V , detailInfo1 ?: undefined , detailInfo2 ?: undefined ) => FileWatcher ;
136156 export type GetDetailWatchInfo < X , Y > = ( detailInfo1 : X , detailInfo2 : Y ) => string ;
137157
138158 type CreateFileWatcher < T , U , V , X , Y > = ( host : System , file : string , cb : WatchCallback < U , V > , flags : T , passThrough : V | undefined , detailInfo1 : X | undefined , detailInfo2 : Y | undefined , addWatch : AddWatch < T , U , V > , log : ( s : string ) => void , watchCaption : string , getDetailWatchInfo : GetDetailWatchInfo < X , Y > | undefined ) => FileWatcher ;
@@ -170,7 +190,7 @@ namespace ts {
170190 }
171191
172192 function getWatchInfo < T , X , Y > ( file : string , flags : T , detailInfo1 : X | undefined , detailInfo2 : Y | undefined , getDetailWatchInfo : GetDetailWatchInfo < X , Y > | undefined ) {
173- return `WatchInfo: ${ file } ${ flags } ${ getDetailWatchInfo ? getDetailWatchInfo ( detailInfo1 , detailInfo2 ) : "" } `
193+ return `WatchInfo: ${ file } ${ flags } ${ getDetailWatchInfo ? getDetailWatchInfo ( detailInfo1 , detailInfo2 ) : "" } ` ;
174194 }
175195
176196 export function closeFileWatcher ( watcher : FileWatcher ) {
0 commit comments