@@ -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,23 +389,37 @@ const DependenciesToAExprs = {
377389
378390 associate ( dep , aexpr ) {
379391 const location = aexpr . meta ( ) . get ( "location" ) ;
380- if ( location && location . file ) {
392+ if ( location && location . file ) {
393+ DebuggingCache . updateFiles ( [ location . file ] ) ;
381394 this . _AEsPerFile . getOrCreate ( location . file , ( ) => new Set ( ) ) . add ( aexpr ) ;
382395 }
383396 this . _depsToAExprs . associate ( dep , aexpr ) ;
384397 dep . updateTracking ( ) ;
385- DebuggingCache . debouncedUpdateDebuggingViews ( ) ;
398+
399+ // Track affected files
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 ) {
389406 const location = aexpr . meta ( ) . get ( "location" ) ;
390- if ( location && location . file && this . _AEsPerFile . has ( location . file ) ) {
391- this . _AEsPerFile . get ( location . file ) . delete ( aexpr ) ;
407+ if ( location && location . file ) {
408+ DebuggingCache . updateFiles ( [ location . file ] ) ;
409+ if ( this . _AEsPerFile . has ( location . file ) ) {
410+ this . _AEsPerFile . get ( location . file ) . delete ( aexpr ) ;
411+ }
392412 }
393413 const deps = this . getDepsForAExpr ( aexpr ) ;
394414 this . _depsToAExprs . removeAllLeftFor ( aexpr ) ;
395415 deps . forEach ( dep => dep . updateTracking ( ) ) ;
396- DebuggingCache . debouncedUpdateDebuggingViews ( ) ;
416+
417+ // Track affected files
418+ for ( const dep of DependenciesToAExprs . getDepsForAExpr ( aexpr ) ) {
419+ for ( const hook of HooksToDependencies . getHooksForDep ( dep ) ) {
420+ hook . getLocations ( ) . then ( locations => DebuggingCache . updateFiles ( locations . map ( loc => loc . file ) ) ) ;
421+ }
422+ }
397423 } ,
398424
399425 getAEsInFile ( url ) {
@@ -431,12 +457,26 @@ const HooksToDependencies = {
431457
432458 associate ( hook , dep ) {
433459 this . _hooksToDeps . associate ( hook , dep ) ;
434- DebuggingCache . debouncedUpdateDebuggingViews ( ) ;
460+
461+ // Track affected files
462+ hook . getLocations ( ) . then ( locations => DebuggingCache . updateFiles ( locations . map ( loc => loc . file ) ) ) ;
463+ for ( const ae of DependenciesToAExprs . getAExprsForDep ( dep ) ) {
464+ if ( ae . meta ( ) . has ( "location" ) ) {
465+ DebuggingCache . updateFiles ( [ ae . meta ( ) . get ( "location" ) . file ] ) ;
466+ }
467+ }
435468 } ,
436469
437470 remove ( hook , dep ) {
438471 this . _hooksToDeps . remove ( hook , dep ) ;
439- DebuggingCache . debouncedUpdateDebuggingViews ( ) ;
472+
473+ // Track affected files
474+ hook . getLocations ( ) . then ( locations => DebuggingCache . updateFiles ( locations . map ( loc => loc . file ) ) ) ;
475+ for ( const ae of DependenciesToAExprs . getAExprsForDep ( dep ) ) {
476+ if ( ae . meta ( ) . has ( "location" ) ) {
477+ DebuggingCache . updateFiles ( [ ae . meta ( ) . get ( "location" ) . file ] ) ;
478+ }
479+ }
440480 } ,
441481
442482 async getHooksInFile ( url ) {
@@ -453,7 +493,16 @@ const HooksToDependencies = {
453493
454494 disconnectAllForDependency ( dep ) {
455495 this . _hooksToDeps . removeAllLeftFor ( dep ) ;
456- DebuggingCache . debouncedUpdateDebuggingViews ( ) ;
496+
497+ // Track affected files
498+ for ( const hook of HooksToDependencies . getHooksForDep ( dep ) ) {
499+ hook . getLocations ( ) . then ( locations => DebuggingCache . updateFiles ( locations . map ( loc => loc . file ) ) ) ;
500+ }
501+ for ( const ae of DependenciesToAExprs . getAExprsForDep ( dep ) ) {
502+ if ( ae . meta ( ) . has ( "location" ) ) {
503+ DebuggingCache . updateFiles ( [ ae . meta ( ) . get ( "location" ) . file ] ) ;
504+ }
505+ }
457506 } ,
458507
459508 getDepsForHook ( hook ) {
@@ -516,6 +565,7 @@ class Hook {
516565 }
517566
518567 addLocation ( location ) {
568+ if ( ! location ) return ;
519569 if ( ! this . locations . some ( loc => _ . isEqual ( loc , location ) ) ) {
520570 this . locations . push ( location ) ;
521571 }
@@ -529,6 +579,15 @@ class Hook {
529579
530580 notifyDependencies ( ) {
531581 HooksToDependencies . getDepsForHook ( this ) . forEach ( dep => dep . notifyAExprs ( ) ) ;
582+
583+ this . getLocations ( ) . then ( locations => DebuggingCache . updateFiles ( locations . map ( loc => loc . file ) ) ) ;
584+ for ( const dep of HooksToDependencies . getDepsForHook ( this ) ) {
585+ for ( const ae of DependenciesToAExprs . getAExprsForDep ( dep ) ) {
586+ if ( ae . meta ( ) . has ( "location" ) ) {
587+ DebuggingCache . updateFiles ( [ ae . meta ( ) . get ( "location" ) . file ] ) ;
588+ }
589+ }
590+ }
532591 }
533592}
534593
@@ -877,23 +936,20 @@ class TracingHandler {
877936 if ( ! hook ) return ;
878937 hook . addLocation ( location || TracingHandler . findRegistrationLocation ( ) ) ;
879938 hook . notifyDependencies ( ) ;
880- DebuggingCache . debouncedUpdateDebuggingViews ( ) ;
881939 }
882940
883941 static globalUpdated ( globalName , location ) {
884942 const hook = SourceCodeHook . get ( globalRef , globalName ) ;
885943 if ( ! hook ) return ;
886944 hook . addLocation ( location || TracingHandler . findRegistrationLocation ( ) ) ;
887945 hook . notifyDependencies ( ) ;
888- DebuggingCache . debouncedUpdateDebuggingViews ( ) ;
889946 }
890947
891948 static localUpdated ( scope , varName , location ) {
892949 const hook = SourceCodeHook . get ( scope , varName ) ;
893950 if ( ! hook ) return ;
894951 hook . addLocation ( location || TracingHandler . findRegistrationLocation ( ) ) ;
895952 hook . notifyDependencies ( ) ;
896- DebuggingCache . debouncedUpdateDebuggingViews ( ) ;
897953 }
898954
899955 static async findRegistrationLocation ( ) {
0 commit comments