Commit b7553b8e authored by Tomas Vik (OOO back on 2026-08-31)'s avatar Tomas Vik (OOO back on 2026-08-31) 🌴
Browse files

fix: draft comments disappear after refresh

parent 866bd315
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -121,15 +121,15 @@ describe('MrItemModel', () => {
      expect(commentController.commentingRangeProvider).toBeInstanceOf(CommentingRangeProvider);
    });

    it('when we create comment controller for the same MR, we dispose the previously created controller', async () => {
    it('keeps the same commentController regardless how many times we call getChildren', async () => {
      await item.getChildren();

      expect(commentController.dispose).not.toHaveBeenCalled();
      expect(createCommentControllerMock).toHaveBeenCalledTimes(1);

      // simulates another MR item opening the same MR
      await item.getChildren();

      expect(commentController.dispose).toHaveBeenCalled();
      expect(createCommentControllerMock).toHaveBeenCalledTimes(1);
      expect(commentController.dispose).not.toHaveBeenCalled();
    });
  });
});
+5 −1
Original line number Diff line number Diff line
@@ -46,6 +46,8 @@ const uriForDiscussion = (
};

export class MrItemModel extends ItemModel {
  private cachedChildren?: vscode.TreeItem[];

  constructor(readonly mr: RestMr, readonly repository: WrappedRepository) {
    super();
  }
@@ -96,6 +98,7 @@ export class MrItemModel extends ItemModel {
  }

  async getChildren(): Promise<vscode.TreeItem[]> {
    if (this.cachedChildren) return this.cachedChildren; // don't initialize comments twice
    const { mrVersion } = await this.repository.reloadMr(this.mr);
    const discussions = await this.getMrDiscussions();

@@ -110,7 +113,8 @@ export class MrItemModel extends ItemModel {
          allUrisWithComments.includes(uri.toString()),
        ),
    );
    return [this.overviewItem, ...changedFiles];
    this.cachedChildren = [this.overviewItem, ...changedFiles];
    return this.cachedChildren;
  }

  private async addAllCommentsToVsCode(