Skip to content

Commit 26a5204

Browse files
Copilotalexr00
andauthored
Close outdated multidiff editors when PR is reopened (#8256)
* Initial plan * Initial plan for closing outdated multidiff editors Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Close outdated multidiff editors when PR is reopened Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Refactor multidiff editor closing based on code review feedback Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Add documentation comments based on code review feedback Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Revert formatting changes, keep only functional changes Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Add TabInputTextMultiDiff API proposal * Use TabInputTextMultiDiff API instead of workaround Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Clean up --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent f86aae0 commit 26a5204

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"quickDiffProvider",
3737
"remoteCodingAgents",
3838
"shareProvider",
39+
"tabInputMultiDiff",
3940
"tokenInformation",
4041
"treeItemMarkdownLabel",
4142
"treeViewMarkdownMessage"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
// https://github.com/microsoft/vscode/issues/206411
7+
8+
declare module 'vscode' {
9+
10+
export class TabInputTextMultiDiff {
11+
12+
readonly textDiffs: TabInputTextDiff[];
13+
14+
constructor(textDiffs: TabInputTextDiff[]);
15+
}
16+
17+
export interface Tab {
18+
19+
readonly input: TabInputText | TabInputTextDiff | TabInputTextMultiDiff | TabInputCustom | TabInputWebview | TabInputNotebook | TabInputNotebookDiff | TabInputTerminal | unknown;
20+
21+
}
22+
}

src/view/reviewManager.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,27 @@ export class ReviewManager extends Disposable {
675675
}
676676
}
677677

678+
private async _closeOutdatedMultiDiffEditors(pullRequest: PullRequestModel): Promise<void> {
679+
// Close any multidiff editors for this PR that may be outdated
680+
const multiDiffLabel = vscode.l10n.t('Changes in Pull Request #{0}', pullRequest.number);
681+
682+
const closePromises: Promise<boolean>[] = [];
683+
for (const tabGroup of vscode.window.tabGroups.all) {
684+
for (const tab of tabGroup.tabs) {
685+
// Check if this is a TabInputTextMultiDiff with matching label
686+
if (tab.input instanceof vscode.TabInputTextMultiDiff && tab.label.startsWith(multiDiffLabel)) {
687+
Logger.appendLine(`Closing outdated multidiff editor for PR #${pullRequest.number}`, this.id);
688+
closePromises.push(Promise.resolve(vscode.window.tabGroups.close(tab)));
689+
}
690+
}
691+
}
692+
await Promise.all(closePromises);
693+
}
694+
678695
public async _upgradePullRequestEditors(pullRequest: PullRequestModel) {
696+
// Close any outdated multidiff editors first
697+
await this._closeOutdatedMultiDiffEditors(pullRequest);
698+
679699
// Go through all open editors and find pr scheme editors that belong to the active pull request.
680700
// Close the editors, and reopen them from the pull request.
681701
const reopenFilenames: Set<[PRUriParams, PRUriParams]> = new Set();

0 commit comments

Comments
 (0)