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

Re-create disposed EventEmitter in clear #1491

Merged
merged 1 commit into from
Jun 5, 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
4 changes: 2 additions & 2 deletions client/src/common/diagnostic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ class DiagnosticFeatureProviderImpl implements DiagnosticProviderShape {
};

this.activeTextDocument = Window.activeTextEditor?.document;
Window.onDidChangeActiveTextEditor((editor) => {
disposables.push(Window.onDidChangeActiveTextEditor((editor) => {
const oldActive = this.activeTextDocument;
this.activeTextDocument = editor?.document;
if (oldActive !== undefined) {
Expand All @@ -968,7 +968,7 @@ class DiagnosticFeatureProviderImpl implements DiagnosticProviderShape {
this.diagnosticRequestor.pull(this.activeTextDocument);
}
}
});
}));

// For pull model diagnostics we pull for documents visible in the UI.
// From an eventing point of view we still rely on open document events
Expand Down
3 changes: 2 additions & 1 deletion client/src/common/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ export abstract class TextDocumentEventFeature<P extends { textDocument: TextDoc

private _listener: Disposable | undefined;
protected readonly _selectors: Map<string, VDocumentSelector>;
private readonly _onNotificationSent: EventEmitter<NotificationSendEvent<P>>;
private _onNotificationSent: EventEmitter<NotificationSendEvent<P>>;

public static textDocumentFilter(selectors: IterableIterator<VDocumentSelector>, textDocument: TextDocument): boolean {
for (const selector of selectors) {
Expand Down Expand Up @@ -429,6 +429,7 @@ export abstract class TextDocumentEventFeature<P extends { textDocument: TextDoc
public clear(): void {
this._selectors.clear();
this._onNotificationSent.dispose();
this._onNotificationSent = new EventEmitter<NotificationSendEvent<P>>();
if (this._listener) {
this._listener.dispose();
this._listener = undefined;
Expand Down
16 changes: 12 additions & 4 deletions client/src/common/notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1009,10 +1009,10 @@ export class NotebookDocumentSyncFeature implements DynamicFeature<proto.Noteboo
private readonly client: FeatureClient<NotebookDocumentMiddleware, $NotebookDocumentOptions>;
private readonly registrations: Map<string, NotebookDocumentSyncFeatureProvider>;
private dedicatedChannel: vscode.DocumentSelector | undefined;
private readonly _onChangeNotificationSent: vscode.EventEmitter<VNotebookDocumentChangeEvent>;
private readonly _onOpenNotificationSent: vscode.EventEmitter<vscode.NotebookDocument>;
private readonly _onCloseNotificationSent: vscode.EventEmitter<vscode.NotebookDocument>;
private readonly _onSaveNotificationSent: vscode.EventEmitter<vscode.NotebookDocument>;
private _onChangeNotificationSent: vscode.EventEmitter<VNotebookDocumentChangeEvent>;
private _onOpenNotificationSent: vscode.EventEmitter<vscode.NotebookDocument>;
private _onCloseNotificationSent: vscode.EventEmitter<vscode.NotebookDocument>;
private _onSaveNotificationSent: vscode.EventEmitter<vscode.NotebookDocument>;

constructor(client: FeatureClient<NotebookDocumentMiddleware, $NotebookDocumentOptions>) {
this.client = client;
Expand Down Expand Up @@ -1156,6 +1156,14 @@ export class NotebookDocumentSyncFeature implements DynamicFeature<proto.Noteboo
provider.dispose();
}
this.registrations.clear();
this._onChangeNotificationSent.dispose();
this._onChangeNotificationSent = new vscode.EventEmitter<VNotebookDocumentChangeEvent>();
this._onOpenNotificationSent.dispose();
this._onOpenNotificationSent = new vscode.EventEmitter<vscode.NotebookDocument>();
this._onCloseNotificationSent.dispose();
this._onCloseNotificationSent = new vscode.EventEmitter<vscode.NotebookDocument>();
this._onSaveNotificationSent.dispose();
this._onSaveNotificationSent = new vscode.EventEmitter<vscode.NotebookDocument>();
}

public handles(textDocument: vscode.TextDocument): boolean {
Expand Down