@@ -39,7 +39,12 @@ import type {
3939 DocumentDirtyIdleTriggerEvent ,
4040 DocumentDirtyStateChangeEvent ,
4141} from '../trackers/documentTracker' ;
42- import type { AnnotationContext , AnnotationProviderBase , TextEditorCorrelationKey } from './annotationProvider' ;
42+ import type {
43+ AnnotationContext ,
44+ AnnotationProviderBase ,
45+ AnnotationStatus ,
46+ TextEditorCorrelationKey ,
47+ } from './annotationProvider' ;
4348import { getEditorCorrelationKey } from './annotationProvider' ;
4449import type { ChangesAnnotationContext } from './gutterChangesAnnotationProvider' ;
4550
@@ -177,10 +182,8 @@ export class FileAnnotationController implements Disposable {
177182
178183 const provider = this . getProvider ( editor ) ;
179184 if ( provider == null ) {
180- void setContext ( 'gitlens:annotationStatus' , undefined ) ;
181185 void this . detachKeyboardHook ( ) ;
182186 } else {
183- void setContext ( 'gitlens:annotationStatus' , provider . statusContextValue ) ;
184187 void this . attachKeyboardHook ( ) ;
185188 }
186189 }
@@ -201,8 +204,11 @@ export class FileAnnotationController implements Disposable {
201204 void this . clearCore ( getEditorCorrelationKey ( editor ) ) ;
202205 }
203206
204- private onDirtyIdleTriggered ( e : DocumentDirtyIdleTriggerEvent ) {
205- if ( ! e . document . isBlameable || ! configuration . get ( 'fileAnnotations.preserveWhileEditing' ) ) return ;
207+ private async onDirtyIdleTriggered ( e : DocumentDirtyIdleTriggerEvent ) {
208+ if ( ! configuration . get ( 'fileAnnotations.preserveWhileEditing' ) ) return ;
209+
210+ const status = await e . document . getStatus ( ) ;
211+ if ( ! status . blameable ) return ;
206212
207213 const editor = window . activeTextEditor ;
208214 if ( editor == null ) return ;
@@ -292,7 +298,8 @@ export class FileAnnotationController implements Disposable {
292298 if ( provider == null ) return undefined ;
293299
294300 const trackedDocument = await this . container . documentTracker . get ( editor ! . document ) ;
295- if ( ! trackedDocument ?. isBlameable ) return undefined ;
301+ const status = await trackedDocument ?. getStatus ( ) ;
302+ if ( ! status ?. blameable ) return undefined ;
296303
297304 return provider . annotationType ;
298305 }
@@ -320,6 +327,52 @@ export class FileAnnotationController implements Disposable {
320327 debouncedRestore ( editor ) ;
321328 }
322329
330+ private readonly _annotatedUris = new Set < string > ( ) ;
331+ private readonly _computingUris = new Set < string > ( ) ;
332+
333+ async onProviderEditorStatusChanged ( editor : TextEditor | undefined , status : AnnotationStatus | undefined ) {
334+ if ( editor == null ) return ;
335+
336+ let windowStatus ;
337+
338+ if ( this . isInWindowToggle ( ) ) {
339+ windowStatus = status ;
340+ this . _annotatedUris . clear ( ) ;
341+ this . _computingUris . clear ( ) ;
342+ } else {
343+ windowStatus = undefined ;
344+ const uri = editor . document . uri . toString ( ) ;
345+
346+ switch ( status ) {
347+ case 'computing' :
348+ this . _annotatedUris . add ( uri ) ;
349+ this . _computingUris . add ( uri ) ;
350+ break ;
351+ case 'computed' :
352+ this . _annotatedUris . add ( uri ) ;
353+ this . _computingUris . delete ( uri ) ;
354+ break ;
355+ default :
356+ this . _annotatedUris . delete ( uri ) ;
357+ this . _computingUris . delete ( uri ) ;
358+ break ;
359+ }
360+
361+ const provider = this . getProvider ( editor ) ;
362+ if ( provider == null ) {
363+ this . _annotatedUris . delete ( uri ) ;
364+ } else {
365+ this . _annotatedUris . add ( uri ) ;
366+ }
367+ }
368+
369+ await Promise . allSettled ( [
370+ setContext ( 'gitlens:window:annotated' , windowStatus ) ,
371+ setContext ( 'gitlens:tabs:annotated:computing' , [ ...this . _computingUris ] ) ,
372+ setContext ( 'gitlens:tabs:annotated' , [ ...this . _annotatedUris ] ) ,
373+ ] ) ;
374+ }
375+
323376 async show ( editor : TextEditor | undefined , type : FileAnnotationType , context ?: AnnotationContext ) : Promise < boolean > ;
324377 async show ( editor : TextEditor | undefined , type : 'changes' , context ?: ChangesAnnotationContext ) : Promise < boolean > ;
325378 @log < FileAnnotationController [ 'show' ] > ( {
@@ -362,7 +415,8 @@ export class FileAnnotationController implements Disposable {
362415 this . _editor = editor ;
363416
364417 const trackedDocument = await this . container . documentTracker . getOrAdd ( editor . document ) ;
365- if ( ! trackedDocument . isBlameable ) return false ;
418+ const status = await trackedDocument ?. getStatus ( ) ;
419+ if ( ! status ?. blameable ) return false ;
366420
367421 const currentProvider = this . getProvider ( editor ) ;
368422 if ( currentProvider ?. annotationType === type ) {
@@ -373,14 +427,12 @@ export class FileAnnotationController implements Disposable {
373427 const provider = await window . withProgress (
374428 { location : ProgressLocation . Window } ,
375429 async ( progress : Progress < { message : string } > ) => {
376- await setContext ( 'gitlens:annotationStatus' , 'computing' ) ;
430+ void this . onProviderEditorStatusChanged ( editor , 'computing' ) ;
377431
378432 const computingAnnotations = this . showAnnotationsCore ( currentProvider , editor , type , context , progress ) ;
379- const provider = await computingAnnotations ;
433+ void ( await computingAnnotations ) ;
380434
381- if ( editor === this . _editor ) {
382- await setContext ( 'gitlens:annotationStatus' , provider ?. statusContextValue ) ;
383- }
435+ void this . onProviderEditorStatusChanged ( editor , 'computed' ) ;
384436
385437 return computingAnnotations ;
386438 } ,
@@ -415,7 +467,8 @@ export class FileAnnotationController implements Disposable {
415467 ) : Promise < boolean > {
416468 if ( editor != null && this . _toggleModes . get ( type ) === 'file' ) {
417469 const trackedDocument = await this . container . documentTracker . getOrAdd ( editor . document ) ;
418- if ( ( type === 'changes' && ! trackedDocument . isTracked ) || ! trackedDocument . isBlameable ) {
470+ const status = await trackedDocument ?. getStatus ( ) ;
471+ if ( ( type === 'changes' && ! status ?. tracked ) || ! status ?. blameable ) {
419472 return false ;
420473 }
421474 }
@@ -484,7 +537,10 @@ export class FileAnnotationController implements Disposable {
484537 provider . dispose ( ) ;
485538
486539 if ( ! this . _annotationProviders . size || key === getEditorCorrelationKey ( this . _editor ) ) {
487- await setContext ( 'gitlens:annotationStatus' , undefined ) ;
540+ if ( this . _editor != null ) {
541+ void this . onProviderEditorStatusChanged ( this . _editor , undefined ) ;
542+ }
543+
488544 await this . detachKeyboardHook ( ) ;
489545 }
490546
@@ -542,21 +598,36 @@ export class FileAnnotationController implements Disposable {
542598 const { GutterBlameAnnotationProvider } = await import (
543599 /* webpackChunkName: "annotations" */ './gutterBlameAnnotationProvider'
544600 ) ;
545- provider = new GutterBlameAnnotationProvider ( this . container , editor , trackedDocument ) ;
601+ provider = new GutterBlameAnnotationProvider (
602+ this . container ,
603+ e => this . onProviderEditorStatusChanged ( e . editor , e . status ) ,
604+ editor ,
605+ trackedDocument ,
606+ ) ;
546607 break ;
547608 }
548609 case 'changes' : {
549610 const { GutterChangesAnnotationProvider } = await import (
550611 /* webpackChunkName: "annotations" */ './gutterChangesAnnotationProvider'
551612 ) ;
552- provider = new GutterChangesAnnotationProvider ( this . container , editor , trackedDocument ) ;
613+ provider = new GutterChangesAnnotationProvider (
614+ this . container ,
615+ e => this . onProviderEditorStatusChanged ( e . editor , e . status ) ,
616+ editor ,
617+ trackedDocument ,
618+ ) ;
553619 break ;
554620 }
555621 case 'heatmap' : {
556622 const { GutterHeatmapBlameAnnotationProvider } = await import (
557623 /* webpackChunkName: "annotations" */ './gutterHeatmapBlameAnnotationProvider'
558624 ) ;
559- provider = new GutterHeatmapBlameAnnotationProvider ( this . container , editor , trackedDocument ) ;
625+ provider = new GutterHeatmapBlameAnnotationProvider (
626+ this . container ,
627+ e => this . onProviderEditorStatusChanged ( e . editor , e . status ) ,
628+ editor ,
629+ trackedDocument ,
630+ ) ;
560631 break ;
561632 }
562633 }
0 commit comments