Skip to content

Commit 1f76dc1

Browse files
authored
Continue the quest to refresh less (#7688)
Fixes #7643
1 parent ea82c1f commit 1f76dc1

3 files changed

Lines changed: 55 additions & 18 deletions

File tree

src/commands.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,8 +1461,6 @@ ${contents}
14611461
reviewManager.repository.pull(false),
14621462
reviewManager.updateComments()
14631463
]);
1464-
PullRequestOverviewPanel.refresh();
1465-
reviewManager.changesInPrDataProvider.refresh();
14661464
});
14671465
});
14681466
}),
@@ -1488,7 +1486,6 @@ ${contents}
14881486
}
14891487

14901488
PullRequestOverviewPanel.refresh();
1491-
tree.refresh(prNode);
14921489
}),
14931490
);
14941491

src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ async function deferredActivate(context: vscode.ExtensionContext, showPRControll
451451

452452
const prTree = new PullRequestsTreeDataProvider(telemetry, context, reposManager, copilotRemoteAgentManager);
453453
context.subscriptions.push(prTree);
454-
context.subscriptions.push(credentialStore.onDidGetSession(() => prTree.refresh(undefined, true)));
454+
context.subscriptions.push(credentialStore.onDidGetSession(() => prTree.refreshAll(true)));
455455
Logger.appendLine('Looking for git repository', ACTIVATION);
456456
const repositories = apiImpl.repositories;
457457
Logger.appendLine(`Found ${repositories.length} repositories during activation`, ACTIVATION);

src/view/prsTreeDataProvider.ts

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,17 @@ export class PullRequestsTreeDataProvider extends Disposable implements vscode.T
6363
} else if (Array.isArray(e)) {
6464
this.refreshPullRequests(e);
6565
} else {
66-
this.refresh(undefined, true);
66+
this.refreshAllQueryResults(true);
6767
}
6868
}));
6969
this._register(new PRStatusDecorationProvider(this.prsTreeModel, this._copilotManager));
7070
this._register(vscode.commands.registerCommand('pr.refreshList', _ => {
71-
this.refresh(undefined, true);
71+
this.refreshAllQueryResults(true);
7272
}));
7373

7474
this._register(vscode.commands.registerCommand('pr.loadMore', (node: CategoryTreeNode) => {
7575
node.fetchNextPage = true;
76-
this._onDidChangeTreeData.fire(node);
76+
this.refresh(node);
7777
}));
7878

7979
this._view = this._register(vscode.window.createTreeView('pr:github', {
@@ -101,7 +101,7 @@ export class PullRequestsTreeDataProvider extends Disposable implements vscode.T
101101
});
102102

103103
this._register(this._copilotManager.onDidChangeStates(() => {
104-
this.refresh(undefined);
104+
this.refreshAllQueryResults();
105105
}));
106106

107107
this._register(this._copilotManager.onDidChangeNotifications(() => {
@@ -115,7 +115,7 @@ export class PullRequestsTreeDataProvider extends Disposable implements vscode.T
115115
}
116116
}));
117117

118-
this._register(this._copilotManager.onDidCreatePullRequest(() => this.refresh(undefined, true)));
118+
this._register(this._copilotManager.onDidCreatePullRequest(() => this.refreshAllQueryResults(true)));
119119

120120
// Listen for PR overview panel changes to sync the tree view
121121
this._register(PullRequestOverviewPanel.onVisible(pullRequest => {
@@ -157,7 +157,7 @@ export class PullRequestsTreeDataProvider extends Disposable implements vscode.T
157157

158158
this._register(vscode.workspace.onDidChangeConfiguration(e => {
159159
if (e.affectsConfiguration(`${PR_SETTINGS_NAMESPACE}.${FILE_LIST_LAYOUT}`)) {
160-
this._onDidChangeTreeData.fire();
160+
this.refreshAll();
161161
}
162162
}));
163163

@@ -270,44 +270,84 @@ export class PullRequestsTreeDataProvider extends Disposable implements vscode.T
270270
this._initialized = true;
271271
this._register(
272272
this._reposManager.onDidChangeState(() => {
273-
this.refresh();
273+
this.refreshAll();
274274
}),
275275
);
276276

277277
for (const model of reviewModels) {
278-
this._register(model.onDidChangeLocalFileChanges(_ => { this.refresh(); }));
278+
this._register(model.onDidChangeLocalFileChanges(_ => { this.refreshAllQueryResults(); }));
279279
}
280280

281281
this.notificationProvider = this._register(new NotificationProvider(this, credentialStore, this._reposManager));
282282

283283
this.initializeCategories();
284-
this.refresh();
284+
this.refreshAll();
285285
}
286286

287287
private async initializeCategories() {
288288
this._register(vscode.workspace.onDidChangeConfiguration(async e => {
289289
if (e.affectsConfiguration(`${PR_SETTINGS_NAMESPACE}.${QUERIES}`)) {
290-
this.refresh();
290+
this.refreshAll();
291291
}
292292
}));
293293
}
294294

295-
refresh(node?: TreeNode, reset?: boolean): void {
295+
refreshAll(reset?: boolean) {
296+
this.tryReset(!!reset);
297+
this._onDidChangeTreeData.fire();
298+
}
299+
300+
private tryReset(reset: boolean) {
296301
if (reset) {
297302
this.prsTreeModel.clearCache(true);
298303
}
299-
return node ? this._onDidChangeTreeData.fire(node) : this._onDidChangeTreeData.fire();
304+
}
305+
306+
private refreshAllQueryResults(reset?: boolean) {
307+
this.tryReset(!!reset);
308+
309+
if (!this._children || this._children.length === 0) {
310+
this._onDidChangeTreeData.fire();
311+
return;
312+
}
313+
314+
if (this._children[0] instanceof WorkspaceFolderNode) {
315+
(this._children as WorkspaceFolderNode[]).forEach(folderNode => this.refreshQueryResultsForFolder(folderNode));
316+
return;
317+
}
318+
this.refreshQueryResultsForFolder();
319+
}
320+
321+
private refreshQueryResultsForFolder(manager?: WorkspaceFolderNode, reset?: boolean) {
322+
if (!manager && this._children[0] instanceof WorkspaceFolderNode) {
323+
// Not permitted. There're multiple folder nodes, therefore must specify which one to refresh
324+
throw new Error('Must specify a folder node to refresh when there are multiple folder nodes');
325+
}
326+
327+
if (!this._children || this._children.length === 0) {
328+
this._onDidChangeTreeData.fire();
329+
return;
330+
}
331+
const queries = manager?.children ?? this._children;
332+
this.tryReset(!!reset);
333+
334+
this._onDidChangeTreeData.fire([...queries]);
335+
}
336+
337+
refresh(node: TreeNode, reset?: boolean): void {
338+
this.tryReset(!!reset);
339+
return this._onDidChangeTreeData.fire(node);
300340
}
301341

302342
private refreshRepo(manager: FolderRepositoryManager): void {
303343
if ((this._children.length === 0) || (this._children[0] instanceof CategoryTreeNode && this._children[0].folderRepoManager === manager)) {
304-
return this.refresh(undefined, true);
344+
return this.refreshQueryResultsForFolder(undefined, true);
305345
}
306346
if (this._children[0] instanceof WorkspaceFolderNode) {
307347
const children: WorkspaceFolderNode[] = this._children as WorkspaceFolderNode[];
308348
const node = children.find(node => node.folderManager === manager);
309349
if (node) {
310-
this._onDidChangeTreeData.fire(node);
350+
this.refreshQueryResultsForFolder(node);
311351
return;
312352
}
313353
}

0 commit comments

Comments
 (0)