@@ -221,6 +221,7 @@ export class AEDebuggingCache {
221221 constructor ( ) {
222222 this . registeredDebuggingViews = [ ] ;
223223 this . debouncedUpdateDebuggingViews = _ . debounce ( this . updateDebggingViews , 100 ) ;
224+ this . changedFiles = new Set ( ) ;
224225 }
225226 /*MD ## Registration MD*/
226227 async registerFileForAEDebugging ( url , context , triplesCallback ) {
@@ -231,7 +232,7 @@ export class AEDebuggingCache {
231232 }
232233 return false ;
233234 } ;
234- this . registeredDebuggingViews . push ( callback ) ;
235+ this . registeredDebuggingViews . push ( { callback, url } ) ;
235236
236237 triplesCallback ( ( await this . getDependencyTriplesForFile ( url ) ) ) ;
237238 }
@@ -305,24 +306,24 @@ export class AEDebuggingCache {
305306 } else if ( type === 1 ) {
306307 if ( recentDeletions > 0 ) {
307308 const matchingLines = Math . max ( recentDeletions , data . length ) ;
308- for ( let i = 0 ; i < matchingLines ; i ++ ) {
309+ for ( let i = 0 ; i < matchingLines ; i ++ ) {
309310 mapping [ originalLine - matchingLines + i ] = [ newLine , true ] ;
310311 newLine ++ ;
311312 }
312- data = data . substring ( matchingLines )
313- }
314- if ( data . length > 0 ) {
313+ data = data . substring ( matchingLines ) ;
314+ }
315+ if ( data . length > 0 ) {
315316 newLine += data . length ;
316317 recentAdditions += data . length ;
317318 }
318319 } else {
319320 if ( recentAdditions > 0 ) {
320321 const matchingLines = Math . max ( recentAdditions , data . length ) ;
321- for ( let i = 0 ; i < matchingLines ; i ++ ) {
322+ for ( let i = 0 ; i < matchingLines ; i ++ ) {
322323 mapping [ originalLine ] = [ newLine - matchingLines + i , true ] ;
323324 originalLine ++ ;
324- }
325- data = data . substring ( matchingLines )
325+ }
326+ data = data . substring ( matchingLines ) ;
326327 }
327328 recentDeletions += data . length ;
328329 for ( let i = 0 ; i < data . length ; i ++ ) {
@@ -337,13 +338,21 @@ export class AEDebuggingCache {
337338 return mapping ;
338339 }
339340 /*MD ## Rewriting API MD*/
341+ updateFiles ( files ) {
342+ if ( ! files ) return ;
343+ files . forEach ( file => this . changedFiles . add ( file ) ) ;
344+ this . debouncedUpdateDebuggingViews ( ) ;
345+ }
346+
340347 async updateDebggingViews ( ) {
341348 for ( let i = 0 ; i < this . registeredDebuggingViews . length ; i ++ ) {
342- if ( ! ( await this . registeredDebuggingViews [ i ] ( ) ) ) {
349+ if ( ! [ ...this . changedFiles ] . some ( file => file . includes ( this . registeredDebuggingViews [ i ] . url ) ) ) continue ;
350+ if ( ! ( await this . registeredDebuggingViews [ i ] . callback ( ) ) ) {
343351 this . registeredDebuggingViews . splice ( i , 1 ) ;
344352 i -- ;
345353 }
346354 }
355+ this . changedFiles = new Set ( ) ;
347356 }
348357
349358 async getDependencyTriplesForFile ( url ) {
@@ -369,6 +378,9 @@ export class AEDebuggingCache {
369378 return result ;
370379 }
371380}
381+
382+ async function relatedFiles ( dependencies , aexprs ) { }
383+
372384export const DebuggingCache = new AEDebuggingCache ( ) ;
373385
374386const DependenciesToAExprs = {
@@ -377,12 +389,17 @@ const DependenciesToAExprs = {
377389
378390 associate ( dep , aexpr ) {
379391 const location = aexpr . meta ( ) . get ( "location" ) ;
380- if ( location && location . file ) {
392+ if ( location && location . file ) {
381393 this . _AEsPerFile . getOrCreate ( location . file , ( ) => new Set ( ) ) . add ( aexpr ) ;
382394 }
383395 this . _depsToAExprs . associate ( dep , aexpr ) ;
384396 dep . updateTracking ( ) ;
385- DebuggingCache . debouncedUpdateDebuggingViews ( ) ;
397+
398+ // Track affected files
399+ DebuggingCache . updateFiles ( [ location . file ] ) ;
400+ for ( const hook of HooksToDependencies . getHooksForDep ( dep ) ) {
401+ hook . getLocations ( ) . then ( locations => DebuggingCache . updateFiles ( locations . map ( loc => loc . file ) ) ) ;
402+ }
386403 } ,
387404
388405 disconnectAllForAExpr ( aexpr ) {
@@ -393,7 +410,14 @@ const DependenciesToAExprs = {
393410 const deps = this . getDepsForAExpr ( aexpr ) ;
394411 this . _depsToAExprs . removeAllLeftFor ( aexpr ) ;
395412 deps . forEach ( dep => dep . updateTracking ( ) ) ;
396- DebuggingCache . debouncedUpdateDebuggingViews ( ) ;
413+
414+ // Track affected files
415+ DebuggingCache . updateFiles ( [ location . file ] ) ;
416+ for ( const dep of DependenciesToAExprs . getDepsForAExpr ( aexpr ) ) {
417+ for ( const hook of HooksToDependencies . getHooksForDep ( dep ) ) {
418+ hook . getLocations ( ) . then ( locations => DebuggingCache . updateFiles ( locations . map ( loc => loc . file ) ) ) ;
419+ }
420+ }
397421 } ,
398422
399423 getAEsInFile ( url ) {
@@ -431,12 +455,22 @@ const HooksToDependencies = {
431455
432456 associate ( hook , dep ) {
433457 this . _hooksToDeps . associate ( hook , dep ) ;
434- DebuggingCache . debouncedUpdateDebuggingViews ( ) ;
458+
459+ // Track affected files
460+ hook . getLocations ( ) . then ( locations => DebuggingCache . updateFiles ( locations . map ( loc => loc . file ) ) ) ;
461+ for ( const ae of DependenciesToAExprs . getAExprsForDep ( dep ) ) {
462+ DebuggingCache . updateFiles ( [ ae . meta ( ) . get ( "location" ) . file ] ) ;
463+ }
435464 } ,
436465
437466 remove ( hook , dep ) {
438467 this . _hooksToDeps . remove ( hook , dep ) ;
439- DebuggingCache . debouncedUpdateDebuggingViews ( ) ;
468+
469+ // Track affected files
470+ hook . getLocations ( ) . then ( locations => DebuggingCache . updateFiles ( locations . map ( loc => loc . file ) ) ) ;
471+ for ( const ae of DependenciesToAExprs . getAExprsForDep ( dep ) ) {
472+ DebuggingCache . updateFiles ( [ ae . meta ( ) . get ( "location" ) . file ] ) ;
473+ }
440474 } ,
441475
442476 async getHooksInFile ( url ) {
@@ -453,7 +487,14 @@ const HooksToDependencies = {
453487
454488 disconnectAllForDependency ( dep ) {
455489 this . _hooksToDeps . removeAllLeftFor ( dep ) ;
456- DebuggingCache . debouncedUpdateDebuggingViews ( ) ;
490+
491+ // Track affected files
492+ for ( const hook of HooksToDependencies . getHooksForDep ( dep ) ) {
493+ hook . getLocations ( ) . then ( locations => DebuggingCache . updateFiles ( locations . map ( loc => loc . file ) ) ) ;
494+ }
495+ for ( const ae of DependenciesToAExprs . getAExprsForDep ( dep ) ) {
496+ DebuggingCache . updateFiles ( [ ae . meta ( ) . get ( "location" ) . file ] ) ;
497+ }
457498 } ,
458499
459500 getDepsForHook ( hook ) {
@@ -516,6 +557,7 @@ class Hook {
516557 }
517558
518559 addLocation ( location ) {
560+ if ( ! location ) return ;
519561 if ( ! this . locations . some ( loc => _ . isEqual ( loc , location ) ) ) {
520562 this . locations . push ( location ) ;
521563 }
@@ -529,6 +571,13 @@ class Hook {
529571
530572 notifyDependencies ( ) {
531573 HooksToDependencies . getDepsForHook ( this ) . forEach ( dep => dep . notifyAExprs ( ) ) ;
574+
575+ this . getLocations ( ) . then ( locations => DebuggingCache . updateFiles ( locations . map ( loc => loc . file ) ) ) ;
576+ for ( const dep of HooksToDependencies . getDepsForHook ( this ) ) {
577+ for ( const ae of DependenciesToAExprs . getAExprsForDep ( dep ) ) {
578+ DebuggingCache . updateFiles ( [ ae . meta ( ) . get ( "location" ) . file ] ) ;
579+ }
580+ }
532581 }
533582}
534583
@@ -877,23 +926,20 @@ class TracingHandler {
877926 if ( ! hook ) return ;
878927 hook . addLocation ( location || TracingHandler . findRegistrationLocation ( ) ) ;
879928 hook . notifyDependencies ( ) ;
880- DebuggingCache . debouncedUpdateDebuggingViews ( ) ;
881929 }
882930
883931 static globalUpdated ( globalName , location ) {
884932 const hook = SourceCodeHook . get ( globalRef , globalName ) ;
885933 if ( ! hook ) return ;
886934 hook . addLocation ( location || TracingHandler . findRegistrationLocation ( ) ) ;
887935 hook . notifyDependencies ( ) ;
888- DebuggingCache . debouncedUpdateDebuggingViews ( ) ;
889936 }
890937
891938 static localUpdated ( scope , varName , location ) {
892939 const hook = SourceCodeHook . get ( scope , varName ) ;
893940 if ( ! hook ) return ;
894941 hook . addLocation ( location || TracingHandler . findRegistrationLocation ( ) ) ;
895942 hook . notifyDependencies ( ) ;
896- DebuggingCache . debouncedUpdateDebuggingViews ( ) ;
897943 }
898944
899945 static async findRegistrationLocation ( ) {
0 commit comments