Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show all comments in the comments view from a non-checked out PR when the description is opened. #6575

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions src/github/pullRequestModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1263,17 +1263,9 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
}

static async openChanges(folderManager: FolderRepositoryManager, pullRequestModel: PullRequestModel) {
const isCurrentPR = folderManager.activePullRequest?.number === pullRequestModel.number;
const changes = pullRequestModel.fileChanges.size > 0 ? pullRequestModel.fileChanges.values() : await pullRequestModel.getFileChangesInfo();
const changeModels = await PullRequestModel.getChangeModels(folderManager, pullRequestModel);
const args: [vscode.Uri, vscode.Uri | undefined, vscode.Uri | undefined][] = [];

for (const change of changes) {
let changeModel;
if (change instanceof SlimFileChange) {
changeModel = new RemoteFileChangeModel(folderManager, change, pullRequestModel);
} else {
changeModel = new InMemFileChangeModel(folderManager, pullRequestModel as (PullRequestModel & IResolvedPullRequestModel), change, isCurrentPR, pullRequestModel.mergeBase!);
}
for (const changeModel of changeModels) {
args.push([changeModel.filePath, changeModel.parentFilePath, changeModel.filePath]);
}

Expand Down Expand Up @@ -1399,6 +1391,22 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
return parsed;
}

public static async getChangeModels(folderManager: FolderRepositoryManager, pullRequestModel: PullRequestModel): Promise<(RemoteFileChangeModel | InMemFileChangeModel)[]> {
const isCurrentPR = folderManager.activePullRequest?.number === pullRequestModel.number;
const changes = pullRequestModel.fileChanges.size > 0 ? pullRequestModel.fileChanges.values() : await pullRequestModel.getFileChangesInfo();
const changeModels: (RemoteFileChangeModel | InMemFileChangeModel)[] = [];
for (const change of changes) {
let changeModel;
if (change instanceof SlimFileChange) {
changeModel = new RemoteFileChangeModel(folderManager, change, pullRequestModel);
} else {
changeModel = new InMemFileChangeModel(folderManager, pullRequestModel as (PullRequestModel & IResolvedPullRequestModel), change, isCurrentPR, pullRequestModel.mergeBase!);
}
changeModels.push(changeModel);
}
return changeModels;
}

/**
* List the changed files in a pull request.
*/
Expand Down
20 changes: 19 additions & 1 deletion src/view/pullRequestCommentController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Logger from '../common/logger';
import { ITelemetry } from '../common/telemetry';
import { fromPRUri, Schemes } from '../common/uri';
import { groupBy } from '../common/utils';
import { PULL_REQUEST_OVERVIEW_VIEW_TYPE } from '../common/webview';
import { FolderRepositoryManager } from '../github/folderRepositoryManager';
import { GitHubRepository } from '../github/githubRepository';
import { GHPRComment, GHPRCommentThread, TemporaryComment } from '../github/prComment';
Expand Down Expand Up @@ -186,18 +187,35 @@ export class PullRequestCommentController extends CommentControllerBase implemen
return tabs.filter(tab => tab.input instanceof vscode.TabInputText || tab.input instanceof vscode.TabInputTextDiff).map(tab => tab.input as vscode.TabInputText | vscode.TabInputTextDiff);
}

private prDescriptionOpened(tabs: readonly vscode.Tab[]): boolean {
return tabs.some(tab => tab.input instanceof vscode.TabInputWebview && tab.label.includes(`#${this.pullRequestModel.number}`) && tab.input.viewType.includes(PULL_REQUEST_OVERVIEW_VIEW_TYPE));
}

private async cleanClosedPrs() {
// Remove comments for which no editors belonging to the same PR are open
const allPrEditors = await this.getPREditors(this.allTabs());
if (allPrEditors.length === 0) {
const prDescriptionOpened = this.prDescriptionOpened(vscode.window.tabGroups.all.map(group => group.tabs).flat());
if (allPrEditors.length === 0 && !prDescriptionOpened) {
this.removeAllCommentsThreads();
}
}

private async openAllTextDocuments(): Promise<vscode.TextDocument[]> {
const files = await PullRequestModel.getChangeModels(this._folderRepoManager, this.pullRequestModel);
const textDocuments: vscode.TextDocument[] = [];
for (const file of files) {
textDocuments.push(await vscode.workspace.openTextDocument(file.filePath));
}
return textDocuments;
}

private async onDidChangeOpenTabs(e: vscode.TabChangeEvent): Promise<void> {
const added = await this.getPREditors(this.filterTabsToPrTabs(e.opened));
if (added.length) {
await this.addThreadsForEditors(added);
} else if (this.prDescriptionOpened(e.opened)) {
const textDocuments = await this.openAllTextDocuments();
await this.addThreadsForEditors(textDocuments);
}
if (e.closed.length > 0) {
// Delay cleaning closed editors to handle the case where a preview tab is replaced
Expand Down