Skip to content

Commit 6edad9e

Browse files
committed
Remove external uses of current panel
Part of #3058
1 parent f937ee0 commit 6edad9e

8 files changed

Lines changed: 55 additions & 15 deletions

src/commands.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,16 +1065,18 @@ export function registerCommands(
10651065

10661066
context.subscriptions.push(
10671067
vscode.commands.registerCommand('pr.refreshDescription', async () => {
1068-
if (PullRequestOverviewPanel.currentPanel) {
1069-
PullRequestOverviewPanel.refresh();
1068+
const panel = PullRequestOverviewPanel.getActivePanel();
1069+
if (panel) {
1070+
panel.refreshPanel();
10701071
}
10711072
}),
10721073
);
10731074

10741075
context.subscriptions.push(vscode.commands.registerCommand('pr.focusDescriptionInput',
10751076
async () => {
1076-
if (PullRequestOverviewPanel.currentPanel) {
1077-
PullRequestOverviewPanel.scrollToReview();
1077+
const panel = PullRequestOverviewPanel.getActivePanel();
1078+
if (panel) {
1079+
panel.scrollToPendingReview();
10781080
}
10791081
}
10801082
));

src/github/issueOverview.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@ export class IssueOverviewPanel<TItem extends IssueModel = IssueModel> extends W
8282
}
8383
}
8484

85+
/**
86+
* Return the panel whose webview is currently active (focused),
87+
* or `undefined` when no issue/PR panel is active.
88+
* Today there is at most one panel; with multiple panels this
89+
* will iterate the panel map.
90+
*/
91+
public static getActivePanel(): IssueOverviewPanel | undefined {
92+
if (this.currentPanel?._panel.active) {
93+
return this.currentPanel;
94+
}
95+
return undefined;
96+
}
97+
8598
protected setPanelTitle(title: string): void {
8699
try {
87100
this._panel.title = title;

src/github/pullRequestOverview.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,24 +109,46 @@ export class PullRequestOverviewPanel extends IssueOverviewPanel<PullRequestMode
109109
}
110110

111111
public static override refresh(): void {
112-
if (this.currentPanel) {
113-
this.currentPanel.refreshPanel();
112+
const panel = this.getActivePanel();
113+
if (panel) {
114+
panel.refreshPanel();
114115
}
115116
}
116117

117-
public static scrollToReview(): void {
118-
if (this.currentPanel) {
119-
this.currentPanel._postMessage({ command: 'pr.scrollToPendingReview' });
118+
public static scrollToReview(owner: string, repo: string, number: number): void {
119+
const panel = this.findPanel(owner, repo, number);
120+
if (panel) {
121+
panel.scrollToPendingReview();
120122
}
121123
}
122124

125+
/**
126+
* Scroll the webview to the pending review section.
127+
*/
128+
public scrollToPendingReview(): void {
129+
this._postMessage({ command: 'pr.scrollToPendingReview' });
130+
}
131+
123132
/**
124133
* Get the currently active pull request from the current panel
125134
*/
126135
public static getCurrentPullRequest(): PullRequestModel | undefined {
127136
return this.currentPanel?._item;
128137
}
129138

139+
/**
140+
* Return the panel whose webview is currently active (focused),
141+
* or `undefined` when no PR panel is active.
142+
* Today there is at most one panel; with multiple panels this
143+
* will iterate the panel map.
144+
*/
145+
public static override getActivePanel(): PullRequestOverviewPanel | undefined {
146+
if (this.currentPanel?._panel.active) {
147+
return this.currentPanel;
148+
}
149+
return undefined;
150+
}
151+
130152
/**
131153
* Find the panel showing a specific pull request.
132154
* Currently there is at most one panel, but this will support

src/lm/issueContextProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class IssueContextProvider implements vscode.ChatContextProvider {
2929
) { }
3030

3131
async provideChatContextForResource(_options: { resource: vscode.Uri }, _token: vscode.CancellationToken): Promise<IssueChatContextItem | undefined> {
32-
const item = IssueOverviewPanel.currentPanel?.getCurrentItem();
32+
const item = IssueOverviewPanel.getActivePanel()?.getCurrentItem();
3333
if (item) {
3434
return this._issueToUnresolvedContext(item);
3535
}

src/lm/pullRequestContextProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ Active pull request (may not be the same as open pull request): ${folderManager.
9292
}
9393

9494
async provideChatContextForResource(_options: { resource: vscode.Uri }, _token: vscode.CancellationToken): Promise<PRChatContextItem | undefined> {
95-
const item = PullRequestOverviewPanel.currentPanel?.getCurrentItem();
95+
const item = PullRequestOverviewPanel.getActivePanel()?.getCurrentItem();
9696
if (item) {
9797
return this._prToUnresolvedContext(item);
9898
}

src/lm/tools/openPullRequestTool.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export class OpenPullRequestTool extends PullRequestTool {
1313
public static readonly toolId = 'github-pull-request_openPullRequest';
1414

1515
protected _findActivePullRequest(): PullRequestModel | undefined {
16-
// First check if there's a PR overview panel open
17-
const panelPR = PullRequestOverviewPanel.currentPanel?.getCurrentItem();
16+
// First check if there's an active PR overview panel
17+
const panelPR = PullRequestOverviewPanel.getActivePanel()?.getCurrentItem();
1818
if (panelPR) {
1919
return panelPR;
2020
}

src/view/pullRequestCommentController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ export class PullRequestCommentController extends CommentControllerBase implemen
497497
number: this.pullRequestModel.number
498498
};
499499
await PullRequestOverviewPanel.createOrShow(this._telemetry, this._folderRepoManager.context.extensionUri, this._folderRepoManager, identity, this.pullRequestModel);
500-
PullRequestOverviewPanel.scrollToReview();
500+
PullRequestOverviewPanel.scrollToReview(identity.owner, identity.repo, identity.number);
501501

502502
/* __GDPR__
503503
"pr.openDescription" : {}

src/view/reviewCommentController.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,10 @@ export class ReviewCommentController extends CommentControllerBase implements Co
723723

724724
public async openReview(): Promise<void> {
725725
await this._reviewManager.openDescription();
726-
PullRequestOverviewPanel.scrollToReview();
726+
const pr = this._folderRepoManager.activePullRequest;
727+
if (pr) {
728+
PullRequestOverviewPanel.scrollToReview(pr.remote.owner, pr.remote.repositoryName, pr.number);
729+
}
727730
}
728731

729732
// #endregion

0 commit comments

Comments
 (0)