33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6+ import { RunOnceScheduler } from 'vs/base/common/async' ;
67import { URI } from 'vs/base/common/uri' ;
78import * as nls from 'vs/nls' ;
89import { ILocalizedString } from 'vs/platform/action/common/action' ;
@@ -34,6 +35,9 @@ export class NotebookVariablesView extends ViewPane {
3435
3536 private tree : WorkbenchAsyncDataTree < INotebookScope , INotebookVariableElement > | undefined ;
3637 private activeNotebook : NotebookTextModel | undefined ;
38+ private readonly dataSource : NotebookVariableDataSource ;
39+
40+ private updateScheduler : RunOnceScheduler ;
3741
3842 constructor (
3943 options : IViewPaneOptions ,
@@ -59,6 +63,9 @@ export class NotebookVariablesView extends ViewPane {
5963 this . _register ( this . notebookExecutionStateService . onDidChangeExecution ( this . handleExecutionStateChange . bind ( this ) ) ) ;
6064
6165 this . setActiveNotebook ( ) ;
66+
67+ this . dataSource = new NotebookVariableDataSource ( this . notebookKernelService ) ;
68+ this . updateScheduler = new RunOnceScheduler ( ( ) => this . tree ?. updateChildren ( ) , 100 ) ;
6269 }
6370
6471 protected override renderBody ( container : HTMLElement ) : void {
@@ -70,7 +77,7 @@ export class NotebookVariablesView extends ViewPane {
7077 container ,
7178 new NotebookVariablesDelegate ( ) ,
7279 [ new NotebookVariableRenderer ( ) ] ,
73- new NotebookVariableDataSource ( this . notebookKernelService ) ,
80+ this . dataSource ,
7481 {
7582 accessibilityProvider : new NotebookVariableAccessibilityProvider ( ) ,
7683 identityProvider : { getId : ( e : INotebookVariableElement ) => e . id } ,
@@ -87,7 +94,7 @@ export class NotebookVariablesView extends ViewPane {
8794 this . tree ?. layout ( height , width ) ;
8895 }
8996
90- setActiveNotebook ( ) {
97+ private setActiveNotebook ( ) {
9198 const current = this . activeNotebook ;
9299 const activeEditorPane = this . editorService . activeEditorPane ;
93100 if ( activeEditorPane && activeEditorPane . getId ( ) === 'workbench.editor.notebook' ) {
@@ -101,23 +108,31 @@ export class NotebookVariablesView extends ViewPane {
101108 private handleActiveEditorChange ( ) {
102109 if ( this . setActiveNotebook ( ) && this . activeNotebook ) {
103110 this . tree ?. setInput ( { kind : 'root' , notebook : this . activeNotebook } ) ;
104- this . tree ?. updateChildren ( ) ;
111+ this . updateScheduler . schedule ( ) ;
105112 }
106113 }
107114
108115 private handleExecutionStateChange ( event : ICellExecutionStateChangedEvent | IExecutionStateChangedEvent ) {
109116 if ( this . activeNotebook ) {
110- // changed === undefined -> excecution ended
111- if ( event . changed === undefined && event . affectsNotebook ( this . activeNotebook ?. uri ) ) {
112- this . tree ?. updateChildren ( ) ;
117+ if ( event . affectsNotebook ( this . activeNotebook . uri ) ) {
118+ // new execution state means either new variables or the kernel is busy so we shouldn't ask
119+ this . dataSource . cancel ( ) ;
120+
121+ // changed === undefined -> excecution ended
122+ if ( event . changed === undefined ) {
123+ this . updateScheduler . schedule ( ) ;
124+ }
125+ else {
126+ this . updateScheduler . cancel ( ) ;
127+ }
113128 }
114129 }
115130 }
116131
117132 private handleVariablesChanged ( notebookUri : URI ) {
118133 if ( this . activeNotebook && notebookUri . toString ( ) === this . activeNotebook . uri . toString ( ) ) {
119134 this . tree ?. setInput ( { kind : 'root' , notebook : this . activeNotebook } ) ;
120- this . tree ?. updateChildren ( ) ;
135+ this . updateScheduler . schedule ( ) ;
121136 }
122137 }
123138}
0 commit comments