@jupyterlab/debugger 4.0.0-alpha.9 → 4.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/debugger.d.ts +3 -1
- package/lib/debugger.js +5 -3
- package/lib/debugger.js.map +1 -1
- package/lib/dialogs/evaluate.d.ts +5 -0
- package/lib/dialogs/evaluate.js +16 -6
- package/lib/dialogs/evaluate.js.map +1 -1
- package/lib/factory.d.ts +1 -1
- package/lib/factory.js +15 -9
- package/lib/factory.js.map +1 -1
- package/lib/handler.js +15 -7
- package/lib/handler.js.map +1 -1
- package/lib/handlers/console.js +9 -3
- package/lib/handlers/console.js.map +1 -1
- package/lib/handlers/editor.d.ts +26 -12
- package/lib/handlers/editor.js +166 -89
- package/lib/handlers/editor.js.map +1 -1
- package/lib/handlers/file.js +6 -2
- package/lib/handlers/file.js.map +1 -1
- package/lib/handlers/notebook.d.ts +0 -7
- package/lib/handlers/notebook.js +11 -17
- package/lib/handlers/notebook.js.map +1 -1
- package/lib/icons.d.ts +2 -1
- package/lib/icons.js +6 -1
- package/lib/icons.js.map +1 -1
- package/lib/model.js +1 -0
- package/lib/model.js.map +1 -1
- package/lib/panels/breakpoints/index.d.ts +2 -2
- package/lib/panels/breakpoints/index.js +9 -7
- package/lib/panels/breakpoints/index.js.map +1 -1
- package/lib/panels/breakpoints/pauseonexceptions.d.ts +53 -0
- package/lib/panels/breakpoints/pauseonexceptions.js +98 -0
- package/lib/panels/breakpoints/pauseonexceptions.js.map +1 -0
- package/lib/panels/callstack/index.d.ts +1 -1
- package/lib/panels/kernelSources/body.d.ts +5 -7
- package/lib/panels/kernelSources/body.js +37 -47
- package/lib/panels/kernelSources/body.js.map +1 -1
- package/lib/panels/kernelSources/filter.d.ts +1 -2
- package/lib/panels/kernelSources/filter.js +2 -2
- package/lib/panels/kernelSources/filter.js.map +1 -1
- package/lib/panels/kernelSources/index.js +1 -1
- package/lib/panels/kernelSources/index.js.map +1 -1
- package/lib/panels/kernelSources/model.d.ts +10 -1
- package/lib/panels/kernelSources/model.js +19 -1
- package/lib/panels/kernelSources/model.js.map +1 -1
- package/lib/panels/sources/body.js +5 -3
- package/lib/panels/sources/body.js.map +1 -1
- package/lib/panels/variables/grid.d.ts +10 -0
- package/lib/panels/variables/grid.js +28 -351
- package/lib/panels/variables/grid.js.map +1 -1
- package/lib/panels/variables/gridpanel.d.ts +140 -0
- package/lib/panels/variables/gridpanel.js +363 -0
- package/lib/panels/variables/gridpanel.js.map +1 -0
- package/lib/panels/variables/mimerenderer.js +9 -1
- package/lib/panels/variables/mimerenderer.js.map +1 -1
- package/lib/panels/variables/scope.js +4 -0
- package/lib/panels/variables/scope.js.map +1 -1
- package/lib/panels/variables/tree.d.ts +1 -0
- package/lib/panels/variables/tree.js +136 -47
- package/lib/panels/variables/tree.js.map +1 -1
- package/lib/service.d.ts +20 -6
- package/lib/service.js +84 -59
- package/lib/service.js.map +1 -1
- package/lib/session.d.ts +20 -6
- package/lib/session.js +59 -11
- package/lib/session.js.map +1 -1
- package/lib/sidebar.js +1 -1
- package/lib/sources.d.ts +2 -2
- package/lib/sources.js +32 -17
- package/lib/sources.js.map +1 -1
- package/lib/tokens.d.ts +57 -13
- package/lib/tokens.js.map +1 -1
- package/package.json +38 -46
- package/src/config.ts +78 -0
- package/src/debugger.ts +154 -0
- package/src/dialogs/evaluate.ts +144 -0
- package/src/factory.ts +72 -0
- package/src/handler.ts +528 -0
- package/src/handlers/console.ts +118 -0
- package/src/handlers/editor.ts +469 -0
- package/src/handlers/file.ts +86 -0
- package/src/handlers/notebook.ts +128 -0
- package/src/hash.ts +69 -0
- package/src/icons.ts +64 -0
- package/src/index.ts +16 -0
- package/src/model.ts +155 -0
- package/src/panels/breakpoints/body.tsx +145 -0
- package/src/panels/breakpoints/index.ts +116 -0
- package/src/panels/breakpoints/model.ts +74 -0
- package/src/panels/breakpoints/pauseonexceptions.tsx +141 -0
- package/src/panels/callstack/body.tsx +96 -0
- package/src/panels/callstack/index.ts +152 -0
- package/src/panels/callstack/model.ts +86 -0
- package/src/panels/kernelSources/body.tsx +139 -0
- package/src/panels/kernelSources/filter.tsx +44 -0
- package/src/panels/kernelSources/index.tsx +106 -0
- package/src/panels/kernelSources/model.ts +160 -0
- package/src/panels/sources/body.ts +161 -0
- package/src/panels/sources/index.tsx +85 -0
- package/src/panels/sources/model.ts +94 -0
- package/src/panels/sources/sourcepath.tsx +28 -0
- package/src/panels/variables/grid.ts +144 -0
- package/src/panels/variables/gridpanel.ts +455 -0
- package/src/panels/variables/index.ts +199 -0
- package/src/panels/variables/mimerenderer.ts +125 -0
- package/src/panels/variables/model.ts +61 -0
- package/src/panels/variables/scope.tsx +132 -0
- package/src/panels/variables/tree.tsx +521 -0
- package/src/service.ts +1009 -0
- package/src/session.ts +342 -0
- package/src/sidebar.ts +194 -0
- package/src/sources.ts +327 -0
- package/src/svg.d.ts +9 -0
- package/src/tokens.ts +1071 -0
- package/style/breakpoints.css +21 -12
- package/style/icons/exceptions.svg +10 -0
- package/style/index.css +1 -1
- package/style/index.js +1 -1
- package/style/kernelSources.css +3 -0
- package/style/variables.css +68 -21
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
|
|
4
|
+
import { IThemeManager } from '@jupyterlab/apputils';
|
|
5
|
+
import { ITranslator, nullTranslator } from '@jupyterlab/translation';
|
|
6
|
+
import {
|
|
7
|
+
PanelWithToolbar,
|
|
8
|
+
tableRowsIcon,
|
|
9
|
+
ToolbarButton,
|
|
10
|
+
treeViewIcon
|
|
11
|
+
} from '@jupyterlab/ui-components';
|
|
12
|
+
import { CommandRegistry } from '@lumino/commands';
|
|
13
|
+
import { Panel, Widget } from '@lumino/widgets';
|
|
14
|
+
import { IDebugger } from '../../tokens';
|
|
15
|
+
import { VariablesBodyGrid } from './grid';
|
|
16
|
+
import { ScopeSwitcher } from './scope';
|
|
17
|
+
import { VariablesBodyTree } from './tree';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A Panel to show a variable explorer.
|
|
21
|
+
*/
|
|
22
|
+
export class Variables extends PanelWithToolbar {
|
|
23
|
+
/**
|
|
24
|
+
* Instantiate a new Variables Panel.
|
|
25
|
+
*
|
|
26
|
+
* @param options The instantiation options for a Variables Panel.
|
|
27
|
+
*/
|
|
28
|
+
constructor(options: Variables.IOptions) {
|
|
29
|
+
super(options);
|
|
30
|
+
const { model, service, commands, themeManager } = options;
|
|
31
|
+
const translator = options.translator || nullTranslator;
|
|
32
|
+
const trans = translator.load('jupyterlab');
|
|
33
|
+
this.title.label = trans.__('Variables');
|
|
34
|
+
this.toolbar.addClass('jp-DebuggerVariables-toolbar');
|
|
35
|
+
this._tree = new VariablesBodyTree({
|
|
36
|
+
model,
|
|
37
|
+
service,
|
|
38
|
+
commands,
|
|
39
|
+
translator
|
|
40
|
+
});
|
|
41
|
+
this._table = new VariablesBodyGrid({
|
|
42
|
+
model,
|
|
43
|
+
commands,
|
|
44
|
+
themeManager,
|
|
45
|
+
translator
|
|
46
|
+
});
|
|
47
|
+
this._table.hide();
|
|
48
|
+
|
|
49
|
+
this.toolbar.addItem(
|
|
50
|
+
'scope-switcher',
|
|
51
|
+
new ScopeSwitcher({
|
|
52
|
+
translator,
|
|
53
|
+
model,
|
|
54
|
+
tree: this._tree,
|
|
55
|
+
grid: this._table
|
|
56
|
+
})
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const onViewChange = (): void => {
|
|
60
|
+
if (this._table.isHidden) {
|
|
61
|
+
this._tree.hide();
|
|
62
|
+
this._table.show();
|
|
63
|
+
this.node.setAttribute('data-jp-table', 'true');
|
|
64
|
+
markViewButtonSelection('table');
|
|
65
|
+
} else {
|
|
66
|
+
this._tree.show();
|
|
67
|
+
this._table.hide();
|
|
68
|
+
this.node.removeAttribute('data-jp-table');
|
|
69
|
+
markViewButtonSelection('tree');
|
|
70
|
+
}
|
|
71
|
+
this.update();
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const treeViewButton = new ToolbarButton({
|
|
75
|
+
icon: treeViewIcon,
|
|
76
|
+
className: 'jp-TreeView',
|
|
77
|
+
onClick: onViewChange,
|
|
78
|
+
tooltip: trans.__('Tree View')
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const tableViewButton = new ToolbarButton({
|
|
82
|
+
icon: tableRowsIcon,
|
|
83
|
+
className: 'jp-TableView',
|
|
84
|
+
onClick: onViewChange,
|
|
85
|
+
tooltip: trans.__('Table View')
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const markViewButtonSelection = (selectedView: string): void => {
|
|
89
|
+
const viewModeClassName = 'jp-ViewModeSelected';
|
|
90
|
+
|
|
91
|
+
if (selectedView === 'tree') {
|
|
92
|
+
tableViewButton.removeClass(viewModeClassName);
|
|
93
|
+
treeViewButton.addClass(viewModeClassName);
|
|
94
|
+
} else {
|
|
95
|
+
treeViewButton.removeClass(viewModeClassName);
|
|
96
|
+
tableViewButton.addClass(viewModeClassName);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
markViewButtonSelection(this._table.isHidden ? 'tree' : 'table');
|
|
101
|
+
|
|
102
|
+
this.toolbar.addItem('view-VariableTreeView', treeViewButton);
|
|
103
|
+
|
|
104
|
+
this.toolbar.addItem('view-VariableTableView', tableViewButton);
|
|
105
|
+
|
|
106
|
+
this.addWidget(this._tree);
|
|
107
|
+
this.addWidget(this._table);
|
|
108
|
+
this.addClass('jp-DebuggerVariables');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Set the variable filter for both the tree and table views.
|
|
113
|
+
*/
|
|
114
|
+
set filter(filter: Set<string>) {
|
|
115
|
+
this._tree.filter = filter;
|
|
116
|
+
this._table.filter = filter;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* A message handler invoked on a `'resize'` message.
|
|
121
|
+
*
|
|
122
|
+
* @param msg The Lumino message to process.
|
|
123
|
+
*/
|
|
124
|
+
protected onResize(msg: Widget.ResizeMessage): void {
|
|
125
|
+
super.onResize(msg);
|
|
126
|
+
this._resizeBody(msg);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Resize the body.
|
|
131
|
+
*
|
|
132
|
+
* @param msg The resize message.
|
|
133
|
+
*/
|
|
134
|
+
private _resizeBody(msg: Widget.ResizeMessage): void {
|
|
135
|
+
const height = msg.height - this.toolbar.node.offsetHeight;
|
|
136
|
+
this._tree.node.style.height = `${height}px`;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
private _tree: VariablesBodyTree;
|
|
140
|
+
private _table: VariablesBodyGrid;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Convert a variable to a primitive type.
|
|
145
|
+
*
|
|
146
|
+
* @param variable The variable.
|
|
147
|
+
*/
|
|
148
|
+
export const convertType = (variable: IDebugger.IVariable): string | number => {
|
|
149
|
+
const { type, value } = variable;
|
|
150
|
+
switch (type) {
|
|
151
|
+
case 'int':
|
|
152
|
+
return parseInt(value, 10);
|
|
153
|
+
case 'float':
|
|
154
|
+
return parseFloat(value);
|
|
155
|
+
case 'bool':
|
|
156
|
+
return value;
|
|
157
|
+
case 'str':
|
|
158
|
+
if (variable.presentationHint?.attributes?.includes('rawString')) {
|
|
159
|
+
return value.slice(1, value.length - 1);
|
|
160
|
+
} else {
|
|
161
|
+
return value;
|
|
162
|
+
}
|
|
163
|
+
default:
|
|
164
|
+
return type ?? value;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* A namespace for Variables `statics`.
|
|
170
|
+
*/
|
|
171
|
+
export namespace Variables {
|
|
172
|
+
/**
|
|
173
|
+
* Instantiation options for `Variables`.
|
|
174
|
+
*/
|
|
175
|
+
export interface IOptions extends Panel.IOptions {
|
|
176
|
+
/**
|
|
177
|
+
* The variables model.
|
|
178
|
+
*/
|
|
179
|
+
model: IDebugger.Model.IVariables;
|
|
180
|
+
/**
|
|
181
|
+
* The debugger service.
|
|
182
|
+
*/
|
|
183
|
+
service: IDebugger;
|
|
184
|
+
/**
|
|
185
|
+
* The commands registry.
|
|
186
|
+
*/
|
|
187
|
+
commands: CommandRegistry;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* An optional application theme manager to detect theme changes.
|
|
191
|
+
*/
|
|
192
|
+
themeManager?: IThemeManager | null;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* The application language translator
|
|
196
|
+
*/
|
|
197
|
+
translator?: ITranslator;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Jupyter Development Team.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { MainAreaWidget } from '@jupyterlab/apputils';
|
|
7
|
+
import { IRenderMimeRegistry, MimeModel } from '@jupyterlab/rendermime';
|
|
8
|
+
import {
|
|
9
|
+
ITranslator,
|
|
10
|
+
nullTranslator,
|
|
11
|
+
TranslationBundle
|
|
12
|
+
} from '@jupyterlab/translation';
|
|
13
|
+
import { PromiseDelegate } from '@lumino/coreutils';
|
|
14
|
+
import { Panel } from '@lumino/widgets';
|
|
15
|
+
import { murmur2 } from '../../hash';
|
|
16
|
+
import { IDebugger } from '../../tokens';
|
|
17
|
+
|
|
18
|
+
const RENDERER_PANEL_CLASS = 'jp-VariableRendererPanel';
|
|
19
|
+
const RENDERER_PANEL_RENDERER_CLASS = 'jp-VariableRendererPanel-renderer';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Debugger variable mime type renderer
|
|
23
|
+
*/
|
|
24
|
+
export class VariableMimeRenderer extends MainAreaWidget<Panel> {
|
|
25
|
+
/**
|
|
26
|
+
* Instantiate a new VariableMimeRenderer.
|
|
27
|
+
*/
|
|
28
|
+
constructor(options: VariableMimeRenderer.IOptions) {
|
|
29
|
+
const { dataLoader, rendermime, translator } = options;
|
|
30
|
+
const content = new Panel();
|
|
31
|
+
const loaded = new PromiseDelegate<void>();
|
|
32
|
+
super({
|
|
33
|
+
content,
|
|
34
|
+
reveal: Promise.all([dataLoader, loaded.promise])
|
|
35
|
+
});
|
|
36
|
+
this.content.addClass(RENDERER_PANEL_CLASS);
|
|
37
|
+
this.trans = (translator ?? nullTranslator).load('jupyterlab');
|
|
38
|
+
this.dataLoader = dataLoader;
|
|
39
|
+
this.renderMime = rendermime;
|
|
40
|
+
this._dataHash = null;
|
|
41
|
+
|
|
42
|
+
this.refresh()
|
|
43
|
+
.then(() => {
|
|
44
|
+
loaded.resolve();
|
|
45
|
+
})
|
|
46
|
+
.catch(reason => loaded.reject(reason));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Refresh the variable view
|
|
51
|
+
*/
|
|
52
|
+
async refresh(force = false): Promise<void> {
|
|
53
|
+
let data = await this.dataLoader();
|
|
54
|
+
|
|
55
|
+
if (Object.keys(data.data).length === 0) {
|
|
56
|
+
data = {
|
|
57
|
+
data: {
|
|
58
|
+
'text/plain': this.trans.__(
|
|
59
|
+
'The variable is undefined in the active context.'
|
|
60
|
+
)
|
|
61
|
+
},
|
|
62
|
+
metadata: {}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (data.data) {
|
|
67
|
+
const hash = murmur2(JSON.stringify(data), 17);
|
|
68
|
+
if (force || this._dataHash !== hash) {
|
|
69
|
+
if (this.content.layout) {
|
|
70
|
+
this.content.widgets.forEach(w => {
|
|
71
|
+
this.content.layout!.removeWidget(w);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// We trust unconditionally the data as the user is required to
|
|
76
|
+
// execute the code to load a particular variable in memory
|
|
77
|
+
const mimeType = this.renderMime.preferredMimeType(data.data, 'any');
|
|
78
|
+
|
|
79
|
+
if (mimeType) {
|
|
80
|
+
const widget = this.renderMime.createRenderer(mimeType);
|
|
81
|
+
widget.addClass(RENDERER_PANEL_RENDERER_CLASS);
|
|
82
|
+
const model = new MimeModel({ ...data, trusted: true });
|
|
83
|
+
this._dataHash = hash;
|
|
84
|
+
await widget.renderModel(model);
|
|
85
|
+
|
|
86
|
+
this.content.addWidget(widget);
|
|
87
|
+
} else {
|
|
88
|
+
this._dataHash = null;
|
|
89
|
+
return Promise.reject('Unable to determine the preferred mime type.');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
this._dataHash = null;
|
|
94
|
+
return Promise.reject('Unable to get a view on the variable.');
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
protected dataLoader: () => Promise<IDebugger.IRichVariable>;
|
|
99
|
+
protected renderMime: IRenderMimeRegistry;
|
|
100
|
+
protected trans: TranslationBundle;
|
|
101
|
+
private _dataHash: number | null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Debugger variable mime type renderer namespace
|
|
106
|
+
*/
|
|
107
|
+
export namespace VariableMimeRenderer {
|
|
108
|
+
/**
|
|
109
|
+
* Constructor options
|
|
110
|
+
*/
|
|
111
|
+
export interface IOptions {
|
|
112
|
+
/**
|
|
113
|
+
* Loader of the variable to be rendered
|
|
114
|
+
*/
|
|
115
|
+
dataLoader: () => Promise<IDebugger.IRichVariable>;
|
|
116
|
+
/**
|
|
117
|
+
* Render mime type registry
|
|
118
|
+
*/
|
|
119
|
+
rendermime: IRenderMimeRegistry;
|
|
120
|
+
/**
|
|
121
|
+
* Translation manager
|
|
122
|
+
*/
|
|
123
|
+
translator?: ITranslator;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Copyright (c) Jupyter Development Team.
|
|
2
|
+
// Distributed under the terms of the Modified BSD License.
|
|
3
|
+
|
|
4
|
+
import { ISignal, Signal } from '@lumino/signaling';
|
|
5
|
+
|
|
6
|
+
import { IDebugger } from '../../tokens';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A model for a variable explorer.
|
|
10
|
+
*/
|
|
11
|
+
export class VariablesModel implements IDebugger.Model.IVariables {
|
|
12
|
+
/**
|
|
13
|
+
* Get all the scopes.
|
|
14
|
+
*/
|
|
15
|
+
get scopes(): IDebugger.IScope[] {
|
|
16
|
+
return this._state;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Set the scopes.
|
|
21
|
+
*/
|
|
22
|
+
set scopes(scopes: IDebugger.IScope[]) {
|
|
23
|
+
this._state = scopes;
|
|
24
|
+
this._changed.emit();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Signal emitted when the current variable has changed.
|
|
29
|
+
*/
|
|
30
|
+
get changed(): ISignal<this, void> {
|
|
31
|
+
return this._changed;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Signal emitted when the current variable has been expanded.
|
|
36
|
+
*/
|
|
37
|
+
get variableExpanded(): ISignal<this, IDebugger.IVariable> {
|
|
38
|
+
return this._variableExpanded;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
get selectedVariable(): IDebugger.IVariableSelection | null {
|
|
42
|
+
return this._selectedVariable;
|
|
43
|
+
}
|
|
44
|
+
set selectedVariable(selection: IDebugger.IVariableSelection | null) {
|
|
45
|
+
this._selectedVariable = selection;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Expand a variable.
|
|
50
|
+
*
|
|
51
|
+
* @param variable The variable to expand.
|
|
52
|
+
*/
|
|
53
|
+
expandVariable(variable: IDebugger.IVariable): void {
|
|
54
|
+
this._variableExpanded.emit(variable);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private _selectedVariable: IDebugger.IVariableSelection | null = null;
|
|
58
|
+
private _state: IDebugger.IScope[] = [];
|
|
59
|
+
private _variableExpanded = new Signal<this, IDebugger.IVariable>(this);
|
|
60
|
+
private _changed = new Signal<this, void>(this);
|
|
61
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) Jupyter Development Team.
|
|
3
|
+
* Distributed under the terms of the Modified BSD License.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
ITranslator,
|
|
8
|
+
nullTranslator,
|
|
9
|
+
TranslationBundle
|
|
10
|
+
} from '@jupyterlab/translation';
|
|
11
|
+
import { HTMLSelect, ReactWidget, UseSignal } from '@jupyterlab/ui-components';
|
|
12
|
+
import React, { useState } from 'react';
|
|
13
|
+
import { IDebugger } from '../../tokens';
|
|
14
|
+
import { VariablesBodyGrid } from './grid';
|
|
15
|
+
import { VariablesBodyTree } from './tree';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A React component to handle scope changes.
|
|
19
|
+
*
|
|
20
|
+
* @param {object} props The component props.
|
|
21
|
+
* @param props.model The variables model.
|
|
22
|
+
* @param props.tree The variables tree widget.
|
|
23
|
+
* @param props.grid The variables grid widget.
|
|
24
|
+
* @param props.trans The translation bundle.
|
|
25
|
+
*/
|
|
26
|
+
const ScopeSwitcherComponent = ({
|
|
27
|
+
model,
|
|
28
|
+
tree,
|
|
29
|
+
grid,
|
|
30
|
+
trans
|
|
31
|
+
}: {
|
|
32
|
+
model: IDebugger.Model.IVariables;
|
|
33
|
+
tree: VariablesBodyTree;
|
|
34
|
+
grid: VariablesBodyGrid;
|
|
35
|
+
trans: TranslationBundle;
|
|
36
|
+
}): JSX.Element => {
|
|
37
|
+
const [value, setValue] = useState('-');
|
|
38
|
+
const scopes = model.scopes;
|
|
39
|
+
|
|
40
|
+
const onChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
|
|
41
|
+
const value = event.target.value;
|
|
42
|
+
setValue(value);
|
|
43
|
+
tree.scope = value;
|
|
44
|
+
grid.scope = value;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<HTMLSelect
|
|
49
|
+
onChange={onChange}
|
|
50
|
+
value={value}
|
|
51
|
+
aria-label={trans.__('Scope')}
|
|
52
|
+
>
|
|
53
|
+
{scopes.map(scope => (
|
|
54
|
+
<option key={scope.name} value={scope.name}>
|
|
55
|
+
{trans.__(scope.name)}
|
|
56
|
+
</option>
|
|
57
|
+
))}
|
|
58
|
+
</HTMLSelect>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* A widget to switch between scopes.
|
|
64
|
+
*/
|
|
65
|
+
export class ScopeSwitcher extends ReactWidget {
|
|
66
|
+
/**
|
|
67
|
+
* Instantiate a new scope switcher.
|
|
68
|
+
*
|
|
69
|
+
* @param options The instantiation options for a ScopeSwitcher
|
|
70
|
+
*/
|
|
71
|
+
constructor(options: ScopeSwitcher.IOptions) {
|
|
72
|
+
super();
|
|
73
|
+
const { translator, model, tree, grid } = options;
|
|
74
|
+
this._model = model;
|
|
75
|
+
this._tree = tree;
|
|
76
|
+
this._grid = grid;
|
|
77
|
+
this._trans = (translator || nullTranslator).load('jupyterlab');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Render the scope switcher.
|
|
82
|
+
*/
|
|
83
|
+
render(): JSX.Element {
|
|
84
|
+
return (
|
|
85
|
+
<UseSignal signal={this._model.changed} initialSender={this._model}>
|
|
86
|
+
{(): JSX.Element => (
|
|
87
|
+
<ScopeSwitcherComponent
|
|
88
|
+
model={this._model}
|
|
89
|
+
trans={this._trans}
|
|
90
|
+
tree={this._tree}
|
|
91
|
+
grid={this._grid}
|
|
92
|
+
/>
|
|
93
|
+
)}
|
|
94
|
+
</UseSignal>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private _model: IDebugger.Model.IVariables;
|
|
99
|
+
private _tree: VariablesBodyTree;
|
|
100
|
+
private _grid: VariablesBodyGrid;
|
|
101
|
+
private _trans: TranslationBundle;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* A namespace for ScopeSwitcher statics
|
|
106
|
+
*/
|
|
107
|
+
export namespace ScopeSwitcher {
|
|
108
|
+
/**
|
|
109
|
+
* The ScopeSwitcher instantiation options.
|
|
110
|
+
*/
|
|
111
|
+
export interface IOptions {
|
|
112
|
+
/**
|
|
113
|
+
* The variables model.
|
|
114
|
+
*/
|
|
115
|
+
model: IDebugger.Model.IVariables;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The variables tree viewer.
|
|
119
|
+
*/
|
|
120
|
+
tree: VariablesBodyTree;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The variables table viewer.
|
|
124
|
+
*/
|
|
125
|
+
grid: VariablesBodyGrid;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* An optional translator.
|
|
129
|
+
*/
|
|
130
|
+
translator?: ITranslator;
|
|
131
|
+
}
|
|
132
|
+
}
|