From 9b313c37f878ae1574e7e9866b8a1d18ae0bf75a Mon Sep 17 00:00:00 2001 From: aamunger Date: Thu, 9 Nov 2023 09:19:54 -0800 Subject: [PATCH] move view into debug container --- .../debug/browser/debug.contribution.ts | 3 ++ .../contrib/kernelVariables/variablesView.ts | 54 ------------------- .../notebookVariablesView.ts} | 40 +++++++++----- .../notebookVariables/variablesView.ts | 42 +++++++++++++++ .../notebook/browser/notebook.contribution.ts | 3 ++ .../contrib/notebook/browser/notebookIcons.ts | 1 + 6 files changed, 77 insertions(+), 66 deletions(-) delete mode 100644 src/vs/workbench/contrib/notebook/browser/contrib/kernelVariables/variablesView.ts rename src/vs/workbench/contrib/notebook/browser/contrib/{kernelVariables/variablesPanel.ts => notebookVariables/notebookVariablesView.ts} (62%) create mode 100644 src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/variablesView.ts diff --git a/src/vs/workbench/contrib/debug/browser/debug.contribution.ts b/src/vs/workbench/contrib/debug/browser/debug.contribution.ts index 4ff1a98bd7317..e956a5de039f7 100644 --- a/src/vs/workbench/contrib/debug/browser/debug.contribution.ts +++ b/src/vs/workbench/contrib/debug/browser/debug.contribution.ts @@ -52,6 +52,8 @@ import { BREAKPOINTS_VIEW_ID, BREAKPOINT_EDITOR_CONTRIBUTION_ID, CALLSTACK_VIEW_ import { DebugContentProvider } from 'vs/workbench/contrib/debug/common/debugContentProvider'; import { DebugLifecycle } from 'vs/workbench/contrib/debug/common/debugLifecycle'; import { DisassemblyViewInput } from 'vs/workbench/contrib/debug/common/disassemblyViewInput'; +import { NotebookVariablesView } from 'vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesView'; +import { NOTEBOOK_KERNEL } from 'vs/workbench/contrib/notebook/common/notebookContextKeys'; import { launchSchemaId } from 'vs/workbench/services/configuration/common/configuration'; import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle'; @@ -413,6 +415,7 @@ viewsRegistry.registerViews([{ id: CALLSTACK_VIEW_ID, name: nls.localize2('callS 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); 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); 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); +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); // Register disassembly view diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/kernelVariables/variablesView.ts b/src/vs/workbench/contrib/notebook/browser/contrib/kernelVariables/variablesView.ts deleted file mode 100644 index 806eb39ec3bf5..0000000000000 --- a/src/vs/workbench/contrib/notebook/browser/contrib/kernelVariables/variablesView.ts +++ /dev/null @@ -1,54 +0,0 @@ -/*--------------------------------------------------------------------------------------------- - * Copyright (c) Microsoft Corporation. All rights reserved. - * Licensed under the MIT License. See License.txt in the project root for license information. - *--------------------------------------------------------------------------------------------*/ - -import * as nls from 'vs/nls'; -import { Disposable } from 'vs/base/common/lifecycle'; -import { IWorkbenchContribution } from 'vs/workbench/common/contributions'; -import { Registry } from 'vs/platform/registry/common/platform'; -import { Extensions, IViewContainersRegistry, IViewsRegistry, ViewContainerLocation } from 'vs/workbench/common/views'; -import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; -import { VariablesPanelDescriptor } from 'vs/workbench/contrib/notebook/browser/contrib/kernelVariables/variablesPanel'; -import { ViewPaneContainer } from 'vs/workbench/browser/parts/views/viewPaneContainer'; - -const VARIABLES_VIEW_CONTAINER_ID = 'variablesViewContainer'; - -export class VariablesView extends Disposable implements IWorkbenchContribution { - - constructor() { - super(); - this.enableVariablesView(); - } - - private async enableVariablesView() { - const viewEnabled = true; - - if (viewEnabled) { - const viewContainer = await this.getViewContainer(); - const variablesPanelDescriptor = new VariablesPanelDescriptor(); - const viewsRegistry = Registry.as(Extensions.ViewsRegistry); - if (viewContainer) { - viewsRegistry.registerViews([variablesPanelDescriptor!], viewContainer); - } - } else { - // this.contextKeyListener = this.contextKeyService.onDidChangeContext(e => { - // if (e.affectsSome()) { - // this.enableVariablesView(); - // } - // }); - } - } - - getViewContainer() { - return Registry.as(Extensions.ViewContainersRegistry).registerViewContainer({ - id: VARIABLES_VIEW_CONTAINER_ID, - title: { value: nls.localize('variables', "Kernel Variables"), original: 'Kernel Variables' }, - ctorDescriptor: new SyncDescriptor(ViewPaneContainer, [VARIABLES_VIEW_CONTAINER_ID, { mergeViewWithContainerWhenSingleView: true }]), - storageId: VARIABLES_VIEW_CONTAINER_ID, - hideIfEmpty: true, - order: 5 - }, ViewContainerLocation.Panel); - } - -} diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/kernelVariables/variablesPanel.ts b/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesView.ts similarity index 62% rename from src/vs/workbench/contrib/notebook/browser/contrib/kernelVariables/variablesPanel.ts rename to src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesView.ts index a0b77ed5d67e8..ef977aa48b3f4 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/kernelVariables/variablesPanel.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesView.ts @@ -18,15 +18,20 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { IThemeService } from 'vs/platform/theme/common/themeService'; import { IViewPaneOptions, ViewPane } from 'vs/workbench/browser/parts/views/viewPane'; import { IViewDescriptor, IViewDescriptorService } from 'vs/workbench/common/views'; +import { getNotebookEditorFromEditorPane } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; +import { variablesViewIcon } from 'vs/workbench/contrib/notebook/browser/notebookIcons'; +import { INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService'; +import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; +export class NotebookVariablesView extends ViewPane { -export class VariablesPanel extends ViewPane { - - static readonly ID = 'variablesView'; - static readonly TITLE: ILocalizedString = nls.localize2('remote.tunnel', "Ports"); + static readonly ID = 'notebookVariablesView'; + static readonly TITLE: ILocalizedString = nls.localize2('notebook.notebookVariables', "Notebook Variables"); constructor( options: IViewPaneOptions, + @IEditorService private readonly editorService: IEditorService, + @INotebookKernelService private readonly notebookKernelService: INotebookKernelService, @IKeybindingService keybindingService: IKeybindingService, @IContextMenuService contextMenuService: IContextMenuService, @IContextKeyService contextKeyService: IContextKeyService, @@ -41,24 +46,35 @@ export class VariablesPanel extends ViewPane { ) { super(options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService); + this._register(this.editorService.onDidActiveEditorChange(this.handleActiveEditorChange)); + } + private handleActiveEditorChange() { + const activeEditorPane = this.editorService.activeEditorPane; + if (activeEditorPane && activeEditorPane.getId() === 'workbench.editor.notebook') { + const notebookModel = getNotebookEditorFromEditorPane(activeEditorPane)?.textModel; + if (notebookModel) { + const selectedKernel = this.notebookKernelService.getMatchingKernel(notebookModel).selected; + console.log(selectedKernel?.id); + } + } } } export class VariablesPanelDescriptor implements IViewDescriptor { - readonly id = VariablesPanel.ID; - readonly name: ILocalizedString = VariablesPanel.TITLE; - readonly ctorDescriptor: SyncDescriptor; + readonly id = NotebookVariablesView.ID; + readonly name: ILocalizedString = NotebookVariablesView.TITLE; + readonly ctorDescriptor: SyncDescriptor; readonly canToggleVisibility = true; readonly hideByDefault = false; - // group is not actually used for views that are not extension contributed. Use order instead. - readonly group = 'details@0'; - // -500 comes from the remote explorer viewOrderDelegate - readonly order = -500; + readonly order = 500; readonly remoteAuthority?: string | string[]; readonly canMoveView = true; + readonly containerIcon = variablesViewIcon; constructor() { - this.ctorDescriptor = new SyncDescriptor(VariablesPanel); + this.ctorDescriptor = new SyncDescriptor(NotebookVariablesView); } } + + diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/variablesView.ts b/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/variablesView.ts new file mode 100644 index 0000000000000..aee3e1e6f4c99 --- /dev/null +++ b/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/variablesView.ts @@ -0,0 +1,42 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { Disposable } from 'vs/base/common/lifecycle'; +import { IWorkbenchContribution } from 'vs/workbench/common/contributions'; +import { Registry } from 'vs/platform/registry/common/platform'; +import { IViewContainersRegistry } from 'vs/workbench/common/views'; +import { VIEWLET_ID as debugContainerId } from 'vs/workbench/contrib/debug/common/debug'; + + +export class NotebookVariables extends Disposable implements IWorkbenchContribution { + + constructor() { + super(); + this.enableVariablesView(); + } + + private async enableVariablesView() { + const viewEnabled = true; + + if (viewEnabled) { + const debugViewContainer = Registry.as('workbench.registry.view.containers').get(debugContainerId); + + if (debugViewContainer) { + // const variablesPanelDescriptor = new VariablesPanelDescriptor(); + // const viewsRegistry = Registry.as(Extensions.ViewsRegistry); + + // viewsRegistry.registerViews([variablesPanelDescriptor], debugViewContainer); + } + + } else { + // this.contextKeyListener = this.contextKeyService.onDidChangeContext(e => { + // if (e.affectsSome()) { + // this.enableVariablesView(); + // } + // }); + } + } + +} diff --git a/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts b/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts index 9689de4040b65..fc47fa84be9f7 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts @@ -119,6 +119,8 @@ import { runAccessibilityHelpAction, showAccessibleOutput } from 'vs/workbench/c import { IAccessibleViewService } from 'vs/workbench/contrib/accessibility/browser/accessibleView'; import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { AccessibilityHelpAction, AccessibleViewAction } from 'vs/workbench/contrib/accessibility/browser/accessibleViewActions'; +import { NotebookVariables } from 'vs/workbench/contrib/notebook/browser/contrib/notebookVariables/variablesView'; + /*--------------------------------------------------------------------------------------------- */ Registry.as(EditorExtensions.EditorPane).registerEditorPane( @@ -718,6 +720,7 @@ workbenchContributionsRegistry.registerWorkbenchContribution(NotebookLanguageSel workbenchContributionsRegistry.registerWorkbenchContribution(SimpleNotebookWorkingCopyEditorHandler, LifecyclePhase.Ready); workbenchContributionsRegistry.registerWorkbenchContribution(NotebookAccessibilityHelpContribution, LifecyclePhase.Eventually); workbenchContributionsRegistry.registerWorkbenchContribution(NotebookAccessibleViewContribution, LifecyclePhase.Eventually); +workbenchContributionsRegistry.registerWorkbenchContribution(NotebookVariables, LifecyclePhase.Eventually); registerSingleton(INotebookService, NotebookService, InstantiationType.Delayed); registerSingleton(INotebookEditorWorkerService, NotebookEditorWorkerServiceImpl, InstantiationType.Delayed); diff --git a/src/vs/workbench/contrib/notebook/browser/notebookIcons.ts b/src/vs/workbench/contrib/notebook/browser/notebookIcons.ts index 69c932935ebd8..20ffe3867e833 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookIcons.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookIcons.ts @@ -36,3 +36,4 @@ export const copyIcon = registerIcon('notebook-copy', Codicon.copy, localize('co export const previousChangeIcon = registerIcon('notebook-diff-editor-previous-change', Codicon.arrowUp, localize('previousChangeIcon', 'Icon for the previous change action in the diff editor.')); export const nextChangeIcon = registerIcon('notebook-diff-editor-next-change', Codicon.arrowDown, localize('nextChangeIcon', 'Icon for the next change action in the diff editor.')); +export const variablesViewIcon = registerIcon('variables-view-icon', Codicon.debugAlt, localize('variablesViewIcon', 'View icon of the variables view.'));