Skip to content

Commit cec928c

Browse files
Copilotalexr00
andcommitted
Use finally block for cleanup to eliminate duplication
Move QuickPick and event listener cleanup to finally block Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 5748015 commit cec928c

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/commands.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,9 @@ ${contents}
16131613
quickPick.show();
16141614
quickPick.busy = true;
16151615

1616+
let acceptDisposable: vscode.Disposable | undefined;
1617+
let hideDisposable: vscode.Disposable | undefined;
1618+
16161619
// Fetch all open PRs
16171620
try {
16181621
const prs = await githubRepo.manager.getPullRequests(PRType.All, { fetchNextPage: false });
@@ -1629,8 +1632,6 @@ ${contents}
16291632
quickPick.busy = false;
16301633

16311634
// Handle selection
1632-
let acceptDisposable: vscode.Disposable | undefined;
1633-
let hideDisposable: vscode.Disposable | undefined;
16341635
const selected = await new Promise<(vscode.QuickPickItem & { pr?: PullRequestModel }) | string | undefined>((resolve) => {
16351636
acceptDisposable = quickPick.onDidAccept(() => {
16361637
if (quickPick.selectedItems.length > 0) {
@@ -1646,13 +1647,6 @@ ${contents}
16461647
hideDisposable = quickPick.onDidHide(() => resolve(undefined));
16471648
});
16481649

1649-
// Clean up event listeners
1650-
acceptDisposable?.dispose();
1651-
hideDisposable?.dispose();
1652-
1653-
quickPick.hide();
1654-
quickPick.dispose();
1655-
16561650
if (!selected) {
16571651
return;
16581652
}
@@ -1676,9 +1670,13 @@ ${contents}
16761670
return ReviewManager.getReviewManagerForFolderManager(reviewsManager.reviewManagers, githubRepo.manager)?.switch(prModel);
16771671
}
16781672
} catch (e) {
1673+
vscode.window.showErrorMessage(vscode.l10n.t('Failed to fetch pull requests: {0}', formatError(e)));
1674+
} finally {
1675+
// Clean up event listeners and QuickPick
1676+
acceptDisposable?.dispose();
1677+
hideDisposable?.dispose();
16791678
quickPick.hide();
16801679
quickPick.dispose();
1681-
return vscode.window.showErrorMessage(vscode.l10n.t('Failed to fetch pull requests: {0}', formatError(e)));
16821680
}
16831681
}));
16841682

0 commit comments

Comments
 (0)