Skip to content

Commit 1ce790d

Browse files
authored
Re-create disposed EventEmitter in clear (#1491)
1 parent 1f603f4 commit 1ce790d

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

client/src/common/diagnostic.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ class DiagnosticFeatureProviderImpl implements DiagnosticProviderShape {
956956
};
957957

958958
this.activeTextDocument = Window.activeTextEditor?.document;
959-
Window.onDidChangeActiveTextEditor((editor) => {
959+
disposables.push(Window.onDidChangeActiveTextEditor((editor) => {
960960
const oldActive = this.activeTextDocument;
961961
this.activeTextDocument = editor?.document;
962962
if (oldActive !== undefined) {
@@ -968,7 +968,7 @@ class DiagnosticFeatureProviderImpl implements DiagnosticProviderShape {
968968
this.diagnosticRequestor.pull(this.activeTextDocument);
969969
}
970970
}
971-
});
971+
}));
972972

973973
// For pull model diagnostics we pull for documents visible in the UI.
974974
// From an eventing point of view we still rely on open document events

client/src/common/features.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ export abstract class TextDocumentEventFeature<P extends { textDocument: TextDoc
339339

340340
private _listener: Disposable | undefined;
341341
protected readonly _selectors: Map<string, VDocumentSelector>;
342-
private readonly _onNotificationSent: EventEmitter<NotificationSendEvent<P>>;
342+
private _onNotificationSent: EventEmitter<NotificationSendEvent<P>>;
343343

344344
public static textDocumentFilter(selectors: IterableIterator<VDocumentSelector>, textDocument: TextDocument): boolean {
345345
for (const selector of selectors) {
@@ -429,6 +429,7 @@ export abstract class TextDocumentEventFeature<P extends { textDocument: TextDoc
429429
public clear(): void {
430430
this._selectors.clear();
431431
this._onNotificationSent.dispose();
432+
this._onNotificationSent = new EventEmitter<NotificationSendEvent<P>>();
432433
if (this._listener) {
433434
this._listener.dispose();
434435
this._listener = undefined;

client/src/common/notebook.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,10 +1009,10 @@ export class NotebookDocumentSyncFeature implements DynamicFeature<proto.Noteboo
10091009
private readonly client: FeatureClient<NotebookDocumentMiddleware, $NotebookDocumentOptions>;
10101010
private readonly registrations: Map<string, NotebookDocumentSyncFeatureProvider>;
10111011
private dedicatedChannel: vscode.DocumentSelector | undefined;
1012-
private readonly _onChangeNotificationSent: vscode.EventEmitter<VNotebookDocumentChangeEvent>;
1013-
private readonly _onOpenNotificationSent: vscode.EventEmitter<vscode.NotebookDocument>;
1014-
private readonly _onCloseNotificationSent: vscode.EventEmitter<vscode.NotebookDocument>;
1015-
private readonly _onSaveNotificationSent: vscode.EventEmitter<vscode.NotebookDocument>;
1012+
private _onChangeNotificationSent: vscode.EventEmitter<VNotebookDocumentChangeEvent>;
1013+
private _onOpenNotificationSent: vscode.EventEmitter<vscode.NotebookDocument>;
1014+
private _onCloseNotificationSent: vscode.EventEmitter<vscode.NotebookDocument>;
1015+
private _onSaveNotificationSent: vscode.EventEmitter<vscode.NotebookDocument>;
10161016

10171017
constructor(client: FeatureClient<NotebookDocumentMiddleware, $NotebookDocumentOptions>) {
10181018
this.client = client;
@@ -1156,6 +1156,14 @@ export class NotebookDocumentSyncFeature implements DynamicFeature<proto.Noteboo
11561156
provider.dispose();
11571157
}
11581158
this.registrations.clear();
1159+
this._onChangeNotificationSent.dispose();
1160+
this._onChangeNotificationSent = new vscode.EventEmitter<VNotebookDocumentChangeEvent>();
1161+
this._onOpenNotificationSent.dispose();
1162+
this._onOpenNotificationSent = new vscode.EventEmitter<vscode.NotebookDocument>();
1163+
this._onCloseNotificationSent.dispose();
1164+
this._onCloseNotificationSent = new vscode.EventEmitter<vscode.NotebookDocument>();
1165+
this._onSaveNotificationSent.dispose();
1166+
this._onSaveNotificationSent = new vscode.EventEmitter<vscode.NotebookDocument>();
11591167
}
11601168

11611169
public handles(textDocument: vscode.TextDocument): boolean {

0 commit comments

Comments
 (0)