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

don't put REPL variable view behind a notebook setting #230349

Merged
merged 2 commits into from
Oct 3, 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 @@ -50,20 +50,13 @@ export class NotebookVariables extends Disposable implements IWorkbenchContribut

private handleConfigChange(e: IConfigurationChangeEvent) {
if (e.affectsConfiguration(NotebookSetting.notebookVariablesView)) {
if (!this.configurationService.getValue(NotebookSetting.notebookVariablesView)) {
this.viewEnabled.set(false);
} else if (this.initialized) {
this.viewEnabled.set(true);
} else {
this.handleInitEvent();
}
this.handleInitEvent();
}
}

private handleInitEvent(notebook?: URI) {
if (this.configurationService.getValue(NotebookSetting.notebookVariablesView)
&& (!!notebook || this.editorService.activeEditorPane?.getId() === 'workbench.editor.notebook')) {

const enabled = this.editorService.activeEditorPane?.getId() === 'workbench.editor.repl' || this.configurationService.getValue(NotebookSetting.notebookVariablesView);
if (enabled && (!!notebook || this.editorService.activeEditorPane?.getId() === 'workbench.editor.notebook')) {
if (this.hasVariableProvider(notebook) && !this.initialized && this.initializeView()) {
this.viewEnabled.set(true);
this.initialized = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import { localize } from '../../../../../../nls.js';
import { NotebookTextModel } from '../../../common/model/notebookTextModel.js';
import { INotebookKernel, INotebookKernelService, VariablesResult, variablePageSize } from '../../../common/notebookKernelService.js';

export interface IEmptyScope {
kind: 'empty';
}

export interface INotebookScope {
kind: 'root';
readonly notebook: NotebookTextModel;
Expand Down Expand Up @@ -49,8 +53,10 @@ export class NotebookVariableDataSource implements IAsyncDataSource<INotebookSco
this.cancellationTokenSource = new CancellationTokenSource();
}

async getChildren(element: INotebookScope | INotebookVariableElement): Promise<Array<INotebookVariableElement>> {
if (element.kind === 'root') {
async getChildren(element: INotebookScope | INotebookVariableElement | IEmptyScope): Promise<Array<INotebookVariableElement>> {
if (element.kind === 'empty') {
return [];
} else if (element.kind === 'root') {
return this.getRootVariables(element.notebook);
} else {
return this.getVariables(element);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ import { IThemeService } from '../../../../../../platform/theme/common/themeServ
import { IViewPaneOptions, ViewPane } from '../../../../../browser/parts/views/viewPane.js';
import { IViewDescriptorService } from '../../../../../common/views.js';
import { CONTEXT_VARIABLE_EXTENSIONID, CONTEXT_VARIABLE_INTERFACES, CONTEXT_VARIABLE_LANGUAGE, CONTEXT_VARIABLE_NAME, CONTEXT_VARIABLE_TYPE, CONTEXT_VARIABLE_VALUE } from '../../../../debug/common/debug.js';
import { INotebookScope, INotebookVariableElement, NotebookVariableDataSource } from './notebookVariablesDataSource.js';
import { IEmptyScope, INotebookScope, INotebookVariableElement, NotebookVariableDataSource } from './notebookVariablesDataSource.js';
import { NotebookVariableAccessibilityProvider, NotebookVariableRenderer, NotebookVariablesDelegate } from './notebookVariablesTree.js';
import { getNotebookEditorFromEditorPane } from '../../notebookBrowser.js';
import { NotebookTextModel } from '../../../common/model/notebookTextModel.js';
import { ICellExecutionStateChangedEvent, IExecutionStateChangedEvent, INotebookExecutionStateService } from '../../../common/notebookExecutionStateService.js';
import { INotebookKernelService } from '../../../common/notebookKernelService.js';
import { IEditorService } from '../../../../../services/editor/common/editorService.js';
import { IEditorPane } from '../../../../../common/editor.js';
import { IEditorCloseEvent, IEditorPane } from '../../../../../common/editor.js';
import { isCompositeNotebookEditorInput } from '../../../common/notebookEditorInput.js';

export type contextMenuArg = { source: string; name: string; type?: string; value?: string; expression?: string; language?: string; extensionId?: string };
Expand All @@ -44,7 +44,7 @@ export class NotebookVariablesView extends ViewPane {
static readonly NOTEBOOK_TITLE: ILocalizedString = nls.localize2('notebook.notebookVariables', "Notebook Variables");
static readonly REPL_TITLE: ILocalizedString = nls.localize2('notebook.ReplVariables', "REPL Variables");

private tree: WorkbenchAsyncDataTree<INotebookScope, INotebookVariableElement> | undefined;
private tree: WorkbenchAsyncDataTree<INotebookScope | IEmptyScope, INotebookVariableElement> | undefined;
private activeNotebook: NotebookTextModel | undefined;
private readonly dataSource: NotebookVariableDataSource;

Expand All @@ -71,11 +71,12 @@ export class NotebookVariablesView extends ViewPane {
) {
super(options, keybindingService, contextMenuService, configurationService, contextKeyService, viewDescriptorService, instantiationService, openerService, themeService, telemetryService, hoverService);

this._register(this.editorService.onDidActiveEditorChange(this.handleActiveEditorChange.bind(this)));
this._register(this.editorService.onDidActiveEditorChange(() => this.handleActiveEditorChange()));
this._register(this.notebookKernelService.onDidNotebookVariablesUpdate(this.handleVariablesChanged.bind(this)));
this._register(this.notebookExecutionStateService.onDidChangeExecution(this.handleExecutionStateChange.bind(this)));
this._register(this.editorService.onDidCloseEditor((e) => this.handleCloseEditor(e)));

this.activeNotebook = this.getActiveNotebook()?.notebookDocument;
this.handleActiveEditorChange(false);

this.dataSource = new NotebookVariableDataSource(this.notebookKernelService);
this.updateScheduler = new RunOnceScheduler(() => this.tree?.updateChildren(), 100);
Expand All @@ -85,7 +86,7 @@ export class NotebookVariablesView extends ViewPane {
super.renderBody(container);
this.element.classList.add('debug-pane');

this.tree = <WorkbenchAsyncDataTree<INotebookScope, INotebookVariableElement>>this.instantiationService.createInstance(
this.tree = <WorkbenchAsyncDataTree<INotebookScope | IEmptyScope, INotebookVariableElement>>this.instantiationService.createInstance(
WorkbenchAsyncDataTree,
'notebookVariablesTree',
container,
Expand Down Expand Up @@ -143,15 +144,19 @@ export class NotebookVariablesView extends ViewPane {
this.tree?.layout(height, width);
}

private setActiveNotebook(notebookDocument: NotebookTextModel, editor: IEditorPane) {
private setActiveNotebook(notebookDocument: NotebookTextModel, editor: IEditorPane, doUpdate = true) {
this.activeNotebook = notebookDocument;
this.tree?.setInput({ kind: 'root', notebook: notebookDocument });
this.updateScheduler.schedule();

if (isCompositeNotebookEditorInput(editor.input)) {
this.updateTitle(NotebookVariablesView.REPL_TITLE.value);
} else {
this.updateTitle(NotebookVariablesView.NOTEBOOK_TITLE.value);
}

if (doUpdate) {
this.tree?.setInput({ kind: 'root', notebook: notebookDocument });
this.updateScheduler.schedule();
}
}

private getActiveNotebook() {
Expand All @@ -160,10 +165,17 @@ export class NotebookVariablesView extends ViewPane {
return notebookDocument && notebookEditor ? { notebookDocument, notebookEditor } : undefined;
}

private handleActiveEditorChange() {
private handleCloseEditor(e: IEditorCloseEvent) {
if (e.editor.resource && e.editor.resource.toString() === this.activeNotebook?.uri.toString()) {
this.tree?.setInput({ kind: 'empty' });
this.updateScheduler.schedule();
}
}

private handleActiveEditorChange(doUpdate = true) {
const found = this.getActiveNotebook();
if (found && found.notebookDocument !== this.activeNotebook) {
this.setActiveNotebook(found.notebookDocument, found.notebookEditor);
this.setActiveNotebook(found.notebookDocument, found.notebookEditor, doUpdate);
}
}

Expand Down
Loading