Skip to content

Commit 9dfe878

Browse files
authored
Show all comments in the comments view from a non-checked out PR when the description is opened. (#6575)
Fixes #6167
1 parent 17174bd commit 9dfe878

2 files changed

Lines changed: 37 additions & 11 deletions

File tree

src/github/pullRequestModel.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,17 +1263,9 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
12631263
}
12641264

12651265
static async openChanges(folderManager: FolderRepositoryManager, pullRequestModel: PullRequestModel) {
1266-
const isCurrentPR = folderManager.activePullRequest?.number === pullRequestModel.number;
1267-
const changes = pullRequestModel.fileChanges.size > 0 ? pullRequestModel.fileChanges.values() : await pullRequestModel.getFileChangesInfo();
1266+
const changeModels = await PullRequestModel.getChangeModels(folderManager, pullRequestModel);
12681267
const args: [vscode.Uri, vscode.Uri | undefined, vscode.Uri | undefined][] = [];
1269-
1270-
for (const change of changes) {
1271-
let changeModel;
1272-
if (change instanceof SlimFileChange) {
1273-
changeModel = new RemoteFileChangeModel(folderManager, change, pullRequestModel);
1274-
} else {
1275-
changeModel = new InMemFileChangeModel(folderManager, pullRequestModel as (PullRequestModel & IResolvedPullRequestModel), change, isCurrentPR, pullRequestModel.mergeBase!);
1276-
}
1268+
for (const changeModel of changeModels) {
12771269
args.push([changeModel.filePath, changeModel.parentFilePath, changeModel.filePath]);
12781270
}
12791271

@@ -1399,6 +1391,22 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
13991391
return parsed;
14001392
}
14011393

1394+
public static async getChangeModels(folderManager: FolderRepositoryManager, pullRequestModel: PullRequestModel): Promise<(RemoteFileChangeModel | InMemFileChangeModel)[]> {
1395+
const isCurrentPR = folderManager.activePullRequest?.number === pullRequestModel.number;
1396+
const changes = pullRequestModel.fileChanges.size > 0 ? pullRequestModel.fileChanges.values() : await pullRequestModel.getFileChangesInfo();
1397+
const changeModels: (RemoteFileChangeModel | InMemFileChangeModel)[] = [];
1398+
for (const change of changes) {
1399+
let changeModel;
1400+
if (change instanceof SlimFileChange) {
1401+
changeModel = new RemoteFileChangeModel(folderManager, change, pullRequestModel);
1402+
} else {
1403+
changeModel = new InMemFileChangeModel(folderManager, pullRequestModel as (PullRequestModel & IResolvedPullRequestModel), change, isCurrentPR, pullRequestModel.mergeBase!);
1404+
}
1405+
changeModels.push(changeModel);
1406+
}
1407+
return changeModels;
1408+
}
1409+
14021410
/**
14031411
* List the changed files in a pull request.
14041412
*/

src/view/pullRequestCommentController.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Logger from '../common/logger';
1212
import { ITelemetry } from '../common/telemetry';
1313
import { fromPRUri, Schemes } from '../common/uri';
1414
import { groupBy } from '../common/utils';
15+
import { PULL_REQUEST_OVERVIEW_VIEW_TYPE } from '../common/webview';
1516
import { FolderRepositoryManager } from '../github/folderRepositoryManager';
1617
import { GitHubRepository } from '../github/githubRepository';
1718
import { GHPRComment, GHPRCommentThread, TemporaryComment } from '../github/prComment';
@@ -186,18 +187,35 @@ export class PullRequestCommentController extends CommentControllerBase implemen
186187
return tabs.filter(tab => tab.input instanceof vscode.TabInputText || tab.input instanceof vscode.TabInputTextDiff).map(tab => tab.input as vscode.TabInputText | vscode.TabInputTextDiff);
187188
}
188189

190+
private prDescriptionOpened(tabs: readonly vscode.Tab[]): boolean {
191+
return tabs.some(tab => tab.input instanceof vscode.TabInputWebview && tab.label.includes(`#${this.pullRequestModel.number}`) && tab.input.viewType.includes(PULL_REQUEST_OVERVIEW_VIEW_TYPE));
192+
}
193+
189194
private async cleanClosedPrs() {
190195
// Remove comments for which no editors belonging to the same PR are open
191196
const allPrEditors = await this.getPREditors(this.allTabs());
192-
if (allPrEditors.length === 0) {
197+
const prDescriptionOpened = this.prDescriptionOpened(vscode.window.tabGroups.all.map(group => group.tabs).flat());
198+
if (allPrEditors.length === 0 && !prDescriptionOpened) {
193199
this.removeAllCommentsThreads();
194200
}
195201
}
196202

203+
private async openAllTextDocuments(): Promise<vscode.TextDocument[]> {
204+
const files = await PullRequestModel.getChangeModels(this._folderRepoManager, this.pullRequestModel);
205+
const textDocuments: vscode.TextDocument[] = [];
206+
for (const file of files) {
207+
textDocuments.push(await vscode.workspace.openTextDocument(file.filePath));
208+
}
209+
return textDocuments;
210+
}
211+
197212
private async onDidChangeOpenTabs(e: vscode.TabChangeEvent): Promise<void> {
198213
const added = await this.getPREditors(this.filterTabsToPrTabs(e.opened));
199214
if (added.length) {
200215
await this.addThreadsForEditors(added);
216+
} else if (this.prDescriptionOpened(e.opened)) {
217+
const textDocuments = await this.openAllTextDocuments();
218+
await this.addThreadsForEditors(textDocuments);
201219
}
202220
if (e.closed.length > 0) {
203221
// Delay cleaning closed editors to handle the case where a preview tab is replaced

0 commit comments

Comments
 (0)