Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add goto variables button #230446

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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();

Expand Down Expand Up @@ -73,14 +74,14 @@ export class NotebookVariables extends Disposable implements IWorkbenchContribut
}

private initializeView() {
const debugViewContainer = Registry.as<IViewContainersRegistry>('workbench.registry.view.containers').get(debugContainerId);
const debugViewContainer = this.viewDescriptorService.getViewContainerById(debugContainerId);

if (debugViewContainer) {
const viewsRegistry = Registry.as<IViewsRegistry>(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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/notebook/browser/notebookIcons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.'));
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -19,6 +19,7 @@ export class NotebookEditorContextKeys {
private readonly _notebookKernelSourceCount: IContextKey<number>;
private readonly _notebookKernelSelected: IContextKey<boolean>;
private readonly _interruptibleKernel: IContextKey<boolean>;
private readonly _hasVariableProvider: IContextKey<boolean>;
private readonly _someCellRunning: IContextKey<boolean>;
private readonly _kernelRunning: IContextKey<boolean>;
private readonly _hasOutputs: IContextKey<boolean>;
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -174,6 +177,7 @@ export class NotebookEditorContextKeys {
this._notebookKernelCount.reset();
this._notebookKernelSourceCount.reset();
this._interruptibleKernel.reset();
this._hasVariableProvider.reset();
return;
}

Expand All @@ -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 ?? '');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,6 @@ export const NOTEBOOK_KERNEL_SELECTED = new RawContextKey<boolean>('notebookKern
export const NOTEBOOK_INTERRUPTIBLE_KERNEL = new RawContextKey<boolean>('notebookInterruptibleKernel', false);
export const NOTEBOOK_MISSING_KERNEL_EXTENSION = new RawContextKey<boolean>('notebookMissingKernelExtension', false);
export const NOTEBOOK_HAS_OUTPUTS = new RawContextKey<boolean>('notebookHasOutputs', false);
export const KERNEL_HAS_VARIABLE_PROVIDER = new RawContextKey<boolean>('kernelHasVariableProvider', false);

//#endregion
2 changes: 0 additions & 2 deletions src/vs/workbench/contrib/replNotebook/browser/replEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
Loading