diff --git a/src/vs/workbench/api/browser/mainThreadNotebookKernels.ts b/src/vs/workbench/api/browser/mainThreadNotebookKernels.ts index 196ecaea1ea..e1190a65660 100644 --- a/src/vs/workbench/api/browser/mainThreadNotebookKernels.ts +++ b/src/vs/workbench/api/browser/mainThreadNotebookKernels.ts @@ -440,4 +440,8 @@ export class MainThreadNotebookKernels implements MainThreadNotebookKernelsShape emitter.fire(undefined); } } + + $variablesUpdated(notebookUri: UriComponents): void { + this._notebookKernelService.notifyVariablesChange(URI.revive(notebookUri)); + } } diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index 7bb1c7cc4b4..a5675e79f1e 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -1134,6 +1134,7 @@ export interface MainThreadNotebookKernelsShape extends IDisposable { $removeKernelSourceActionProvider(handle: number, eventHandle: number): void; $emitNotebookKernelSourceActionsChangeEvent(eventHandle: number): void; $receiveVariable(requestId: string, variable: VariablesResult): void; + $variablesUpdated(notebookUri: UriComponents): void; } export interface MainThreadNotebookRenderersShape extends IDisposable { diff --git a/src/vs/workbench/api/common/extHostNotebookKernels.ts b/src/vs/workbench/api/common/extHostNotebookKernels.ts index 76eadcb84c3..164369d1212 100644 --- a/src/vs/workbench/api/common/extHostNotebookKernels.ts +++ b/src/vs/workbench/api/common/extHostNotebookKernels.ts @@ -212,6 +212,7 @@ export class ExtHostNotebookKernels implements ExtHostNotebookKernelsShape { checkProposedApiEnabled(extension, 'notebookVariableProvider'); _variableProvider = value; data.hasVariableProvider = !!value; + value?.onDidChangeVariables(e => that._proxy.$variablesUpdated(e.uri)); _update(); }, get variableProvider() { diff --git a/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesView.ts b/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesView.ts index 445c8e442be..eba684c4c9f 100644 --- a/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesView.ts +++ b/src/vs/workbench/contrib/notebook/browser/contrib/notebookVariables/notebookVariablesView.ts @@ -5,6 +5,7 @@ import { IObjectTreeElement } from 'vs/base/browser/ui/tree/tree'; import { CancellationToken } from 'vs/base/common/cancellation'; +import { URI } from 'vs/base/common/uri'; import * as nls from 'vs/nls'; import { ILocalizedString } from 'vs/platform/action/common/action'; import { ICommandService } from 'vs/platform/commands/common/commands'; @@ -56,6 +57,7 @@ export class NotebookVariablesView extends ViewPane { this._register(this.editorService.onDidActiveEditorChange(this.handleActiveEditorChange.bind(this))); this._register(this.notebookExecutionStateService.onDidChangeExecution(this.handleExecutionStateChange.bind(this))); + this._register(this.notebookKernelService.onDidNotebookVariablesUpdate(this.handleVariablesChanged.bind(this))); } protected override renderBody(container: HTMLElement): void { @@ -105,6 +107,12 @@ export class NotebookVariablesView extends ViewPane { } } + private handleVariablesChanged(notebookUri: URI) { + if (this.activeNotebook && notebookUri.toString() === this.activeNotebook.uri.toString()) { + this.updateVariables(this.activeNotebook); + } + } + private async updateVariables(notebook: NotebookTextModel) { const selectedKernel = this.notebookKernelService.getMatchingKernel(notebook).selected; if (selectedKernel && selectedKernel.hasVariableProvider) { diff --git a/src/vs/workbench/contrib/notebook/browser/services/notebookKernelServiceImpl.ts b/src/vs/workbench/contrib/notebook/browser/services/notebookKernelServiceImpl.ts index adc3249aab0..d86b1b7f928 100644 --- a/src/vs/workbench/contrib/notebook/browser/services/notebookKernelServiceImpl.ts +++ b/src/vs/workbench/contrib/notebook/browser/services/notebookKernelServiceImpl.ts @@ -106,6 +106,7 @@ export class NotebookKernelService extends Disposable implements INotebookKernel private readonly _onDidRemoveKernel = this._register(new Emitter()); private readonly _onDidChangeNotebookAffinity = this._register(new Emitter()); private readonly _onDidChangeSourceActions = this._register(new Emitter()); + private readonly _onDidNotebookVariablesChange = this._register(new Emitter()); private readonly _kernelSources = new Map(); private readonly _kernelSourceActionsUpdates = new Map(); private readonly _kernelDetectionTasks = new Map(); @@ -118,6 +119,7 @@ export class NotebookKernelService extends Disposable implements INotebookKernel readonly onDidChangeNotebookAffinity: Event = this._onDidChangeNotebookAffinity.event; readonly onDidChangeSourceActions: Event = this._onDidChangeSourceActions.event; readonly onDidChangeKernelDetectionTasks: Event = this._onDidChangeKernelDetectionTasks.event; + readonly onDidNotebookVariablesUpdate: Event = this._onDidNotebookVariablesChange.event; private static _storageNotebookBinding = 'notebook.controller2NotebookBindings'; @@ -201,6 +203,10 @@ export class NotebookKernelService extends Disposable implements INotebookKernel } } + notifyVariablesChange(notebookUri: URI): void { + this._onDidNotebookVariablesChange.fire(notebookUri); + } + registerKernel(kernel: INotebookKernel): IDisposable { if (this._kernels.has(kernel.id)) { throw new Error(`NOTEBOOK CONTROLLER with id '${kernel.id}' already exists`); diff --git a/src/vs/workbench/contrib/notebook/common/notebookKernelService.ts b/src/vs/workbench/contrib/notebook/common/notebookKernelService.ts index 30c9bc59f57..6b1e5ca8c9b 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookKernelService.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookKernelService.ts @@ -117,6 +117,7 @@ export interface INotebookKernelService { readonly onDidRemoveKernel: Event; readonly onDidChangeSelectedNotebooks: Event; readonly onDidChangeNotebookAffinity: Event; + readonly onDidNotebookVariablesUpdate: Event; registerKernel(kernel: INotebookKernel): IDisposable; getMatchingKernel(notebook: INotebookTextModelLike): INotebookKernelMatchResult; @@ -155,6 +156,8 @@ export interface INotebookKernelService { registerKernelSourceActionProvider(viewType: string, provider: IKernelSourceActionProvider): IDisposable; getKernelSourceActions2(notebook: INotebookTextModelLike): Promise; //#endregion + + notifyVariablesChange(notebookUri: URI): void; } export const INotebookKernelHistoryService = createDecorator('INotebookKernelHistoryService'); diff --git a/src/vscode-dts/vscode.proposed.notebookVariableProvider.d.ts b/src/vscode-dts/vscode.proposed.notebookVariableProvider.d.ts index 02fa3f10b77..0071af59ff4 100644 --- a/src/vscode-dts/vscode.proposed.notebookVariableProvider.d.ts +++ b/src/vscode-dts/vscode.proposed.notebookVariableProvider.d.ts @@ -21,7 +21,7 @@ declare module 'vscode' { } interface NotebookVariableProvider { - onDidChangeVariables: Event; + onDidChangeVariables: Event; /** When parent is undefined, this is requesting global Variables. When a variable is passed, it's requesting child props of that Variable. */ provideVariables(notebook: NotebookDocument, parent: Variable | undefined, kind: NotebookVariablesRequestKind, start: number, token: CancellationToken): AsyncIterable;