Skip to content

Commit 5dd6c8b

Browse files
committed
Make sure comments are always set on view
Fixes microsoft#143831
1 parent cb0f441 commit 5dd6c8b

File tree

1 file changed

+40
-17
lines changed

1 file changed

+40
-17
lines changed

src/vs/workbench/api/browser/mainThreadComments.ts

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,8 @@ export class MainThreadComments extends Disposable implements MainThreadComments
409409
const commentsPanelAlreadyConstructed = !!this._viewDescriptorService.getViewDescriptorById(COMMENTS_VIEW_ID);
410410
if (!commentsPanelAlreadyConstructed) {
411411
this.registerView(commentsPanelAlreadyConstructed);
412-
this.registerViewOpenedListener(commentsPanelAlreadyConstructed);
413412
}
413+
this.registerViewListeners(commentsPanelAlreadyConstructed);
414414
this._commentService.setWorkspaceComments(String(handle), []);
415415
}
416416

@@ -513,24 +513,22 @@ export class MainThreadComments extends Disposable implements MainThreadComments
513513
}
514514
}
515515

516-
/**
517-
* If the comments view has never been opened, the constructor for it has not yet run so it has
518-
* no listeners for comment threads being set or updated. Listen for the view opening for the
519-
* first time and send it comments then.
520-
*/
521-
private registerViewOpenedListener(commentsPanelAlreadyConstructed: boolean) {
522-
if (!commentsPanelAlreadyConstructed && !this._openViewListener) {
523-
this._openViewListener = this._viewsService.onDidChangeViewVisibility(e => {
524-
if (e.id === COMMENTS_VIEW_ID && e.visible) {
525-
[...this._commentControllers.keys()].forEach(handle => {
526-
let threads = this._commentControllers.get(handle)!.getAllComments();
516+
private setComments() {
517+
[...this._commentControllers.keys()].forEach(handle => {
518+
let threads = this._commentControllers.get(handle)!.getAllComments();
527519

528-
if (threads.length) {
529-
const providerId = this.getHandler(handle);
530-
this._commentService.setWorkspaceComments(providerId, threads);
531-
}
532-
});
520+
if (threads.length) {
521+
const providerId = this.getHandler(handle);
522+
this._commentService.setWorkspaceComments(providerId, threads);
523+
}
524+
});
525+
}
533526

527+
private registerViewOpenedListener() {
528+
if (!this._openViewListener) {
529+
this._openViewListener = this._viewsService.onDidChangeViewVisibility(e => {
530+
if (e.id === COMMENTS_VIEW_ID && e.visible) {
531+
this.setComments();
534532
if (this._openViewListener) {
535533
this._openViewListener.dispose();
536534
this._openViewListener = null;
@@ -540,6 +538,31 @@ export class MainThreadComments extends Disposable implements MainThreadComments
540538
}
541539
}
542540

541+
/**
542+
* If the comments view has never been opened, the constructor for it has not yet run so it has
543+
* no listeners for comment threads being set or updated. Listen for the view opening for the
544+
* first time and send it comments then.
545+
*/
546+
private registerViewListeners(commentsPanelAlreadyConstructed: boolean) {
547+
if (!commentsPanelAlreadyConstructed) {
548+
this.registerViewOpenedListener();
549+
}
550+
551+
this._register(this._viewDescriptorService.onDidChangeContainer(e => {
552+
if (e.views.find(view => view.id === COMMENTS_VIEW_ID)) {
553+
this.setComments();
554+
this.registerViewOpenedListener();
555+
}
556+
}));
557+
this._register(this._viewDescriptorService.onDidChangeContainerLocation(e => {
558+
const commentsContainer = this._viewDescriptorService.getViewContainerByViewId(COMMENTS_VIEW_ID);
559+
if (e.viewContainer.id === commentsContainer?.id) {
560+
this.setComments();
561+
this.registerViewOpenedListener();
562+
}
563+
}));
564+
}
565+
543566
private getHandler(handle: number) {
544567
if (!this._handlers.has(handle)) {
545568
throw new Error('Unknown handler');

0 commit comments

Comments
 (0)