Skip to content

Commit

Permalink
pipe variable change event through from extention API (#198572)
Browse files Browse the repository at this point in the history
pipe variable change event through
  • Loading branch information
amunger authored Nov 17, 2023
1 parent af10768 commit 6f7e102
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/vs/workbench/api/browser/mainThreadNotebookKernels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,4 +440,8 @@ export class MainThreadNotebookKernels implements MainThreadNotebookKernelsShape
emitter.fire(undefined);
}
}

$variablesUpdated(notebookUri: UriComponents): void {
this._notebookKernelService.notifyVariablesChange(URI.revive(notebookUri));
}
}
1 change: 1 addition & 0 deletions src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/api/common/extHostNotebookKernels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export class NotebookKernelService extends Disposable implements INotebookKernel
private readonly _onDidRemoveKernel = this._register(new Emitter<INotebookKernel>());
private readonly _onDidChangeNotebookAffinity = this._register(new Emitter<void>());
private readonly _onDidChangeSourceActions = this._register(new Emitter<INotebookSourceActionChangeEvent>());
private readonly _onDidNotebookVariablesChange = this._register(new Emitter<URI>());
private readonly _kernelSources = new Map<string, IKernelInfoCache>();
private readonly _kernelSourceActionsUpdates = new Map<string, IDisposable>();
private readonly _kernelDetectionTasks = new Map<string, INotebookKernelDetectionTask[]>();
Expand All @@ -118,6 +119,7 @@ export class NotebookKernelService extends Disposable implements INotebookKernel
readonly onDidChangeNotebookAffinity: Event<void> = this._onDidChangeNotebookAffinity.event;
readonly onDidChangeSourceActions: Event<INotebookSourceActionChangeEvent> = this._onDidChangeSourceActions.event;
readonly onDidChangeKernelDetectionTasks: Event<string> = this._onDidChangeKernelDetectionTasks.event;
readonly onDidNotebookVariablesUpdate: Event<URI> = this._onDidNotebookVariablesChange.event;

private static _storageNotebookBinding = 'notebook.controller2NotebookBindings';

Expand Down Expand Up @@ -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`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export interface INotebookKernelService {
readonly onDidRemoveKernel: Event<INotebookKernel>;
readonly onDidChangeSelectedNotebooks: Event<ISelectedNotebooksChangeEvent>;
readonly onDidChangeNotebookAffinity: Event<void>;
readonly onDidNotebookVariablesUpdate: Event<URI>;
registerKernel(kernel: INotebookKernel): IDisposable;

getMatchingKernel(notebook: INotebookTextModelLike): INotebookKernelMatchResult;
Expand Down Expand Up @@ -155,6 +156,8 @@ export interface INotebookKernelService {
registerKernelSourceActionProvider(viewType: string, provider: IKernelSourceActionProvider): IDisposable;
getKernelSourceActions2(notebook: INotebookTextModelLike): Promise<INotebookKernelSourceAction[]>;
//#endregion

notifyVariablesChange(notebookUri: URI): void;
}

export const INotebookKernelHistoryService = createDecorator<INotebookKernelHistoryService>('INotebookKernelHistoryService');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ declare module 'vscode' {
}

interface NotebookVariableProvider {
onDidChangeVariables: Event<void>;
onDidChangeVariables: Event<NotebookDocument>;

/** 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<VariablesResult>;
Expand Down

0 comments on commit 6f7e102

Please sign in to comment.