|
5 | 5 | 'use strict'; |
6 | 6 |
|
7 | 7 | import * as vscode from 'vscode'; |
| 8 | +import { Repository } from './api/api'; |
8 | 9 | import Logger from './common/logger'; |
9 | 10 | import { GHPRComment, GHPRCommentThread, TemporaryComment } from './github/prComment'; |
10 | 11 |
|
@@ -34,32 +35,38 @@ export namespace CommentReply { |
34 | 35 | } |
35 | 36 | } |
36 | 37 |
|
37 | | -const commentHandlers = new Map<string, CommentHandler>(); |
| 38 | +const commentHandlers = new Map<string, { handler: CommentHandler, repoRootUri: string }>(); |
38 | 39 |
|
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() }); |
41 | 42 | } |
42 | 43 |
|
43 | 44 | export function unregisterCommentHandler(key: string) { |
44 | 45 | commentHandlers.delete(key); |
45 | 46 | } |
46 | 47 |
|
47 | 48 | export function resolveCommentHandler(commentThread: GHPRCommentThread): CommentHandler | undefined { |
| 49 | + const possibleHandlers: { handler: CommentHandler, repoRootUri: string }[] = []; |
48 | 50 | for (const commentHandler of commentHandlers.values()) { |
49 | | - if (commentHandler.hasCommentThread(commentThread)) { |
50 | | - return commentHandler; |
| 51 | + if (commentHandler.handler.hasCommentThread(commentThread)) { |
| 52 | + possibleHandlers.push(commentHandler); |
51 | 53 | } |
52 | 54 | } |
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 | + } |
54 | 61 | Logger.warn(`Unable to find handler for comment thread ${commentThread.gitHubThreadId}`); |
55 | 62 |
|
56 | 63 | return; |
57 | 64 | } |
58 | 65 |
|
59 | 66 | export function findActiveHandler() { |
60 | 67 | for (const commentHandler of commentHandlers.values()) { |
61 | | - if (commentHandler.commentController.activeCommentThread) { |
62 | | - return commentHandler; |
| 68 | + if (commentHandler.handler.commentController.activeCommentThread) { |
| 69 | + return commentHandler.handler; |
63 | 70 | } |
64 | 71 | } |
65 | 72 | } |
0 commit comments