@@ -77,13 +77,18 @@ export class DiffApproveProvider {
7777 async ( message : { type : string ; blockId ?: number } ) => {
7878 if ( ! this . diffContent ) return
7979
80+ console . log ( `[DiffApproveProvider] Received message: ${ message . type } ` , { blockId : message . blockId } )
81+
8082 switch ( message . type ) {
8183 case "approve" :
8284 case "deny" : {
8385 if ( message . blockId !== undefined ) {
8486 // Find the group containing this block
8587 const blocks = this . findRelatedBlocks ( message . blockId )
8688 if ( blocks . length > 0 ) {
89+ console . log (
90+ `[DiffApproveProvider] Processing ${ blocks . length } blocks in group for ${ message . type } ` ,
91+ )
8792 // Process all blocks in the group
8893 for ( const block of blocks ) {
8994 await this . onBlockApprove ?.( block . id , message . type === "approve" )
@@ -97,7 +102,15 @@ export class DiffApproveProvider {
97102 } )
98103
99104 if ( this . pendingBlocks . size === 0 ) {
100- await this . onAllBlocksProcessed ?.( )
105+ console . log (
106+ `[DiffApproveProvider] All blocks processed, calling onAllBlocksProcessed` ,
107+ )
108+ try {
109+ await this . onAllBlocksProcessed ?.( )
110+ console . log ( `[DiffApproveProvider] onAllBlocksProcessed completed successfully` )
111+ } catch ( error ) {
112+ console . error ( `[DiffApproveProvider] Error in onAllBlocksProcessed:` , error )
113+ }
101114 this . dispose ( )
102115 }
103116 }
@@ -107,6 +120,9 @@ export class DiffApproveProvider {
107120 case "approveAll" :
108121 case "denyAll" : {
109122 const isApprove = message . type === "approveAll"
123+ console . log (
124+ `[DiffApproveProvider] Processing ${ this . pendingBlocks . size } pending blocks for ${ isApprove ? "approve" : "deny" } all` ,
125+ )
110126 for ( const blockId of this . pendingBlocks ) {
111127 await this . onBlockApprove ?.( blockId , isApprove )
112128 }
@@ -115,7 +131,20 @@ export class DiffApproveProvider {
115131 type : isApprove ? "allBlocksApproved" : "allBlocksDenied" ,
116132 } )
117133 this . pendingBlocks . clear ( )
118- await this . onAllBlocksProcessed ?.( )
134+ console . log (
135+ `[DiffApproveProvider] All blocks processed in ${ isApprove ? "approve" : "deny" } all, calling onAllBlocksProcessed` ,
136+ )
137+ try {
138+ await this . onAllBlocksProcessed ?.( )
139+ console . log (
140+ `[DiffApproveProvider] onAllBlocksProcessed completed successfully for ${ isApprove ? "approve" : "deny" } all` ,
141+ )
142+ } catch ( error ) {
143+ console . error (
144+ `[DiffApproveProvider] Error in onAllBlocksProcessed for ${ isApprove ? "approve" : "deny" } all:` ,
145+ error ,
146+ )
147+ }
119148 this . dispose ( )
120149 break
121150 }
@@ -128,6 +157,20 @@ export class DiffApproveProvider {
128157 // Clean up when panel is closed
129158 panel . onDidDispose (
130159 ( ) => {
160+ console . log ( `[DiffApproveProvider] Panel disposed, ${ this . pendingBlocks . size } pending blocks remaining` )
161+ // If there are still pending blocks when the panel is closed,
162+ // we should still call onAllBlocksProcessed
163+ if ( this . pendingBlocks . size > 0 ) {
164+ console . log ( `[DiffApproveProvider] Panel closed with pending blocks, calling onAllBlocksProcessed` )
165+ try {
166+ this . onAllBlocksProcessed ?.( ) . catch ( ( error ) => {
167+ console . error ( `[DiffApproveProvider] Error in onAllBlocksProcessed on panel close:` , error )
168+ } )
169+ console . log ( `[DiffApproveProvider] onAllBlocksProcessed called on panel close` )
170+ } catch ( error ) {
171+ console . error ( `[DiffApproveProvider] Error calling onAllBlocksProcessed on panel close:` , error )
172+ }
173+ }
131174 this . dispose ( )
132175 } ,
133176 null ,
@@ -515,12 +558,42 @@ export class DiffApproveProvider {
515558 }
516559
517560 public dispose ( ) : void {
518- DiffApproveProvider . currentPanel ?. dispose ( )
519- DiffApproveProvider . currentPanel = undefined
561+ console . log ( `[DiffApproveProvider] dispose called, cleaning up resources` )
562+
563+ // Ensure onAllBlocksProcessed is called whenever we dispose
564+ if ( this . pendingBlocks . size > 0 ) {
565+ console . log (
566+ `[DiffApproveProvider] dispose: Calling onAllBlocksProcessed for ${ this . pendingBlocks . size } remaining blocks` ,
567+ )
568+ try {
569+ this . onAllBlocksProcessed ?.( ) . catch ( ( error ) => {
570+ console . error ( `[DiffApproveProvider] Error in onAllBlocksProcessed during dispose:` , error )
571+ } )
572+ } catch ( error ) {
573+ console . error ( `[DiffApproveProvider] Error calling onAllBlocksProcessed during dispose:` , error )
574+ }
575+ }
576+
577+ // Only dispose the panel if it matches the current one
578+ if ( DiffApproveProvider . currentPanel ) {
579+ try {
580+ DiffApproveProvider . currentPanel . dispose ( )
581+ console . log ( `[DiffApproveProvider] Panel disposed successfully` )
582+ } catch ( error ) {
583+ console . error ( `[DiffApproveProvider] Error disposing panel:` , error )
584+ }
585+ DiffApproveProvider . currentPanel = undefined
586+ }
520587
588+ // Clean up all disposables
521589 while ( this . disposables . length ) {
522- const disposable = this . disposables . pop ( )
523- disposable ?. dispose ( )
590+ try {
591+ const disposable = this . disposables . pop ( )
592+ disposable ?. dispose ( )
593+ } catch ( error ) {
594+ console . error ( `[DiffApproveProvider] Error disposing a disposable:` , error )
595+ }
524596 }
597+ console . log ( `[DiffApproveProvider] All resources cleaned up` )
525598 }
526599}
0 commit comments