Skip to content

Commit 22e3be7

Browse files
authored
Fix #openPullRequest to detect PRs from diff views with multi-workspace support and use consistent terminology (#7803)
* Initial plan * Fix #openPullRequest to consider diff editors and use consistent terminology Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Implement diff view detection for #openPullRequest tool Check if active editor is showing PR diff content (either pr: or review: scheme) and determine the associated PR. This addresses the feedback to detect PRs from diff views instead of just checking for checked out PRs. * Use Tab API to detect diff editors in #openPullRequest tool Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Use reviewParams rootUri to find correct folder manager Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Revert proposal changes
1 parent f6718e4 commit 22e3be7

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed

src/lm/tools/openPullRequestTool.ts

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as vscode from 'vscode';
7+
import { fromPRUri, fromReviewUri, Schemes } from '../../common/uri';
78
import { PullRequestModel } from '../../github/pullRequestModel';
89
import { PullRequestOverviewPanel } from '../../github/pullRequestOverview';
910
import { PullRequestTool } from './activePullRequestTool';
@@ -12,10 +13,58 @@ export class OpenPullRequestTool extends PullRequestTool {
1213
public static readonly toolId = 'github-pull-request_openPullRequest';
1314

1415
protected _findActivePullRequest(): PullRequestModel | undefined {
15-
return PullRequestOverviewPanel.currentPanel?.getCurrentItem();
16+
// First check if there's a PR overview panel open
17+
const panelPR = PullRequestOverviewPanel.currentPanel?.getCurrentItem();
18+
if (panelPR) {
19+
return panelPR;
20+
}
21+
22+
// Check if the active tab is a diff editor showing PR content
23+
const activeTab = vscode.window.tabGroups.activeTabGroup.activeTab;
24+
if (activeTab?.input instanceof vscode.TabInputTextDiff) {
25+
const diffInput = activeTab.input;
26+
const urisToCheck = [diffInput.original, diffInput.modified];
27+
28+
for (const uri of urisToCheck) {
29+
if (uri.scheme === Schemes.Pr) {
30+
// This is a PR diff from GitHub
31+
const prParams = fromPRUri(uri);
32+
if (prParams) {
33+
return this._findPullRequestByNumber(prParams.prNumber, prParams.remoteName);
34+
}
35+
} else if (uri.scheme === Schemes.Review) {
36+
// This is a review diff from a checked out PR
37+
const reviewParams = fromReviewUri(uri.query);
38+
if (reviewParams) {
39+
// For review scheme, find the folder manager based on the root path
40+
const rootUri = vscode.Uri.file(reviewParams.rootPath);
41+
const folderManager = this.folderManagers.getManagerForFile(rootUri);
42+
return folderManager?.activePullRequest;
43+
}
44+
}
45+
}
46+
}
47+
48+
return undefined;
49+
}
50+
51+
private _findPullRequestByNumber(prNumber: number, remoteName: string): PullRequestModel | undefined {
52+
for (const manager of this.folderManagers.folderManagers) {
53+
for (const repo of manager.gitHubRepositories) {
54+
if (repo.remote.remoteName === remoteName) {
55+
// Look for the PR in the repository's PR cache
56+
for (const pr of repo.pullRequestModels) {
57+
if (pr.number === prNumber) {
58+
return pr;
59+
}
60+
}
61+
}
62+
}
63+
}
64+
return undefined;
1665
}
1766

1867
protected _confirmationTitle(): string {
1968
return vscode.l10n.t('Open Pull Request');
2069
}
21-
}
70+
}

0 commit comments

Comments
 (0)