Skip to content

Commit

Permalink
Remove duplicate event (#16172)
Browse files Browse the repository at this point in the history
* Remove duplicate event

* Fixes
  • Loading branch information
DonJayamanne authored Oct 29, 2024
1 parent aa3cd0d commit 5665acf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
5 changes: 4 additions & 1 deletion src/notebooks/controllers/controllerRegistration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,11 @@ export class ControllerRegistration implements IControllerRegistration, IExtensi
this.disposables.push(controller);
this.registeredControllers.set(controller.id, controller);
added.push(controller);
controller.onNotebookControllerSelected(
controller.onNotebookControllerSelectionChanged(
(e) => {
if (!e.selected) {
return;
}
logger.ci(`Controller ${e.controller?.id} selected for ${e.notebook.uri.toString()}`);
this.selectedControllers.set(e.notebook, e.controller);
// Now notify out that we have updated a notebooks controller
Expand Down
6 changes: 2 additions & 4 deletions src/notebooks/controllers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { JupyterNotebookView, InteractiveWindowView } from '../../platform/commo
import { IDisposable } from '../../platform/common/types';
import { JupyterServerCollection } from '../../api';
import { EnvironmentPath } from '@vscode/python-extension';
import type { VSCodeNotebookController } from './vscodeNotebookController';

export const InteractiveControllerIdSuffix = ' (Interactive)';

Expand All @@ -23,13 +24,10 @@ export interface IVSCodeNotebookController extends IDisposable {
readonly id: string;
readonly label: string;
readonly viewType: typeof JupyterNotebookView | typeof InteractiveWindowView;
readonly onNotebookControllerSelected: vscode.Event<{
notebook: vscode.NotebookDocument;
controller: IVSCodeNotebookController;
}>;
readonly onNotebookControllerSelectionChanged: vscode.Event<{
selected: boolean;
notebook: vscode.NotebookDocument;
controller: VSCodeNotebookController;
}>;
readonly onConnecting: vscode.Event<void>;
readonly onDidDispose: vscode.Event<void>;
Expand Down
27 changes: 11 additions & 16 deletions src/notebooks/controllers/vscodeNotebookController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,10 @@ import type { INotebookMetadata } from '@jupyterlab/nbformat';
* in the kernel picker by VS code.
*/
export class VSCodeNotebookController implements Disposable, IVSCodeNotebookController {
private readonly _onNotebookControllerSelected: EventEmitter<{
notebook: NotebookDocument;
controller: VSCodeNotebookController;
}>;
private readonly _onNotebookControllerSelectionChanged = new EventEmitter<{
selected: boolean;
notebook: NotebookDocument;
controller: VSCodeNotebookController;
}>();
private readonly _onConnecting = new EventEmitter<void>();
private pendingCellAdditions = new WeakMap<NotebookDocument, Promise<void>>();
Expand Down Expand Up @@ -125,9 +122,6 @@ export class VSCodeNotebookController implements Disposable, IVSCodeNotebookCont
return this._viewType as typeof InteractiveWindowView | typeof JupyterNotebookView;
}

get onNotebookControllerSelected() {
return this._onNotebookControllerSelected.event;
}
get onNotebookControllerSelectionChanged() {
return this._onNotebookControllerSelectionChanged.event;
}
Expand Down Expand Up @@ -198,11 +192,6 @@ export class VSCodeNotebookController implements Disposable, IVSCodeNotebookCont
) {
trackControllerCreation(kernelConnection.id, kernelConnection.interpreter?.id);
disposableRegistry.push(this);
this._onNotebookControllerSelected = new EventEmitter<{
notebook: NotebookDocument;
controller: VSCodeNotebookController;
}>();

this.displayData = this.displayDataProvider.getDisplayData(this.connection);
this.controller = notebooks.createNotebookController(
id,
Expand Down Expand Up @@ -345,7 +334,6 @@ export class VSCodeNotebookController implements Disposable, IVSCodeNotebookCont
} called from ${new Error('').stack}`
);
this.isDisposed = true;
this._onNotebookControllerSelected.dispose();
this._onNotebookControllerSelectionChanged.dispose();
this._onConnecting.dispose();
this.controller.dispose();
Expand Down Expand Up @@ -428,7 +416,11 @@ export class VSCodeNotebookController implements Disposable, IVSCodeNotebookCont
kernel.dispose().catch(noop);
}
this.associatedDocuments.delete(event.notebook);
this._onNotebookControllerSelectionChanged.fire(event);
this._onNotebookControllerSelectionChanged.fire({
controller: this,
notebook: event.notebook,
selected: event.selected
});

return;
}
Expand All @@ -453,8 +445,11 @@ export class VSCodeNotebookController implements Disposable, IVSCodeNotebookCont
await this.updateCellLanguages(event.notebook);

// If this NotebookController was selected, fire off the event
this._onNotebookControllerSelected.fire({ notebook: event.notebook, controller: this });
this._onNotebookControllerSelectionChanged.fire(event);
this._onNotebookControllerSelectionChanged.fire({
controller: this,
notebook: event.notebook,
selected: event.selected
});
logger.debug(`Controller selection change completed`);
deferred.resolve();
}
Expand Down

0 comments on commit 5665acf

Please sign in to comment.