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

enable variable view for IW #205249

Merged
merged 1 commit into from
Feb 15, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as nls from 'vs/nls';
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { URI } from 'vs/base/common/uri';
import * as nls from 'vs/nls';
import { IConfigurationChangeEvent, IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { Registry } from 'vs/platform/registry/common/platform';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { Extensions, IViewContainersRegistry, IViewsRegistry } from 'vs/workbench/common/views';
import { VIEWLET_ID as debugContainerId } from 'vs/workbench/contrib/debug/common/debug';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
import { NOTEBOOK_VARIABLE_VIEW_ENABLED } from 'vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariableContextKeys';
import { NotebookVariablesView } from 'vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesView';
import { getNotebookEditorFromEditorPane } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { variablesViewIcon } from 'vs/workbench/contrib/notebook/browser/notebookIcons';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IConfigurationChangeEvent, IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService';
import { NotebookSetting } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { getNotebookEditorFromEditorPane } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService';
import { INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService';
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { NOTEBOOK_VARIABLE_VIEW_ENABLED } from 'vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariableContextKeys';
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';

export class NotebookVariables extends Disposable implements IWorkbenchContribution {
private listeners: IDisposable[] = [];
Expand All @@ -33,14 +35,15 @@ export class NotebookVariables extends Disposable implements IWorkbenchContribut
@IConfigurationService private readonly configurationService: IConfigurationService,
@IEditorService private readonly editorService: IEditorService,
@INotebookExecutionStateService private readonly notebookExecutionStateService: INotebookExecutionStateService,
@INotebookKernelService private readonly notebookKernelService: INotebookKernelService
@INotebookKernelService private readonly notebookKernelService: INotebookKernelService,
@INotebookService private readonly notebookDocumentService: INotebookService
) {
super();

this.viewEnabled = NOTEBOOK_VARIABLE_VIEW_ENABLED.bindTo(contextKeyService);

this.listeners.push(this.editorService.onDidActiveEditorChange(() => this.handleInitEvent()));
this.listeners.push(this.notebookExecutionStateService.onDidChangeExecution((e) => this.handleInitEvent()));
this.listeners.push(this.notebookExecutionStateService.onDidChangeExecution((e) => this.handleInitEvent(e.notebook)));

this.configListener = configurationService.onDidChangeConfiguration((e) => this.handleConfigChange(e));
}
Expand All @@ -57,21 +60,23 @@ export class NotebookVariables extends Disposable implements IWorkbenchContribut
}
}

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

if (this.hasVariableProvider() && !this.initialized && this.initializeView()) {
if (this.hasVariableProvider(notebook) && !this.initialized && this.initializeView()) {
this.viewEnabled.set(true);
this.initialized = true;
this.listeners.forEach(listener => listener.dispose());
}
}
}

private hasVariableProvider() {
const notebookDocument = getNotebookEditorFromEditorPane(this.editorService.activeEditorPane)?.getViewModel()?.notebookDocument;
return notebookDocument && this.notebookKernelService.getMatchingKernel(notebookDocument).selected?.hasVariableProvider;
private hasVariableProvider(notebookUri?: URI) {
const notebook = notebookUri ?
this.notebookDocumentService.getNotebookTextModel(notebookUri) :
getNotebookEditorFromEditorPane(this.editorService.activeEditorPane)?.getViewModel()?.notebookDocument;
return notebook && this.notebookKernelService.getMatchingKernel(notebook).selected?.hasVariableProvider;
}

private initializeView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export class NotebookVariablesView extends ViewPane {
private setActiveNotebook() {
const current = this.activeNotebook;
const activeEditorPane = this.editorService.activeEditorPane;
if (activeEditorPane?.getId() === 'workbench.editor.notebook') {
if (activeEditorPane?.getId() === 'workbench.editor.notebook' || activeEditorPane?.getId() === 'workbench.editor.interactive') {
const notebookDocument = getNotebookEditorFromEditorPane(activeEditorPane)?.getViewModel()?.notebookDocument;
this.activeNotebook = notebookDocument;
}
Expand Down