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

Remove duplicate event #16172

Merged
merged 4 commits into from
Oct 29, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading