@@ -347,37 +347,47 @@ func (p *Project) GetLanguageServiceForRequest(ctx context.Context) (*ls.Languag
347347 return languageService , cleanup
348348}
349349
350- func (p * Project ) getModuleResolutionWatchGlobs () (failedLookups map [tspath.Path ]string , affectingLocaions map [tspath.Path ]string ) {
351- failedLookups = make (map [tspath.Path ]string )
352- affectingLocaions = make (map [tspath.Path ]string )
353- for _ , resolvedModulesInFile := range p .program .GetResolvedModules () {
350+ func (p * Project ) updateModuleResolutionWatches (ctx context.Context ) {
351+ client := p .Client ()
352+ if ! p .host .IsWatchEnabled () || client == nil {
353+ return
354+ }
355+
356+ failedLookups := make (map [tspath.Path ]string )
357+ affectingLocations := make (map [tspath.Path ]string )
358+ extractLookups (p , failedLookups , affectingLocations , p .program .GetResolvedModules ())
359+ extractLookups (p , failedLookups , affectingLocations , p .program .GetResolvedTypeReferenceDirectives ())
360+
361+ p .failedLookupsWatch .update (ctx , failedLookups )
362+ p .affectingLocationsWatch .update (ctx , affectingLocations )
363+ }
364+
365+ type ResolutionWithLookupLocations interface {
366+ GetLookupLocations () * module.LookupLocations
367+ }
368+
369+ func extractLookups [T ResolutionWithLookupLocations ](
370+ p * Project ,
371+ failedLookups map [tspath.Path ]string ,
372+ affectingLocations map [tspath.Path ]string ,
373+ cache map [tspath.Path ]module.ModeAwareCache [T ],
374+ ) {
375+ for _ , resolvedModulesInFile := range cache {
354376 for _ , resolvedModule := range resolvedModulesInFile {
355- for _ , failedLookupLocation := range resolvedModule .FailedLookupLocations {
377+ for _ , failedLookupLocation := range resolvedModule .GetLookupLocations (). FailedLookupLocations {
356378 path := p .toPath (failedLookupLocation )
357379 if _ , ok := failedLookups [path ]; ! ok {
358380 failedLookups [path ] = failedLookupLocation
359381 }
360382 }
361- for _ , affectingLocation := range resolvedModule .AffectingLocations {
383+ for _ , affectingLocation := range resolvedModule .GetLookupLocations (). AffectingLocations {
362384 path := p .toPath (affectingLocation )
363- if _ , ok := affectingLocaions [path ]; ! ok {
364- affectingLocaions [path ] = affectingLocation
385+ if _ , ok := affectingLocations [path ]; ! ok {
386+ affectingLocations [path ] = affectingLocation
365387 }
366388 }
367389 }
368390 }
369- return failedLookups , affectingLocaions
370- }
371-
372- func (p * Project ) updateWatchers (ctx context.Context ) {
373- client := p .Client ()
374- if ! p .host .IsWatchEnabled () || client == nil {
375- return
376- }
377-
378- failedLookupGlobs , affectingLocationGlobs := p .getModuleResolutionWatchGlobs ()
379- p .failedLookupsWatch .update (ctx , failedLookupGlobs )
380- p .affectingLocationsWatch .update (ctx , affectingLocationGlobs )
381391}
382392
383393// onWatchEventForNilScriptInfo is fired for watch events that are not the
@@ -530,7 +540,7 @@ func (p *Project) updateGraph() (*compiler.Program, bool) {
530540 p .enqueueInstallTypingsForProject (oldProgram , hasAddedOrRemovedFiles )
531541 // TODO: this is currently always synchronously called by some kind of updating request,
532542 // but in Strada we throttle, so at least sometimes this should be considered top-level?
533- p .updateWatchers (context .TODO ())
543+ p .updateModuleResolutionWatches (context .TODO ())
534544 }
535545 p .Logf ("Finishing updateGraph: Project: %s version: %d in %s" , p .name , p .version , time .Since (start ))
536546 return p .program , true
0 commit comments