@@ -36,6 +36,9 @@ import { CommentsFilters, CommentsFiltersChangeEvent } from 'vs/workbench/contri
36
36
import { Memento , MementoObject } from 'vs/workbench/common/memento' ;
37
37
import { IStorageService , StorageScope , StorageTarget } from 'vs/platform/storage/common/storage' ;
38
38
import { FilterOptions } from 'vs/workbench/contrib/comments/browser/commentsFilterOptions' ;
39
+ import { IActivityService , NumberBadge } from 'vs/workbench/services/activity/common/activity' ;
40
+ import { CommentThreadState } from 'vs/editor/common/languages' ;
41
+ import { IDisposable , MutableDisposable } from 'vs/base/common/lifecycle' ;
39
42
40
43
const CONTEXT_KEY_HAS_COMMENTS = new RawContextKey < boolean > ( 'commentsView.hasComments' , false ) ;
41
44
const VIEW_STORAGE_ID = 'commentsViewState' ;
@@ -47,9 +50,11 @@ export class CommentsPanel extends FilterViewPane implements ICommentsView {
47
50
private messageBoxContainer ! : HTMLElement ;
48
51
private commentsModel ! : CommentsModel ;
49
52
private totalComments : number = 0 ;
53
+ private totalUnresolved = 0 ;
50
54
private readonly hasCommentsContextKey : IContextKey < boolean > ;
51
55
private readonly filter : Filter ;
52
56
readonly filters : CommentsFilters ;
57
+ private readonly activity = this . _register ( new MutableDisposable < IDisposable > ( ) ) ;
53
58
54
59
private currentHeight = 0 ;
55
60
private currentWidth = 0 ;
@@ -73,6 +78,7 @@ export class CommentsPanel extends FilterViewPane implements ICommentsView {
73
78
@ICommentService private readonly commentService : ICommentService ,
74
79
@ITelemetryService telemetryService : ITelemetryService ,
75
80
@IUriIdentityService private readonly uriIdentityService : IUriIdentityService ,
81
+ @IActivityService readonly activityService : IActivityService ,
76
82
@IStorageService readonly storageService : IStorageService
77
83
) {
78
84
const stateMemento = new Memento ( VIEW_STORAGE_ID , storageService ) ;
@@ -97,15 +103,6 @@ export class CommentsPanel extends FilterViewPane implements ICommentsView {
97
103
} , this . contextKeyService ) ) ;
98
104
this . filter = new Filter ( new FilterOptions ( this . filterWidget . getFilterText ( ) , this . filters . showResolved , this . filters . showUnresolved ) ) ;
99
105
100
- this . _register ( this . commentService . onDidSetAllCommentThreads ( e => {
101
- this . totalComments += e . commentThreads . length ;
102
- } ) ) ;
103
-
104
- this . _register ( this . commentService . onDidUpdateCommentThreads ( e => {
105
- this . totalComments += e . added . length ;
106
- this . totalComments -= e . removed . length ;
107
- } ) ) ;
108
-
109
106
this . _register ( this . filters . onDidChange ( ( event : CommentsFiltersChangeEvent ) => {
110
107
if ( event . showResolved || event . showUnresolved ) {
111
108
this . updateFilter ( ) ;
@@ -114,6 +111,16 @@ export class CommentsPanel extends FilterViewPane implements ICommentsView {
114
111
this . _register ( this . filterWidget . onDidChangeFilterText ( ( ) => this . updateFilter ( ) ) ) ;
115
112
}
116
113
114
+ private updateBadge ( unresolved : number ) {
115
+ if ( unresolved === this . totalUnresolved ) {
116
+ return ;
117
+ }
118
+
119
+ this . totalUnresolved = unresolved ;
120
+ const message = nls . localize ( 'totalUnresolvedComments' , '{0} Unresolved Comments' , this . totalUnresolved ) ;
121
+ this . activity . value = this . activityService . showViewActivity ( this . id , { badge : new NumberBadge ( this . totalUnresolved , ( ) => message ) } ) ;
122
+ }
123
+
117
124
override saveState ( ) : void {
118
125
this . viewState [ 'filter' ] = this . filterWidget . getFilterText ( ) ;
119
126
this . viewState [ 'filterHistory' ] = this . filterWidget . getHistory ( ) ;
@@ -389,11 +396,36 @@ export class CommentsPanel extends FilterViewPane implements ICommentsView {
389
396
390
397
private onAllCommentsChanged ( e : IWorkspaceCommentThreadsEvent ) : void {
391
398
this . commentsModel . setCommentThreads ( e . ownerId , e . commentThreads ) ;
399
+
400
+ this . totalComments += e . commentThreads . length ;
401
+
402
+ let unresolved = 0 ;
403
+ for ( const thread of e . commentThreads ) {
404
+ if ( thread . state === CommentThreadState . Unresolved ) {
405
+ unresolved ++ ;
406
+ }
407
+ }
408
+ this . updateBadge ( unresolved ) ;
409
+
392
410
this . refresh ( ) ;
393
411
}
394
412
395
413
private onCommentsUpdated ( e : ICommentThreadChangedEvent ) : void {
396
414
const didUpdate = this . commentsModel . updateCommentThreads ( e ) ;
415
+
416
+ this . totalComments += e . added . length ;
417
+ this . totalComments -= e . removed . length ;
418
+
419
+ let unresolved = 0 ;
420
+ for ( const resource of this . commentsModel . resourceCommentThreads ) {
421
+ for ( const thread of resource . commentThreads ) {
422
+ if ( thread . threadState === CommentThreadState . Unresolved ) {
423
+ unresolved ++ ;
424
+ }
425
+ }
426
+ }
427
+ this . updateBadge ( unresolved ) ;
428
+
397
429
if ( didUpdate ) {
398
430
this . refresh ( ) ;
399
431
}
0 commit comments