3
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
4
*--------------------------------------------------------------------------------------------*/
5
5
6
+ import { RunOnceScheduler } from 'vs/base/common/async' ;
6
7
import { URI } from 'vs/base/common/uri' ;
7
8
import * as nls from 'vs/nls' ;
8
9
import { ILocalizedString } from 'vs/platform/action/common/action' ;
@@ -34,6 +35,9 @@ export class NotebookVariablesView extends ViewPane {
34
35
35
36
private tree : WorkbenchAsyncDataTree < INotebookScope , INotebookVariableElement > | undefined ;
36
37
private activeNotebook : NotebookTextModel | undefined ;
38
+ private readonly dataSource : NotebookVariableDataSource ;
39
+
40
+ private updateScheduler : RunOnceScheduler ;
37
41
38
42
constructor (
39
43
options : IViewPaneOptions ,
@@ -59,6 +63,9 @@ export class NotebookVariablesView extends ViewPane {
59
63
this . _register ( this . notebookExecutionStateService . onDidChangeExecution ( this . handleExecutionStateChange . bind ( this ) ) ) ;
60
64
61
65
this . setActiveNotebook ( ) ;
66
+
67
+ this . dataSource = new NotebookVariableDataSource ( this . notebookKernelService ) ;
68
+ this . updateScheduler = new RunOnceScheduler ( ( ) => this . tree ?. updateChildren ( ) , 100 ) ;
62
69
}
63
70
64
71
protected override renderBody ( container : HTMLElement ) : void {
@@ -70,7 +77,7 @@ export class NotebookVariablesView extends ViewPane {
70
77
container ,
71
78
new NotebookVariablesDelegate ( ) ,
72
79
[ new NotebookVariableRenderer ( ) ] ,
73
- new NotebookVariableDataSource ( this . notebookKernelService ) ,
80
+ this . dataSource ,
74
81
{
75
82
accessibilityProvider : new NotebookVariableAccessibilityProvider ( ) ,
76
83
identityProvider : { getId : ( e : INotebookVariableElement ) => e . id } ,
@@ -87,7 +94,7 @@ export class NotebookVariablesView extends ViewPane {
87
94
this . tree ?. layout ( height , width ) ;
88
95
}
89
96
90
- setActiveNotebook ( ) {
97
+ private setActiveNotebook ( ) {
91
98
const current = this . activeNotebook ;
92
99
const activeEditorPane = this . editorService . activeEditorPane ;
93
100
if ( activeEditorPane && activeEditorPane . getId ( ) === 'workbench.editor.notebook' ) {
@@ -101,23 +108,31 @@ export class NotebookVariablesView extends ViewPane {
101
108
private handleActiveEditorChange ( ) {
102
109
if ( this . setActiveNotebook ( ) && this . activeNotebook ) {
103
110
this . tree ?. setInput ( { kind : 'root' , notebook : this . activeNotebook } ) ;
104
- this . tree ?. updateChildren ( ) ;
111
+ this . updateScheduler . schedule ( ) ;
105
112
}
106
113
}
107
114
108
115
private handleExecutionStateChange ( event : ICellExecutionStateChangedEvent | IExecutionStateChangedEvent ) {
109
116
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
+ }
113
128
}
114
129
}
115
130
}
116
131
117
132
private handleVariablesChanged ( notebookUri : URI ) {
118
133
if ( this . activeNotebook && notebookUri . toString ( ) === this . activeNotebook . uri . toString ( ) ) {
119
134
this . tree ?. setInput ( { kind : 'root' , notebook : this . activeNotebook } ) ;
120
- this . tree ?. updateChildren ( ) ;
135
+ this . updateScheduler . schedule ( ) ;
121
136
}
122
137
}
123
138
}
0 commit comments