Skip to content

Commit d16c530

Browse files
authored
enable variable view for IW (microsoft#205249)
1 parent b698f08 commit d16c530

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariables.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,25 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
import * as nls from 'vs/nls';
76
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
8-
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
7+
import { URI } from 'vs/base/common/uri';
8+
import * as nls from 'vs/nls';
9+
import { IConfigurationChangeEvent, IConfigurationService } from 'vs/platform/configuration/common/configuration';
10+
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
11+
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
912
import { Registry } from 'vs/platform/registry/common/platform';
13+
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
1014
import { Extensions, IViewContainersRegistry, IViewsRegistry } from 'vs/workbench/common/views';
1115
import { VIEWLET_ID as debugContainerId } from 'vs/workbench/contrib/debug/common/debug';
12-
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
16+
import { NOTEBOOK_VARIABLE_VIEW_ENABLED } from 'vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariableContextKeys';
1317
import { NotebookVariablesView } from 'vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesView';
18+
import { getNotebookEditorFromEditorPane } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
1419
import { variablesViewIcon } from 'vs/workbench/contrib/notebook/browser/notebookIcons';
15-
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
16-
import { IConfigurationChangeEvent, IConfigurationService } from 'vs/platform/configuration/common/configuration';
17-
import { INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService';
1820
import { NotebookSetting } from 'vs/workbench/contrib/notebook/common/notebookCommon';
19-
import { getNotebookEditorFromEditorPane } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
21+
import { INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService';
2022
import { INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService';
21-
import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
22-
import { NOTEBOOK_VARIABLE_VIEW_ENABLED } from 'vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariableContextKeys';
23+
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
24+
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
2325

2426
export class NotebookVariables extends Disposable implements IWorkbenchContribution {
2527
private listeners: IDisposable[] = [];
@@ -33,14 +35,15 @@ export class NotebookVariables extends Disposable implements IWorkbenchContribut
3335
@IConfigurationService private readonly configurationService: IConfigurationService,
3436
@IEditorService private readonly editorService: IEditorService,
3537
@INotebookExecutionStateService private readonly notebookExecutionStateService: INotebookExecutionStateService,
36-
@INotebookKernelService private readonly notebookKernelService: INotebookKernelService
38+
@INotebookKernelService private readonly notebookKernelService: INotebookKernelService,
39+
@INotebookService private readonly notebookDocumentService: INotebookService
3740
) {
3841
super();
3942

4043
this.viewEnabled = NOTEBOOK_VARIABLE_VIEW_ENABLED.bindTo(contextKeyService);
4144

4245
this.listeners.push(this.editorService.onDidActiveEditorChange(() => this.handleInitEvent()));
43-
this.listeners.push(this.notebookExecutionStateService.onDidChangeExecution((e) => this.handleInitEvent()));
46+
this.listeners.push(this.notebookExecutionStateService.onDidChangeExecution((e) => this.handleInitEvent(e.notebook)));
4447

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

60-
private handleInitEvent() {
63+
private handleInitEvent(notebook?: URI) {
6164
if (this.configurationService.getValue(NotebookSetting.notebookVariablesView)
62-
&& this.editorService.activeEditorPane?.getId() === 'workbench.editor.notebook') {
65+
&& (!!notebook || this.editorService.activeEditorPane?.getId() === 'workbench.editor.notebook')) {
6366

64-
if (this.hasVariableProvider() && !this.initialized && this.initializeView()) {
67+
if (this.hasVariableProvider(notebook) && !this.initialized && this.initializeView()) {
6568
this.viewEnabled.set(true);
6669
this.initialized = true;
6770
this.listeners.forEach(listener => listener.dispose());
6871
}
6972
}
7073
}
7174

72-
private hasVariableProvider() {
73-
const notebookDocument = getNotebookEditorFromEditorPane(this.editorService.activeEditorPane)?.getViewModel()?.notebookDocument;
74-
return notebookDocument && this.notebookKernelService.getMatchingKernel(notebookDocument).selected?.hasVariableProvider;
75+
private hasVariableProvider(notebookUri?: URI) {
76+
const notebook = notebookUri ?
77+
this.notebookDocumentService.getNotebookTextModel(notebookUri) :
78+
getNotebookEditorFromEditorPane(this.editorService.activeEditorPane)?.getViewModel()?.notebookDocument;
79+
return notebook && this.notebookKernelService.getMatchingKernel(notebook).selected?.hasVariableProvider;
7580
}
7681

7782
private initializeView() {

src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesView.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export class NotebookVariablesView extends ViewPane {
140140
private setActiveNotebook() {
141141
const current = this.activeNotebook;
142142
const activeEditorPane = this.editorService.activeEditorPane;
143-
if (activeEditorPane?.getId() === 'workbench.editor.notebook') {
143+
if (activeEditorPane?.getId() === 'workbench.editor.notebook' || activeEditorPane?.getId() === 'workbench.editor.interactive') {
144144
const notebookDocument = getNotebookEditorFromEditorPane(activeEditorPane)?.getViewModel()?.notebookDocument;
145145
this.activeNotebook = notebookDocument;
146146
}

0 commit comments

Comments
 (0)