From 8bf04271f7101185545718133abbea153c95c7ca Mon Sep 17 00:00:00 2001 From: Aaron Munger Date: Fri, 4 Oct 2024 09:41:51 -0700 Subject: [PATCH] add goto variables button (#230446) * add goto variables button * more appropriate icon --- .../notebookVariables/notebookVariables.ts | 11 +-- .../browser/controller/variablesActions.ts | 69 +++++++++++++++++++ .../notebook/browser/notebook.contribution.ts | 1 + .../contrib/notebook/browser/notebookIcons.ts | 2 +- .../notebookEditorWidgetContextKeys.ts | 7 +- .../notebook/common/notebookContextKeys.ts | 1 + .../replNotebook/browser/replEditor.ts | 2 - 7 files changed, 84 insertions(+), 9 deletions(-) create mode 100644 src/vs/workbench/contrib/notebook/browser/controller/variablesActions.ts diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariables.ts b/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariables.ts index 004dad8ea515e..d1816c4d2a51d 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariables.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariables.ts @@ -11,7 +11,7 @@ import { IContextKey, IContextKeyService } from '../../../../../../platform/cont import { SyncDescriptor } from '../../../../../../platform/instantiation/common/descriptors.js'; import { Registry } from '../../../../../../platform/registry/common/platform.js'; import { IWorkbenchContribution } from '../../../../../common/contributions.js'; -import { Extensions, IViewContainersRegistry, IViewsRegistry } from '../../../../../common/views.js'; +import { Extensions, IViewDescriptorService, IViewsRegistry } from '../../../../../common/views.js'; import { VIEWLET_ID as debugContainerId } from '../../../../debug/common/debug.js'; import { NOTEBOOK_VARIABLE_VIEW_ENABLED } from './notebookVariableContextKeys.js'; import { NotebookVariablesView } from './notebookVariablesView.js'; @@ -36,7 +36,8 @@ export class NotebookVariables extends Disposable implements IWorkbenchContribut @IEditorService private readonly editorService: IEditorService, @INotebookExecutionStateService private readonly notebookExecutionStateService: INotebookExecutionStateService, @INotebookKernelService private readonly notebookKernelService: INotebookKernelService, - @INotebookService private readonly notebookDocumentService: INotebookService + @INotebookService private readonly notebookDocumentService: INotebookService, + @IViewDescriptorService private readonly viewDescriptorService: IViewDescriptorService ) { super(); @@ -73,14 +74,14 @@ export class NotebookVariables extends Disposable implements IWorkbenchContribut } private initializeView() { - const debugViewContainer = Registry.as('workbench.registry.view.containers').get(debugContainerId); + const debugViewContainer = this.viewDescriptorService.getViewContainerById(debugContainerId); if (debugViewContainer) { const viewsRegistry = Registry.as(Extensions.ViewsRegistry); const viewDescriptor = { - id: 'NOTEBOOK_VARIABLES', name: nls.localize2('notebookVariables', "Notebook Variables"), + id: 'workbench.notebook.variables', name: nls.localize2('notebookVariables', "Notebook Variables"), containerIcon: variablesViewIcon, ctorDescriptor: new SyncDescriptor(NotebookVariablesView), - order: 50, weight: 5, canToggleVisibility: true, canMoveView: true, collapsed: false, when: NOTEBOOK_VARIABLE_VIEW_ENABLED, + order: 50, weight: 5, canToggleVisibility: true, canMoveView: true, collapsed: false, when: NOTEBOOK_VARIABLE_VIEW_ENABLED }; viewsRegistry.registerViews([viewDescriptor], debugViewContainer); diff --git a/src/vs/workbench/contrib/notebook/browser/controller/variablesActions.ts b/src/vs/workbench/contrib/notebook/browser/controller/variablesActions.ts new file mode 100644 index 0000000000000..2a8b7811a3e1d --- /dev/null +++ b/src/vs/workbench/contrib/notebook/browser/controller/variablesActions.ts @@ -0,0 +1,69 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import { localize2 } from '../../../../../nls.js'; +import { MenuId, registerAction2 } from '../../../../../platform/actions/common/actions.js'; +import { ContextKeyExpr } from '../../../../../platform/contextkey/common/contextkey.js'; +import { ServicesAccessor } from '../../../../../platform/instantiation/common/instantiation.js'; +import { IViewsService } from '../../../../services/views/common/viewsService.js'; +import { KERNEL_HAS_VARIABLE_PROVIDER } from '../../common/notebookContextKeys.js'; +import { NOTEBOOK_VARIABLE_VIEW_ENABLED } from '../contrib/notebookVariables/notebookVariableContextKeys.js'; +import * as icons from '../notebookIcons.js'; + +import { INotebookActionContext, NotebookAction } from './coreActions.js'; + +const OPEN_VARIABLES_VIEW_COMMAND_ID = 'notebook.openVariablesView'; + +registerAction2(class OpenVariablesViewAction extends NotebookAction { + + constructor() { + super({ + id: OPEN_VARIABLES_VIEW_COMMAND_ID, + title: localize2('notebookActions.openVariablesView', "Variables"), + icon: icons.variablesViewIcon, + menu: [ + { + id: MenuId.InteractiveToolbar, + group: 'navigation', + when: ContextKeyExpr.and( + KERNEL_HAS_VARIABLE_PROVIDER, + // jupyter extension currently contributes their own goto variables button + ContextKeyExpr.notEquals('jupyter.kernel.isjupyter', true), + NOTEBOOK_VARIABLE_VIEW_ENABLED + ) + }, + { + id: MenuId.EditorTitle, + order: -1, + group: 'navigation', + when: ContextKeyExpr.and( + KERNEL_HAS_VARIABLE_PROVIDER, + // jupyter extension currently contributes their own goto variables button + ContextKeyExpr.notEquals('jupyter.kernel.isjupyter', true), + ContextKeyExpr.notEquals('config.notebook.globalToolbar', true), + NOTEBOOK_VARIABLE_VIEW_ENABLED + ) + }, + { + id: MenuId.NotebookToolbar, + order: -1, + group: 'navigation', + when: ContextKeyExpr.and( + KERNEL_HAS_VARIABLE_PROVIDER, + // jupyter extension currently contributes their own goto variables button + ContextKeyExpr.notEquals('jupyter.kernel.isjupyter', true), + ContextKeyExpr.equals('config.notebook.globalToolbar', true), + NOTEBOOK_VARIABLE_VIEW_ENABLED + ) + } + ] + }); + } + + override async runWithContext(accessor: ServicesAccessor, context: INotebookActionContext) { + const variableViewId = 'workbench.notebook.variables'; + accessor.get(IViewsService).openView(variableViewId, true); + } +}); diff --git a/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts b/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts index c35c62624f7ec..857c3a95aa0d5 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts @@ -70,6 +70,7 @@ import './controller/cellOutputActions.js'; import './controller/apiActions.js'; import './controller/foldingController.js'; import './controller/chat/notebook.chat.contribution.js'; +import './controller/variablesActions.js'; // Editor Contribution import './contrib/editorHint/emptyCellEditorHint.js'; diff --git a/src/vs/workbench/contrib/notebook/browser/notebookIcons.ts b/src/vs/workbench/contrib/notebook/browser/notebookIcons.ts index 312d0653f4bbb..d454bfda04aa3 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookIcons.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookIcons.ts @@ -37,4 +37,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.')); +export const variablesViewIcon = registerIcon('variables-view-icon', Codicon.variableGroup, localize('variablesViewIcon', 'View icon of the variables view.')); diff --git a/src/vs/workbench/contrib/notebook/browser/viewParts/notebookEditorWidgetContextKeys.ts b/src/vs/workbench/contrib/notebook/browser/viewParts/notebookEditorWidgetContextKeys.ts index e6f42671e8a6e..d2467be2d7eba 100644 --- a/src/vs/workbench/contrib/notebook/browser/viewParts/notebookEditorWidgetContextKeys.ts +++ b/src/vs/workbench/contrib/notebook/browser/viewParts/notebookEditorWidgetContextKeys.ts @@ -7,7 +7,7 @@ import * as DOM from '../../../../../base/browser/dom.js'; import { DisposableStore, dispose, IDisposable } from '../../../../../base/common/lifecycle.js'; import { IContextKey, IContextKeyService } from '../../../../../platform/contextkey/common/contextkey.js'; import { ICellViewModel, INotebookEditorDelegate, KERNEL_EXTENSIONS } from '../notebookBrowser.js'; -import { NOTEBOOK_CELL_TOOLBAR_LOCATION, NOTEBOOK_HAS_OUTPUTS, NOTEBOOK_HAS_RUNNING_CELL, NOTEBOOK_HAS_SOMETHING_RUNNING, NOTEBOOK_INTERRUPTIBLE_KERNEL, NOTEBOOK_KERNEL, NOTEBOOK_KERNEL_COUNT, NOTEBOOK_KERNEL_SELECTED, NOTEBOOK_KERNEL_SOURCE_COUNT, NOTEBOOK_LAST_CELL_FAILED, NOTEBOOK_MISSING_KERNEL_EXTENSION, NOTEBOOK_USE_CONSOLIDATED_OUTPUT_BUTTON, NOTEBOOK_VIEW_TYPE } from '../../common/notebookContextKeys.js'; +import { KERNEL_HAS_VARIABLE_PROVIDER, NOTEBOOK_CELL_TOOLBAR_LOCATION, NOTEBOOK_HAS_OUTPUTS, NOTEBOOK_HAS_RUNNING_CELL, NOTEBOOK_HAS_SOMETHING_RUNNING, NOTEBOOK_INTERRUPTIBLE_KERNEL, NOTEBOOK_KERNEL, NOTEBOOK_KERNEL_COUNT, NOTEBOOK_KERNEL_SELECTED, NOTEBOOK_KERNEL_SOURCE_COUNT, NOTEBOOK_LAST_CELL_FAILED, NOTEBOOK_MISSING_KERNEL_EXTENSION, NOTEBOOK_USE_CONSOLIDATED_OUTPUT_BUTTON, NOTEBOOK_VIEW_TYPE } from '../../common/notebookContextKeys.js'; import { ICellExecutionStateChangedEvent, IExecutionStateChangedEvent, INotebookExecutionStateService, INotebookFailStateChangedEvent, NotebookExecutionType } from '../../common/notebookExecutionStateService.js'; import { INotebookKernelService } from '../../common/notebookKernelService.js'; import { IExtensionService } from '../../../../services/extensions/common/extensions.js'; @@ -19,6 +19,7 @@ export class NotebookEditorContextKeys { private readonly _notebookKernelSourceCount: IContextKey; private readonly _notebookKernelSelected: IContextKey; private readonly _interruptibleKernel: IContextKey; + private readonly _hasVariableProvider: IContextKey; private readonly _someCellRunning: IContextKey; private readonly _kernelRunning: IContextKey; private readonly _hasOutputs: IContextKey; @@ -44,6 +45,7 @@ export class NotebookEditorContextKeys { this._notebookKernelCount = NOTEBOOK_KERNEL_COUNT.bindTo(contextKeyService); this._notebookKernelSelected = NOTEBOOK_KERNEL_SELECTED.bindTo(contextKeyService); this._interruptibleKernel = NOTEBOOK_INTERRUPTIBLE_KERNEL.bindTo(contextKeyService); + this._hasVariableProvider = KERNEL_HAS_VARIABLE_PROVIDER.bindTo(contextKeyService); this._someCellRunning = NOTEBOOK_HAS_RUNNING_CELL.bindTo(contextKeyService); this._kernelRunning = NOTEBOOK_HAS_SOMETHING_RUNNING.bindTo(contextKeyService); this._useConsolidatedOutputButton = NOTEBOOK_USE_CONSOLIDATED_OUTPUT_BUTTON.bindTo(contextKeyService); @@ -73,6 +75,7 @@ export class NotebookEditorContextKeys { this._notebookKernelCount.reset(); this._notebookKernelSourceCount.reset(); this._interruptibleKernel.reset(); + this._hasVariableProvider.reset(); this._someCellRunning.reset(); this._kernelRunning.reset(); this._viewType.reset(); @@ -174,6 +177,7 @@ export class NotebookEditorContextKeys { this._notebookKernelCount.reset(); this._notebookKernelSourceCount.reset(); this._interruptibleKernel.reset(); + this._hasVariableProvider.reset(); return; } @@ -182,6 +186,7 @@ export class NotebookEditorContextKeys { this._notebookKernelCount.set(all.length); this._notebookKernelSourceCount.set(sourceActions.length); this._interruptibleKernel.set(selected?.implementsInterrupt ?? false); + this._hasVariableProvider.set(selected?.hasVariableProvider ?? false); this._notebookKernelSelected.set(Boolean(selected)); this._notebookKernel.set(selected?.id ?? ''); diff --git a/src/vs/workbench/contrib/notebook/common/notebookContextKeys.ts b/src/vs/workbench/contrib/notebook/common/notebookContextKeys.ts index ad68c6dd08709..733ce1efa254e 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookContextKeys.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookContextKeys.ts @@ -64,5 +64,6 @@ export const NOTEBOOK_KERNEL_SELECTED = new RawContextKey('notebookKern export const NOTEBOOK_INTERRUPTIBLE_KERNEL = new RawContextKey('notebookInterruptibleKernel', false); export const NOTEBOOK_MISSING_KERNEL_EXTENSION = new RawContextKey('notebookMissingKernelExtension', false); export const NOTEBOOK_HAS_OUTPUTS = new RawContextKey('notebookHasOutputs', false); +export const KERNEL_HAS_VARIABLE_PROVIDER = new RawContextKey('kernelHasVariableProvider', false); //#endregion diff --git a/src/vs/workbench/contrib/replNotebook/browser/replEditor.ts b/src/vs/workbench/contrib/replNotebook/browser/replEditor.ts index 3575074c3eb1a..10420ffdbcf53 100644 --- a/src/vs/workbench/contrib/replNotebook/browser/replEditor.ts +++ b/src/vs/workbench/contrib/replNotebook/browser/replEditor.ts @@ -8,7 +8,6 @@ import * as DOM from '../../../../base/browser/dom.js'; import { CancellationToken } from '../../../../base/common/cancellation.js'; import { Emitter, Event } from '../../../../base/common/event.js'; import { DisposableStore, MutableDisposable } from '../../../../base/common/lifecycle.js'; -import { ICodeEditorService } from '../../../../editor/browser/services/codeEditorService.js'; import { CodeEditorWidget } from '../../../../editor/browser/widget/codeEditor/codeEditorWidget.js'; import { ICodeEditorViewState, ICompositeCodeEditor } from '../../../../editor/common/editorCommon.js'; import { IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js'; @@ -121,7 +120,6 @@ export class ReplEditor extends EditorPane implements IEditorPaneWithScrolling { @IInstantiationService instantiationService: IInstantiationService, @INotebookEditorService notebookWidgetService: INotebookEditorService, @IContextKeyService contextKeyService: IContextKeyService, - @ICodeEditorService codeEditorService: ICodeEditorService, @INotebookKernelService notebookKernelService: INotebookKernelService, @ILanguageService languageService: ILanguageService, @IKeybindingService keybindingService: IKeybindingService,