Skip to content

Commit fc0a05a

Browse files
authored
Comments sometimes not resolvable. (#6759)
Fixes #6702
1 parent 43b1266 commit fc0a05a

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

src/github/utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,11 @@ export function updateThread(context: vscode.ExtensionContext, vscodeThread: GHP
179179
}
180180

181181
const newResolvedState = isResolvedToResolvedState(reviewThread.isResolved);
182-
if (vscodeThread.state?.resolved !== newResolvedState) {
182+
const newApplicabilityState = reviewThread.isOutdated ? vscode.CommentThreadApplicability.Outdated : vscode.CommentThreadApplicability.Current;
183+
if ((vscodeThread.state?.resolved !== newResolvedState) || (vscodeThread.state?.applicability !== newApplicabilityState)) {
183184
vscodeThread.state = {
184185
resolved: newResolvedState,
185-
applicability: vscodeThread.state?.applicability
186+
applicability: newApplicabilityState
186187
};
187188
}
188189
vscodeThread.collapsibleState = getCommentCollapsibleState(reviewThread, expand);
@@ -201,6 +202,7 @@ export function updateThread(context: vscode.ExtensionContext, vscodeThread: GHP
201202
} else {
202203
vscodeThread.comments = reviewThread.comments.map(c => new GHPRComment(context, c, vscodeThread, githubRepositories));
203204
}
205+
204206
updateCommentThreadLabel(vscodeThread);
205207
}
206208

src/view/reviewCommentController.ts

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -325,30 +325,18 @@ export class ReviewCommentController extends CommentControllerBase implements Co
325325
});
326326

327327
e.changed.forEach(thread => {
328-
const threadMap = thread.isOutdated
329-
? this._obsoleteFileChangeCommentThreads
330-
: thread.diffSide === DiffSide.RIGHT
331-
? this._workspaceFileChangeCommentThreads
332-
: this._reviewSchemeFileChangeCommentThreads;
333-
334-
const index = threadMap[thread.path] ? threadMap[thread.path].findIndex(t => t.gitHubThreadId === thread.id) : -1;
335-
if (index > -1) {
336-
const matchingThread = threadMap[thread.path][index];
328+
const match = this._findMatchingThread(thread);
329+
if (match.index > -1) {
330+
const matchingThread = match.threadMap[thread.path][match.index];
337331
updateThread(this._context, matchingThread, thread, githubRepositories);
338332
}
339333
});
340334

341335
e.removed.forEach(thread => {
342-
const threadMap = thread.isOutdated
343-
? this._obsoleteFileChangeCommentThreads
344-
: thread.diffSide === DiffSide.RIGHT
345-
? this._workspaceFileChangeCommentThreads
346-
: this._reviewSchemeFileChangeCommentThreads;
347-
348-
const index = threadMap[thread.path] ? threadMap[thread.path].findIndex(t => t.gitHubThreadId === thread.id) : -1;
349-
if (index > -1) {
350-
const matchingThread = threadMap[thread.path][index];
351-
threadMap[thread.path].splice(index, 1);
336+
const match = this._findMatchingThread(thread);
337+
if (match.index > -1) {
338+
const matchingThread = match.threadMap[thread.path][match.index];
339+
match.threadMap[thread.path].splice(match.index, 1);
352340
matchingThread.dispose();
353341
}
354342
});
@@ -359,6 +347,28 @@ export class ReviewCommentController extends CommentControllerBase implements Co
359347
this._register(vscode.window.onDidChangeActiveTextEditor(e => this.onDidChangeActiveTextEditor(e)));
360348
}
361349

350+
private _findMatchingThread(thread: IReviewThread): { threadMap: { [key: string]: GHPRCommentThread[] }, index: number } {
351+
const threadMap = thread.isOutdated
352+
? this._obsoleteFileChangeCommentThreads
353+
: thread.diffSide === DiffSide.RIGHT
354+
? this._workspaceFileChangeCommentThreads
355+
: this._reviewSchemeFileChangeCommentThreads;
356+
357+
let index = threadMap[thread.path]?.findIndex(t => t.gitHubThreadId === thread.id) ?? -1;
358+
if ((index === -1) && thread.isOutdated) {
359+
// The thread has become outdated and needs to be moved to the obsolete threads.
360+
index = this._workspaceFileChangeCommentThreads[thread.path]?.findIndex(t => t.gitHubThreadId === thread.id) ?? -1;
361+
if (index > -1) {
362+
const matchingThread = this._workspaceFileChangeCommentThreads[thread.path]!.splice(index, 1)[0];
363+
if (!this._obsoleteFileChangeCommentThreads[thread.path]) {
364+
this._obsoleteFileChangeCommentThreads[thread.path] = [];
365+
}
366+
this._obsoleteFileChangeCommentThreads[thread.path]!.push(matchingThread);
367+
}
368+
}
369+
return { threadMap, index };
370+
}
371+
362372
private _commentContentChangedListener: vscode.Disposable | undefined;
363373
private onDidChangeActiveTextEditor(editor: vscode.TextEditor | undefined) {
364374
this._commentContentChangedListener?.dispose();

0 commit comments

Comments
 (0)