@@ -53,6 +53,9 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWa
5353 private _context : vscode . ExtensionContext ;
5454 private _activeSession : GDBTargetDebugSession | undefined ;
5555 private readonly sessionLiveWatchStates = new Map < string , SessionLiveWatchState > ( ) ;
56+ private _pendingRefresh : boolean = false ;
57+ private _pendingUpdateTimer : NodeJS . Timeout | undefined ;
58+ private _updateInProgress : boolean = false ;
5659
5760 constructor ( private readonly context : vscode . ExtensionContext ) {
5861 this . roots = this . context . workspaceState . get < LiveWatchNode [ ] > ( this . STORAGE_KEY ) ?? [ ] ;
@@ -113,17 +116,17 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWa
113116 // Using this event because this is when the threadId is available for evaluations
114117 const onStackItem = tracker . onDidChangeActiveStackItem ( async ( item ) => {
115118 if ( ( item . item as vscode . DebugStackFrame ) . frameId !== undefined ) {
116- await this . refresh ( ) ;
119+ this . schedulePendingRefresh ( ) ;
117120 }
118121 } ) ;
119- const onStackTrace = tracker . onStackTrace ( async ( ) => await this . refresh ( ) ) ;
122+ const onStackTrace = tracker . onStackTrace ( async ( ) => this . schedulePendingRefresh ( ) ) ;
120123 // Clearing active session on closing the session
121124 const onWillStopSession = tracker . onWillStopSession ( async ( session ) => {
122125 this . sessionLiveWatchStates . delete ( session . session . id ) ;
123126 if ( this . activeSession ?. session . id && this . activeSession ?. session . id === session . session . id ) {
124127 this . _activeSession = undefined ;
125128 }
126- await this . refresh ( ) ;
129+ this . schedulePendingRefresh ( ) ;
127130 await this . save ( ) ;
128131 } ) ;
129132 const onMemory = tracker . onMemory ( async ( event ) => {
@@ -169,7 +172,7 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWa
169172 }
170173 const enabled = state ?. periodicUpdateEnabled ?? true ;
171174 void vscode . commands . executeCommand ( 'setContext' , 'liveWatch.periodicUpdateEnabled' , enabled ) ;
172- await this . refresh ( ) ;
175+ this . schedulePendingRefresh ( ) ;
173176 }
174177
175178 private async handleOnWillStartSession ( session : GDBTargetDebugSession ) : Promise < void > {
@@ -180,7 +183,7 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWa
180183 session . refreshTimer . onRefresh ( async ( refreshSession ) => {
181184 const state = this . sessionLiveWatchStates . get ( refreshSession . session . id ) ;
182185 if ( this . _activeSession ?. session . id === refreshSession . session . id && state ?. periodicUpdateEnabled ) {
183- await this . refresh ( ) ;
186+ this . schedulePendingRefresh ( ) ;
184187 }
185188 } ) ;
186189 }
@@ -190,7 +193,7 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWa
190193 if ( this . _activeSession ?. session . id !== gdbTargetSession . session . id ) {
191194 return ;
192195 }
193- await this . refresh ( ) ;
196+ this . schedulePendingRefresh ( ) ;
194197 }
195198 private async handleOnContinued ( session : GDBTargetDebugSession ) : Promise < void > {
196199 if ( this . _activeSession ?. session . id != session . session . id ) {
@@ -211,7 +214,32 @@ export class LiveWatchTreeDataProvider implements vscode.TreeDataProvider<LiveWa
211214 if ( this . _activeSession ?. session . id !== gdbTargetSession . session . id ) {
212215 return ;
213216 }
214- await this . refresh ( ) ;
217+ this . schedulePendingRefresh ( ) ;
218+ }
219+
220+ private schedulePendingRefresh ( ) {
221+ this . _pendingRefresh = true ;
222+ if ( this . _pendingUpdateTimer ) {
223+ clearTimeout ( this . _pendingUpdateTimer ) ;
224+ }
225+ this . _pendingUpdateTimer = setTimeout ( async ( ) => {
226+ if ( this . _pendingRefresh ) {
227+ await this . runPendingRefresh ( ) ;
228+ this . _pendingRefresh = false ;
229+ }
230+ } , 50 ) ;
231+ }
232+
233+ private async runPendingRefresh ( ) {
234+ if ( this . _updateInProgress ) {
235+ return ;
236+ }
237+ this . _updateInProgress = true ;
238+ while ( this . _pendingRefresh ) {
239+ this . _pendingRefresh = false ;
240+ await this . refresh ( ) ;
241+ }
242+ this . _updateInProgress = false ;
215243 }
216244
217245 private async addVSCodeCommands ( ) : Promise < boolean > {
0 commit comments