@@ -39,7 +39,12 @@ import type {
39
39
DocumentDirtyIdleTriggerEvent ,
40
40
DocumentDirtyStateChangeEvent ,
41
41
} 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' ;
43
48
import { getEditorCorrelationKey } from './annotationProvider' ;
44
49
import type { ChangesAnnotationContext } from './gutterChangesAnnotationProvider' ;
45
50
@@ -177,10 +182,8 @@ export class FileAnnotationController implements Disposable {
177
182
178
183
const provider = this . getProvider ( editor ) ;
179
184
if ( provider == null ) {
180
- void setContext ( 'gitlens:annotationStatus' , undefined ) ;
181
185
void this . detachKeyboardHook ( ) ;
182
186
} else {
183
- void setContext ( 'gitlens:annotationStatus' , provider . statusContextValue ) ;
184
187
void this . attachKeyboardHook ( ) ;
185
188
}
186
189
}
@@ -201,8 +204,11 @@ export class FileAnnotationController implements Disposable {
201
204
void this . clearCore ( getEditorCorrelationKey ( editor ) ) ;
202
205
}
203
206
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 ;
206
212
207
213
const editor = window . activeTextEditor ;
208
214
if ( editor == null ) return ;
@@ -292,7 +298,8 @@ export class FileAnnotationController implements Disposable {
292
298
if ( provider == null ) return undefined ;
293
299
294
300
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 ;
296
303
297
304
return provider . annotationType ;
298
305
}
@@ -320,6 +327,52 @@ export class FileAnnotationController implements Disposable {
320
327
debouncedRestore ( editor ) ;
321
328
}
322
329
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
+
323
376
async show ( editor : TextEditor | undefined , type : FileAnnotationType , context ?: AnnotationContext ) : Promise < boolean > ;
324
377
async show ( editor : TextEditor | undefined , type : 'changes' , context ?: ChangesAnnotationContext ) : Promise < boolean > ;
325
378
@log < FileAnnotationController [ 'show' ] > ( {
@@ -362,7 +415,8 @@ export class FileAnnotationController implements Disposable {
362
415
this . _editor = editor ;
363
416
364
417
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 ;
366
420
367
421
const currentProvider = this . getProvider ( editor ) ;
368
422
if ( currentProvider ?. annotationType === type ) {
@@ -373,14 +427,12 @@ export class FileAnnotationController implements Disposable {
373
427
const provider = await window . withProgress (
374
428
{ location : ProgressLocation . Window } ,
375
429
async ( progress : Progress < { message : string } > ) => {
376
- await setContext ( 'gitlens:annotationStatus' , 'computing' ) ;
430
+ void this . onProviderEditorStatusChanged ( editor , 'computing' ) ;
377
431
378
432
const computingAnnotations = this . showAnnotationsCore ( currentProvider , editor , type , context , progress ) ;
379
- const provider = await computingAnnotations ;
433
+ void ( await computingAnnotations ) ;
380
434
381
- if ( editor === this . _editor ) {
382
- await setContext ( 'gitlens:annotationStatus' , provider ?. statusContextValue ) ;
383
- }
435
+ void this . onProviderEditorStatusChanged ( editor , 'computed' ) ;
384
436
385
437
return computingAnnotations ;
386
438
} ,
@@ -415,7 +467,8 @@ export class FileAnnotationController implements Disposable {
415
467
) : Promise < boolean > {
416
468
if ( editor != null && this . _toggleModes . get ( type ) === 'file' ) {
417
469
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 ) {
419
472
return false ;
420
473
}
421
474
}
@@ -484,7 +537,10 @@ export class FileAnnotationController implements Disposable {
484
537
provider . dispose ( ) ;
485
538
486
539
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
+
488
544
await this . detachKeyboardHook ( ) ;
489
545
}
490
546
@@ -542,21 +598,36 @@ export class FileAnnotationController implements Disposable {
542
598
const { GutterBlameAnnotationProvider } = await import (
543
599
/* webpackChunkName: "annotations" */ './gutterBlameAnnotationProvider'
544
600
) ;
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
+ ) ;
546
607
break ;
547
608
}
548
609
case 'changes' : {
549
610
const { GutterChangesAnnotationProvider } = await import (
550
611
/* webpackChunkName: "annotations" */ './gutterChangesAnnotationProvider'
551
612
) ;
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
+ ) ;
553
619
break ;
554
620
}
555
621
case 'heatmap' : {
556
622
const { GutterHeatmapBlameAnnotationProvider } = await import (
557
623
/* webpackChunkName: "annotations" */ './gutterHeatmapBlameAnnotationProvider'
558
624
) ;
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
+ ) ;
560
631
break ;
561
632
}
562
633
}
0 commit comments