@@ -8,6 +8,7 @@ import { COPILOT_LOGINS, copilotEventToStatus, CopilotPRStatus } from '../common
88import { Disposable } from '../common/lifecycle' ;
99import { PR_SETTINGS_NAMESPACE , QUERIES } from '../common/settingKeys' ;
1010import { FolderRepositoryManager } from './folderRepositoryManager' ;
11+ import { PullRequestModel } from './pullRequestModel' ;
1112import { RepositoriesManager } from './repositoriesManager' ;
1213import { variableSubstitution } from './utils' ;
1314
@@ -18,11 +19,11 @@ export function isCopilotQuery(query: string): boolean {
1819
1920export class CopilotStateModel extends Disposable {
2021 private _isInitialized = false ;
21- private readonly _states : Map < string , CopilotPRStatus > = new Map ( ) ;
22+ private readonly _states : Map < string , { item : PullRequestModel , status : CopilotPRStatus } > = new Map ( ) ;
2223 private readonly _showNotification : Set < string > = new Set ( ) ;
2324 private readonly _onDidChangeStates = this . _register ( new vscode . EventEmitter < void > ( ) ) ;
2425 readonly onDidChangeStates = this . _onDidChangeStates . event ;
25- private readonly _onDidChangeNotifications = this . _register ( new vscode . EventEmitter < void > ( ) ) ;
26+ private readonly _onDidChangeNotifications = this . _register ( new vscode . EventEmitter < PullRequestModel [ ] > ( ) ) ;
2627 readonly onDidChangeNotifications = this . _onDidChangeNotifications . event ;
2728
2829 makeKey ( owner : string , repo : string , prNumber : number ) : string {
@@ -37,39 +38,41 @@ export class CopilotStateModel extends Disposable {
3738 if ( this . _states . has ( key ) ) {
3839 this . _states . delete ( key ) ;
3940 if ( this . _showNotification . has ( key ) ) {
41+ const item = this . _states . get ( key ) ! ;
4042 this . _showNotification . delete ( key ) ;
41- this . _onDidChangeNotifications . fire ( ) ;
43+ this . _onDidChangeNotifications . fire ( [ item . item ] ) ;
4244 }
4345 this . _onDidChangeStates . fire ( ) ;
4446 }
4547 }
4648
47- set ( owner : string , repo : string , prNumber : number , status : CopilotPRStatus ) : void {
48- const key = this . makeKey ( owner , repo , prNumber ) ;
49+ set ( pullRequestModel : PullRequestModel , status : CopilotPRStatus ) : void {
50+ const key = this . makeKey ( pullRequestModel . remote . owner , pullRequestModel . remote . repositoryName , pullRequestModel . number ) ;
4951 const currentStatus = this . _states . get ( key ) ;
50- if ( currentStatus === status ) {
52+ if ( currentStatus ?. status === status ) {
5153 return ;
5254 }
53- this . _states . set ( key , status ) ;
55+ this . _states . set ( key , { item : pullRequestModel , status } ) ;
5456 if ( this . _isInitialized ) {
5557 this . _showNotification . add ( key ) ;
56- this . _onDidChangeNotifications . fire ( ) ;
58+ this . _onDidChangeNotifications . fire ( pullRequestModel ? [ pullRequestModel ] : [ ] ) ;
5759 }
5860 this . _onDidChangeStates . fire ( ) ;
5961 }
6062
6163 get ( owner : string , repo : string , prNumber : number ) : CopilotPRStatus {
6264 const key = this . makeKey ( owner , repo , prNumber ) ;
63- return this . _states . get ( key ) ?? CopilotPRStatus . None ;
65+ return this . _states . get ( key ) ?. status ?? CopilotPRStatus . None ;
6466 }
6567
6668 keys ( ) : string [ ] {
6769 return Array . from ( this . _states . keys ( ) ) ;
6870 }
6971
7072 clearNotifications ( ) : void {
73+ const items = Array . from ( this . _showNotification ) . map ( key => this . _states . get ( key ) ?. item ) . filter ( ( item ) : item is PullRequestModel => ! ! item ) ;
7174 this . _showNotification . clear ( ) ;
72- this . _onDidChangeNotifications . fire ( ) ;
75+ this . _onDidChangeNotifications . fire ( items ) ;
7376 }
7477
7578 get notifications ( ) : ReadonlySet < string > {
@@ -158,7 +161,7 @@ export class CopilotPRWatcher extends Disposable {
158161 prNumber : pr . number ,
159162 status : latestEvent
160163 } ) ;
161- this . _model . set ( pr . remote . owner , pr . remote . repositoryName , pr . number , latestEvent ) ;
164+ this . _model . set ( pr , latestEvent ) ;
162165 }
163166 }
164167
0 commit comments