@@ -86,6 +86,10 @@ namespace ts.server.typingsInstaller {
86
86
87
87
type ProjectWatchers = Map < FileWatcher > & { isInvoked ?: boolean ; } ;
88
88
89
+ function getDetailWatchInfo ( projectName : string , watchers : ProjectWatchers ) {
90
+ return `Project: ${ projectName } watcher already invoked: ${ watchers . isInvoked } ` ;
91
+ }
92
+
89
93
export abstract class TypingsInstaller {
90
94
private readonly packageNameToTypingLocation : Map < JsTyping . CachedTyping > = createMap < JsTyping . CachedTyping > ( ) ;
91
95
private readonly missingTypingsSet : Map < true > = createMap < true > ( ) ;
@@ -100,6 +104,8 @@ namespace ts.server.typingsInstaller {
100
104
private inFlightRequestCount = 0 ;
101
105
102
106
abstract readonly typesRegistry : Map < MapLike < string > > ;
107
+ /*@internal */
108
+ private readonly watchFactory : WatchFactory < string , ProjectWatchers > ;
103
109
104
110
constructor (
105
111
protected readonly installTypingHost : InstallTypingHost ,
@@ -110,9 +116,11 @@ namespace ts.server.typingsInstaller {
110
116
protected readonly log = nullLog ) {
111
117
this . toCanonicalFileName = createGetCanonicalFileName ( installTypingHost . useCaseSensitiveFileNames ) ;
112
118
this . globalCachePackageJsonPath = combinePaths ( globalCachePath , "package.json" ) ;
113
- if ( this . log . isEnabled ( ) ) {
119
+ const isLoggingEnabled = this . log . isEnabled ( ) ;
120
+ if ( isLoggingEnabled ) {
114
121
this . log . writeLine ( `Global cache location '${ globalCachePath } ', safe file path '${ safeListPath } ', types map path ${ typesMapLocation } ` ) ;
115
122
}
123
+ this . watchFactory = getWatchFactory ( isLoggingEnabled ? WatchLogLevel . Verbose : WatchLogLevel . None , s => this . log . writeLine ( s ) , getDetailWatchInfo ) ;
116
124
this . processCacheLocation ( this . globalCachePath ) ;
117
125
}
118
126
@@ -431,19 +439,13 @@ namespace ts.server.typingsInstaller {
431
439
this . log . writeLine ( `${ projectWatcherType } :: Added:: WatchInfo: ${ path } ` ) ;
432
440
}
433
441
const watcher = projectWatcherType === ProjectWatcherType . FileWatcher ?
434
- this . installTypingHost . watchFile ! ( path , ( f , eventKind ) => { // TODO: GH#18217
435
- if ( isLoggingEnabled ) {
436
- this . log . writeLine ( `FileWatcher:: Triggered with ${ f } eventKind: ${ FileWatcherEventKind [ eventKind ] } :: WatchInfo: ${ path } :: handler is already invoked '${ watchers . isInvoked } '` ) ;
437
- }
442
+ this . watchFactory . watchFile ( this . installTypingHost as WatchFileHost , path , ( ) => {
438
443
if ( ! watchers . isInvoked ) {
439
444
watchers . isInvoked = true ;
440
445
this . sendResponse ( { projectName, kind : ActionInvalidate } ) ;
441
446
}
442
- } , /*pollingInterval*/ 2000 , options ) :
443
- this . installTypingHost . watchDirectory ! ( path , f => { // TODO: GH#18217
444
- if ( isLoggingEnabled ) {
445
- this . log . writeLine ( `DirectoryWatcher:: Triggered with ${ f } :: WatchInfo: ${ path } recursive :: handler is already invoked '${ watchers . isInvoked } '` ) ;
446
- }
447
+ } , PollingInterval . High , options , projectName , watchers ) :
448
+ this . watchFactory . watchDirectory ( this . installTypingHost as WatchDirectoryHost , path , f => {
447
449
if ( watchers . isInvoked || ! fileExtensionIs ( f , Extension . Json ) ) {
448
450
return ;
449
451
}
@@ -453,7 +455,7 @@ namespace ts.server.typingsInstaller {
453
455
watchers . isInvoked = true ;
454
456
this . sendResponse ( { projectName, kind : ActionInvalidate } ) ;
455
457
}
456
- } , /*recursive*/ true , options ) ;
458
+ } , WatchDirectoryFlags . Recursive , options , projectName , watchers ) ;
457
459
458
460
watchers . set ( canonicalPath , isLoggingEnabled ? {
459
461
close : ( ) => {
0 commit comments