Skip to content

Commit f76f831

Browse files
committed
more instantiation fixes
1 parent 9b313c3 commit f76f831

File tree

6 files changed

+188
-67
lines changed

6 files changed

+188
-67
lines changed

src/vs/workbench/contrib/debug/browser/debug.contribution.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ import { BREAKPOINTS_VIEW_ID, BREAKPOINT_EDITOR_CONTRIBUTION_ID, CALLSTACK_VIEW_
5252
import { DebugContentProvider } from 'vs/workbench/contrib/debug/common/debugContentProvider';
5353
import { DebugLifecycle } from 'vs/workbench/contrib/debug/common/debugLifecycle';
5454
import { DisassemblyViewInput } from 'vs/workbench/contrib/debug/common/disassemblyViewInput';
55-
import { NotebookVariablesView } from 'vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesView';
56-
import { NOTEBOOK_KERNEL } from 'vs/workbench/contrib/notebook/common/notebookContextKeys';
5755
import { launchSchemaId } from 'vs/workbench/services/configuration/common/configuration';
5856
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
5957

@@ -415,7 +413,6 @@ viewsRegistry.registerViews([{ id: CALLSTACK_VIEW_ID, name: nls.localize2('callS
415413
viewsRegistry.registerViews([{ id: BREAKPOINTS_VIEW_ID, name: nls.localize2('breakpoints', "Breakpoints"), containerIcon: icons.breakpointsViewIcon, ctorDescriptor: new SyncDescriptor(BreakpointsView), order: 40, weight: 20, canToggleVisibility: true, canMoveView: true, focusCommand: { id: 'workbench.debug.action.focusBreakpointsView' }, when: ContextKeyExpr.or(CONTEXT_BREAKPOINTS_EXIST, CONTEXT_DEBUG_UX.isEqualTo('default'), CONTEXT_HAS_DEBUGGED) }], viewContainer);
416414
viewsRegistry.registerViews([{ id: WelcomeView.ID, name: WelcomeView.LABEL, containerIcon: icons.runViewIcon, ctorDescriptor: new SyncDescriptor(WelcomeView), order: 1, weight: 40, canToggleVisibility: true, when: CONTEXT_DEBUG_UX.isEqualTo('simple') }], viewContainer);
417415
viewsRegistry.registerViews([{ id: LOADED_SCRIPTS_VIEW_ID, name: nls.localize2('loadedScripts', "Loaded Scripts"), containerIcon: icons.loadedScriptsViewIcon, ctorDescriptor: new SyncDescriptor(LoadedScriptsView), order: 35, weight: 5, canToggleVisibility: true, canMoveView: true, collapsed: true, when: ContextKeyExpr.and(CONTEXT_LOADED_SCRIPTS_SUPPORTED, CONTEXT_DEBUG_UX.isEqualTo('default')) }], viewContainer);
418-
viewsRegistry.registerViews([{ id: LOADED_SCRIPTS_VIEW_ID, name: nls.localize2('notebookVariables', "Notebook Variables"), containerIcon: icons.variablesViewIcon, ctorDescriptor: new SyncDescriptor(NotebookVariablesView), order: 50, weight: 5, canToggleVisibility: true, canMoveView: true, collapsed: true, when: NOTEBOOK_KERNEL }], viewContainer);
419416

420417
// Register disassembly view
421418

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import * as nls from 'vs/nls';
7+
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
8+
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
9+
import { Registry } from 'vs/platform/registry/common/platform';
10+
import { Extensions, IViewContainersRegistry, IViewsRegistry } from 'vs/workbench/common/views';
11+
import { VIEWLET_ID as debugContainerId } from 'vs/workbench/contrib/debug/common/debug';
12+
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
13+
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
14+
import { NotebookVariablesView } from 'vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesView';
15+
import { NOTEBOOK_KERNEL } from 'vs/workbench/contrib/notebook/common/notebookContextKeys';
16+
import { variablesViewIcon } from 'vs/workbench/contrib/notebook/browser/notebookIcons';
17+
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
18+
19+
20+
export class NotebookVariables extends Disposable implements IWorkbenchContribution {
21+
private listener: IDisposable;
22+
23+
constructor(
24+
@IEditorService private readonly editorService: IEditorService
25+
) {
26+
super();
27+
this.initializeView();
28+
29+
this.listener = this.editorService.onDidEditorsChange(() => {
30+
if (this.editorService.activeEditorPane?.getId() === 'workbench.editor.notebook') {
31+
this.listener.dispose();
32+
this.initializeView();
33+
}
34+
});
35+
}
36+
37+
private async initializeView() {
38+
39+
const debugViewContainer = Registry.as<IViewContainersRegistry>('workbench.registry.view.containers').get(debugContainerId);
40+
41+
if (debugViewContainer) {
42+
const viewsRegistry = Registry.as<IViewsRegistry>(Extensions.ViewsRegistry);
43+
const viewDescriptor = {
44+
id: 'NOTEBOOK_VARIABLES', name: nls.localize2('notebookVariables', "Notebook Variables"), containerIcon: variablesViewIcon, ctorDescriptor: new SyncDescriptor(NotebookVariablesView),
45+
order: 50, weight: 5, canToggleVisibility: true, canMoveView: true, collapsed: true, when: ContextKeyExpr.notEquals(NOTEBOOK_KERNEL.key, ''),
46+
};
47+
48+
viewsRegistry.registerViews([viewDescriptor], debugViewContainer);
49+
}
50+
51+
}
52+
53+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { IListVirtualDelegate } from 'vs/base/browser/ui/list/list';
7+
import { IListAccessibilityProvider } from 'vs/base/browser/ui/list/listWidget';
8+
import { IAsyncDataSource, ITreeNode, ITreeRenderer } from 'vs/base/browser/ui/tree/tree';
9+
import { FuzzyScore } from 'vs/base/common/filters';
10+
import { localize } from 'vs/nls';
11+
import { WorkbenchAsyncDataTree } from 'vs/platform/list/browser/listService';
12+
13+
export abstract class VariablesSession {
14+
abstract getVariables(): Promise<IVariableTreeElement[]>;
15+
}
16+
17+
export interface IVariableTreeElement {
18+
readonly id: string;
19+
readonly label: string;
20+
readonly value: string;
21+
readonly hasChildren: boolean;
22+
getChildren(): Promise<IVariableTreeElement[]>;
23+
}
24+
25+
export class NotebookVariablesTree extends WorkbenchAsyncDataTree<VariablesSession, IVariableTreeElement, FuzzyScore> { }
26+
27+
export class NotebookVariablesDelegate implements IListVirtualDelegate<IVariableTreeElement> {
28+
29+
getHeight(element: IVariableTreeElement): number {
30+
return 22;
31+
}
32+
33+
getTemplateId(element: IVariableTreeElement): string {
34+
return 'variableElement';
35+
}
36+
}
37+
38+
export class NotebookVariableRenderer implements ITreeRenderer<IVariableTreeElement, FuzzyScore, { container: HTMLElement }> {
39+
40+
get templateId(): string {
41+
return 'variableElement';
42+
}
43+
44+
renderTemplate(container: HTMLElement) {
45+
return { container };
46+
}
47+
48+
renderElement(element: ITreeNode<IVariableTreeElement, FuzzyScore>, index: number, templateData: { container: HTMLElement }, height: number | undefined): void {
49+
templateData.container.innerText = element.element.label;
50+
}
51+
52+
disposeTemplate(): void {
53+
// noop
54+
}
55+
}
56+
57+
export class NotebookVariablesDataSource implements IAsyncDataSource<VariablesSession, IVariableTreeElement> {
58+
59+
hasChildren(element: VariablesSession | IVariableTreeElement): boolean {
60+
if (element instanceof VariablesSession) {
61+
return true;
62+
}
63+
return element.hasChildren;
64+
}
65+
66+
getChildren(element: VariablesSession | IVariableTreeElement): Promise<IVariableTreeElement[]> {
67+
if (element instanceof VariablesSession) {
68+
return element.getVariables();
69+
}
70+
71+
return element.getChildren();
72+
}
73+
}
74+
75+
export class NotebookVariableAccessibilityProvider implements IListAccessibilityProvider<IVariableTreeElement> {
76+
77+
getWidgetAriaLabel(): string {
78+
return localize('debugConsole', "Notebook Variables");
79+
}
80+
81+
getAriaLabel(element: IVariableTreeElement): string {
82+
return localize('notebookVariableAriaLabel', "Variable {0}, value {1}", element.label, element.value);
83+
}
84+
}
85+
86+
export class MockVariables extends VariablesSession {
87+
override getVariables(): Promise<IVariableTreeElement[]> {
88+
return Promise.resolve([
89+
{
90+
id: '1',
91+
label: 'Variable 1',
92+
value: 'Value 1',
93+
hasChildren: true,
94+
getChildren: async () => [
95+
{
96+
id: '1.1',
97+
label: 'Child Variable 1',
98+
value: 'Child Value 1',
99+
hasChildren: false,
100+
getChildren: async () => []
101+
},
102+
{
103+
id: '1.2',
104+
label: 'Child Variable 2',
105+
value: 'Child Value 2',
106+
hasChildren: false,
107+
getChildren: async () => []
108+
}
109+
]
110+
},
111+
{
112+
id: '2',
113+
label: 'Variable 2',
114+
value: 'Value 2',
115+
hasChildren: false,
116+
getChildren: async () => []
117+
}
118+
]);
119+
}
120+
}

src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesView.ts

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@ import { ICommandService } from 'vs/platform/commands/common/commands';
99
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
1010
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
1111
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
12-
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
1312
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
1413
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
1514
import { IOpenerService } from 'vs/platform/opener/common/opener';
1615
import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput';
1716
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
1817
import { IThemeService } from 'vs/platform/theme/common/themeService';
1918
import { IViewPaneOptions, ViewPane } from 'vs/workbench/browser/parts/views/viewPane';
20-
import { IViewDescriptor, IViewDescriptorService } from 'vs/workbench/common/views';
19+
import { IViewDescriptorService } from 'vs/workbench/common/views';
20+
import { MockVariables, NotebookVariableAccessibilityProvider, NotebookVariableRenderer, NotebookVariablesDataSource, NotebookVariablesDelegate, NotebookVariablesTree } from 'vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesTree';
2121
import { getNotebookEditorFromEditorPane } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
22-
import { variablesViewIcon } from 'vs/workbench/contrib/notebook/browser/notebookIcons';
2322
import { INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService';
2423
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
2524

@@ -28,6 +27,8 @@ export class NotebookVariablesView extends ViewPane {
2827
static readonly ID = 'notebookVariablesView';
2928
static readonly TITLE: ILocalizedString = nls.localize2('notebook.notebookVariables', "Notebook Variables");
3029

30+
private tree: NotebookVariablesTree | undefined;
31+
3132
constructor(
3233
options: IViewPaneOptions,
3334
@IEditorService private readonly editorService: IEditorService,
@@ -49,6 +50,16 @@ export class NotebookVariablesView extends ViewPane {
4950
this._register(this.editorService.onDidActiveEditorChange(this.handleActiveEditorChange));
5051
}
5152

53+
public override renderBody(container: HTMLElement): void {
54+
this.tree = this.instantiationService.createInstance(NotebookVariablesTree, 'notebookVariablesView', container,
55+
new NotebookVariablesDelegate(),
56+
[new NotebookVariableRenderer()],
57+
new NotebookVariablesDataSource(),
58+
{ accessibilityProvider: new NotebookVariableAccessibilityProvider() });
59+
60+
this.tree.setInput(new MockVariables());
61+
}
62+
5263
private handleActiveEditorChange() {
5364
const activeEditorPane = this.editorService.activeEditorPane;
5465
if (activeEditorPane && activeEditorPane.getId() === 'workbench.editor.notebook') {
@@ -60,21 +71,3 @@ export class NotebookVariablesView extends ViewPane {
6071
}
6172
}
6273
}
63-
64-
export class VariablesPanelDescriptor implements IViewDescriptor {
65-
readonly id = NotebookVariablesView.ID;
66-
readonly name: ILocalizedString = NotebookVariablesView.TITLE;
67-
readonly ctorDescriptor: SyncDescriptor<NotebookVariablesView>;
68-
readonly canToggleVisibility = true;
69-
readonly hideByDefault = false;
70-
readonly order = 500;
71-
readonly remoteAuthority?: string | string[];
72-
readonly canMoveView = true;
73-
readonly containerIcon = variablesViewIcon;
74-
75-
constructor() {
76-
this.ctorDescriptor = new SyncDescriptor(NotebookVariablesView);
77-
}
78-
}
79-
80-

src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/variablesView.ts

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ import { runAccessibilityHelpAction, showAccessibleOutput } from 'vs/workbench/c
119119
import { IAccessibleViewService } from 'vs/workbench/contrib/accessibility/browser/accessibleView';
120120
import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey';
121121
import { AccessibilityHelpAction, AccessibleViewAction } from 'vs/workbench/contrib/accessibility/browser/accessibleViewActions';
122-
import { NotebookVariables } from 'vs/workbench/contrib/notebook/browser/contrib/notebookVariables/variablesView';
122+
import { NotebookVariables } from 'vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariables';
123123

124124
/*--------------------------------------------------------------------------------------------- */
125125

0 commit comments

Comments
 (0)