Skip to content

Commit a84a532

Browse files
Copilotalexr00
andauthored
Fix local PR tree not updating when PR is created on GitHub website
When a PR is created on the GitHub website (not via VS Code UI), the ReviewManager discovers it via checkGitHubForPrBranch() and associates the local branch with the PR. However, the local PR tree cache in PrsTreeModel was never invalidated afterward, so the "Local Pull Request Branches" category never showed the newly-associated branch. Fix: In PrsTreeModel's onDidChangeActivePullRequest handler, when the new active PR is not already in the cached PR set, delete the LocalPullRequest cache entry and fire a full folder refresh (which triggers refreshRepo() in the tree data provider) instead of the narrow PR-level refresh (which only updates existing PR nodes via refreshPullRequests()). Agent-Logs-Url: https://github.com/microsoft/vscode-pull-request-github/sessions/a016c47c-ed2e-432f-b461-f678d8ab62c8 Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 5985cb4 commit a84a532

File tree

2 files changed

+22
-29
lines changed

2 files changed

+22
-29
lines changed

src/@types/vscode.proposed.chatSessionsProvider.d.ts

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ declare module 'vscode' {
343343
/**
344344
* Statistics about the chat session.
345345
*/
346-
changes?: readonly ChatSessionChangedFile[] | readonly ChatSessionChangedFile2[];
346+
changes?: readonly ChatSessionChangedFile[];
347347

348348
/**
349349
* Arbitrary metadata for the chat session. Can be anything, but must be JSON-stringifyable.
@@ -353,34 +353,7 @@ declare module 'vscode' {
353353
metadata?: { readonly [key: string]: any };
354354
}
355355

356-
/**
357-
* @deprecated Use `ChatSessionChangedFile2` instead
358-
*/
359356
export class ChatSessionChangedFile {
360-
/**
361-
* URI of the file.
362-
*/
363-
modifiedUri: Uri;
364-
365-
/**
366-
* File opened when the user takes the 'compare' action.
367-
*/
368-
originalUri?: Uri;
369-
370-
/**
371-
* Number of insertions made during the session.
372-
*/
373-
insertions: number;
374-
375-
/**
376-
* Number of deletions made during the session.
377-
*/
378-
deletions: number;
379-
380-
constructor(modifiedUri: Uri, insertions: number, deletions: number, originalUri?: Uri);
381-
}
382-
383-
export class ChatSessionChangedFile2 {
384357
/**
385358
* URI of the file.
386359
*/
@@ -728,9 +701,18 @@ declare module 'vscode' {
728701
export interface ChatSessionInputState {
729702
/**
730703
* Fired when the input state is changed by the user.
704+
*
705+
* Move to controller?
731706
*/
732707
readonly onDidChange: Event<void>;
733708

709+
/**
710+
* The resource associated with this chat session.
711+
*
712+
* This is `undefined` for chat sessions that have not yet started.
713+
*/
714+
readonly sessionResource: Uri | undefined;
715+
734716
/**
735717
* The groups of options to show in the UI for user input.
736718
*

src/view/prsTreeModel.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,18 @@ export class PrsTreeModel extends Disposable {
8787
if (e.new) {
8888
prs.push({ model: e.new, event: {} });
8989
}
90-
this._onDidChangeData.fire(prs);
90+
91+
// When a new active PR is discovered (e.g. PR created on GitHub website),
92+
// check if it's already in the local PR cache. If not, clear the local cache
93+
// and fire a full folder refresh so the "Local Pull Request Branches" category
94+
// picks up the newly-associated branch.
95+
if (e.new && !this._allCachedPRs.has(e.new)) {
96+
const cache = this.getFolderCache(manager);
97+
cache.delete(PRType.LocalPullRequest);
98+
this._onDidChangeData.fire(manager);
99+
} else {
100+
this._onDidChangeData.fire(prs);
101+
}
91102

92103
if (this._activePRDisposables.has(manager)) {
93104
disposeAll(this._activePRDisposables.get(manager)!);

0 commit comments

Comments
 (0)