Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"quickDiffProvider",
"remoteCodingAgents",
"shareProvider",
"tabInputMultiDiff",
"tokenInformation",
"treeItemMarkdownLabel",
"treeViewMarkdownMessage"
Expand Down
22 changes: 22 additions & 0 deletions src/@types/vscode.proposed.tabInputMultiDiff.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

// https://github.com/microsoft/vscode/issues/206411

declare module 'vscode' {

export class TabInputTextMultiDiff {

readonly textDiffs: TabInputTextDiff[];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is public API, should we add comments?


constructor(textDiffs: TabInputTextDiff[]);
}

export interface Tab {

readonly input: TabInputText | TabInputTextDiff | TabInputTextMultiDiff | TabInputCustom | TabInputWebview | TabInputNotebook | TabInputNotebookDiff | TabInputTerminal | unknown;

}
}
39 changes: 39 additions & 0 deletions src/view/reviewManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,46 @@ export class ReviewManager extends Disposable {
}
}

private isKnownTabInputType(tabInput: unknown): boolean {
// Note: This list includes all known TabInput types as of VS Code 1.107.0
// If new TabInput types are added to the VS Code API, this list will need to be updated
return (
tabInput instanceof vscode.TabInputText ||
tabInput instanceof vscode.TabInputTextDiff ||
tabInput instanceof vscode.TabInputCustom ||
tabInput instanceof vscode.TabInputWebview ||
tabInput instanceof vscode.TabInputNotebook ||
tabInput instanceof vscode.TabInputNotebookDiff ||
tabInput instanceof vscode.TabInputTerminal
);
}

private async _closeOutdatedMultiDiffEditors(pullRequest: PullRequestModel): Promise<void> {
// Close any multidiff editors for this PR that may be outdated
// Since TabInputMultiDiff is not yet available in the VS Code API (https://github.com/microsoft/vscode/issues/206411),
// we identify multidiff editors by their label pattern
// Note: This label matching is dependent on the exact localized string format from PullRequestModel.openChanges()
// If that format changes, this matching logic will need to be updated as well
const multiDiffLabel = vscode.l10n.t('Changes in Pull Request #{0}', pullRequest.number);

const closePromises: Promise<boolean>[] = [];
for (const tabGroup of vscode.window.tabGroups.all) {
for (const tab of tabGroup.tabs) {
// Multidiff editors have a specific label pattern and the input type is unknown
// since TabInputMultiDiff doesn't exist yet
if (tab.label === multiDiffLabel && !this.isKnownTabInputType(tab.input)) {
Logger.appendLine(`Closing outdated multidiff editor for PR #${pullRequest.number}`, this.id);
closePromises.push(Promise.resolve(vscode.window.tabGroups.close(tab)));
}
}
}
await Promise.all(closePromises);
}

public async _upgradePullRequestEditors(pullRequest: PullRequestModel) {
// Close any outdated multidiff editors first
await this._closeOutdatedMultiDiffEditors(pullRequest);

// Go through all open editors and find pr scheme editors that belong to the active pull request.
// Close the editors, and reopen them from the pull request.
const reopenFilenames: Set<[PRUriParams, PRUriParams]> = new Set();
Expand Down