Skip to content

Commit 84d958f

Browse files
authored
Comments not possible to save within a submodule (#6424)
Fixes #6096
1 parent 8040a44 commit 84d958f

3 files changed

Lines changed: 17 additions & 10 deletions

File tree

src/commentHandlerResolver.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
'use strict';
66

77
import * as vscode from 'vscode';
8+
import { Repository } from './api/api';
89
import Logger from './common/logger';
910
import { GHPRComment, GHPRCommentThread, TemporaryComment } from './github/prComment';
1011

@@ -34,32 +35,38 @@ export namespace CommentReply {
3435
}
3536
}
3637

37-
const commentHandlers = new Map<string, CommentHandler>();
38+
const commentHandlers = new Map<string, { handler: CommentHandler, repoRootUri: string }>();
3839

39-
export function registerCommentHandler(key: string, commentHandler: CommentHandler) {
40-
commentHandlers.set(key, commentHandler);
40+
export function registerCommentHandler(key: string, commentHandler: CommentHandler, repository: Repository) {
41+
commentHandlers.set(key, { handler: commentHandler, repoRootUri: repository.rootUri.toString() });
4142
}
4243

4344
export function unregisterCommentHandler(key: string) {
4445
commentHandlers.delete(key);
4546
}
4647

4748
export function resolveCommentHandler(commentThread: GHPRCommentThread): CommentHandler | undefined {
49+
const possibleHandlers: { handler: CommentHandler, repoRootUri: string }[] = [];
4850
for (const commentHandler of commentHandlers.values()) {
49-
if (commentHandler.hasCommentThread(commentThread)) {
50-
return commentHandler;
51+
if (commentHandler.handler.hasCommentThread(commentThread)) {
52+
possibleHandlers.push(commentHandler);
5153
}
5254
}
53-
55+
if (possibleHandlers.length > 0) {
56+
possibleHandlers.sort((a, b) => {
57+
return b.repoRootUri.length - a.repoRootUri.length;
58+
});
59+
return possibleHandlers[0].handler;
60+
}
5461
Logger.warn(`Unable to find handler for comment thread ${commentThread.gitHubThreadId}`);
5562

5663
return;
5764
}
5865

5966
export function findActiveHandler() {
6067
for (const commentHandler of commentHandlers.values()) {
61-
if (commentHandler.commentController.activeCommentThread) {
62-
return commentHandler;
68+
if (commentHandler.handler.commentController.activeCommentThread) {
69+
return commentHandler.handler;
6370
}
6471
}
6572
}

src/view/pullRequestCommentController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class PullRequestCommentController extends CommentControllerBase implemen
4646
this._commentController = commentController;
4747
this._context = folderRepoManager.context;
4848
this._commentHandlerId = uuid();
49-
registerCommentHandler(this._commentHandlerId, this);
49+
registerCommentHandler(this._commentHandlerId, this, folderRepoManager.repository);
5050

5151
if (this.pullRequestModel.reviewThreadsCacheReady) {
5252
this.initializeThreadsInOpenEditors().then(() => {

src/view/reviewCommentController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class ReviewCommentController extends CommentControllerBase
8282
this._localToDispose.push(this._folderRepoManager.onDidChangeActivePullRequest(() => this.updateResourcesWithCommentingRanges()));
8383
this._localToDispose.push(this._commentController);
8484
this._commentHandlerId = uuid();
85-
registerCommentHandler(this._commentHandlerId, this);
85+
registerCommentHandler(this._commentHandlerId, this, _repository);
8686
}
8787

8888
// #region initialize

0 commit comments

Comments
 (0)