Skip to content

Commit

Permalink
Dispose eventemitters (152)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Nov 13, 2024
1 parent 53ac184 commit 9409f84
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/controllers/ExtensionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export class ExtensionController implements Disposable {
const codelensProvider = new RunCommandCodeLensProvider();

this._context.subscriptions.push(
codelensProvider,
vscode.languages.registerCodeLensProvider('groovy', codelensProvider),
vscode.languages.registerCodeLensProvider('python', codelensProvider)
);
Expand Down Expand Up @@ -530,7 +531,10 @@ export class ExtensionController implements Disposable {
this._context.subscriptions.push(
this._serverTreeView,
this._serverConnectionTreeView,
this._serverConnectionPanelTreeView
this._serverConnectionPanelTreeView,
this._serverTreeProvider,
this._serverConnectionTreeProvider,
this._serverConnectionPanelTreeProvider
);
};

Expand Down
7 changes: 6 additions & 1 deletion src/providers/RunCommandCodeLensProvider.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as vscode from 'vscode';
import { ICON_ID } from '../common';
import type { Disposable } from '../types';

/**
* Provides inline editor code lenses for running Deephaven code.
*/
export class RunCommandCodeLensProvider
implements vscode.CodeLensProvider<vscode.CodeLens>
implements vscode.CodeLensProvider<vscode.CodeLens>, Disposable
{
constructor() {
vscode.workspace.onDidChangeConfiguration(() => {
Expand All @@ -22,6 +23,10 @@ export class RunCommandCodeLensProvider
readonly onDidChangeCodeLenses: vscode.Event<void> =
this._onDidChangeCodeLenses.event;

dispose = async (): Promise<void> => {
this._onDidChangeCodeLenses.dispose();
};

provideCodeLenses(
document: vscode.TextDocument,
_token: vscode.CancellationToken
Expand Down
8 changes: 6 additions & 2 deletions src/providers/TreeDataProviderBase.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as vscode from 'vscode';
import type { IServerManager } from '../types';
import type { Disposable, IServerManager } from '../types';

/**
* Base class for tree view data providers.
*/
export abstract class TreeDataProviderBase<T>
implements vscode.TreeDataProvider<T>
implements vscode.TreeDataProvider<T>, Disposable
{
constructor(serverManager: IServerManager) {
this.serverManager = serverManager;
Expand All @@ -27,6 +27,10 @@ export abstract class TreeDataProviderBase<T>

abstract getChildren(element?: T | undefined): vscode.ProviderResult<T[]>;

dispose = async (): Promise<void> => {
this._onDidChangeTreeData.dispose();
};

refresh(): void {
this._onDidChangeTreeData.fire();
}
Expand Down
1 change: 1 addition & 0 deletions src/services/PanelService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class PanelService implements IPanelService, Disposable {
dispose = async (): Promise<void> => {
this._cnPanelMap.clear();
this._cnVariableMap.clear();
this._onDidUpdate.dispose();
};

/**
Expand Down
8 changes: 7 additions & 1 deletion src/services/SerializedKeyMap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as vscode from 'vscode';
import type { Disposable } from '../types';

/**
* Base class for Maps that need to store their keys as serialized string values
Expand All @@ -10,7 +11,7 @@ import * as vscode from 'vscode';
* // New reference on every call
* e.g. deserializeKey = (key: string) => new URL(key)
*/
export abstract class SerializedKeyMap<TKey, TValue> {
export abstract class SerializedKeyMap<TKey, TValue> implements Disposable {
constructor();
constructor(entries: readonly (readonly [TKey, TValue])[] | null);
constructor(entries?: readonly (readonly [TKey, TValue])[] | null) {
Expand Down Expand Up @@ -40,6 +41,11 @@ export abstract class SerializedKeyMap<TKey, TValue> {
keys.forEach(key => this._onDidChange.fire(key));
}

dispose = async (): Promise<void> => {
this._map.clear();
this._onDidChange.dispose();
};

get(key: TKey): TValue | undefined {
return this._map.get(this.serializeKey(key));
}
Expand Down
11 changes: 9 additions & 2 deletions src/services/ServerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ export class ServerManager implements IServerManager {

canStartServer: boolean;

async dispose(): Promise<void> {
this._onDidConnect.dispose();
this._onDidDisconnect.dispose();
this._onDidLoadConfig.dispose();
this._onDidServerStatusChange.dispose();
this._onDidRegisterEditor.dispose();
this._onDidUpdate.dispose();
}

loadServerConfig = async (): Promise<void> => {
// We want to keep any existing managed servers that aren't overridden by
// the latest config so we don't lose the PSKs that were generated when
Expand Down Expand Up @@ -625,6 +634,4 @@ export class ServerManager implements IServerManager {

this._hasEverUpdatedStatus = true;
};

async dispose(): Promise<void> {}
}
2 changes: 2 additions & 0 deletions src/services/cache/ByURLAsyncCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export class ByURLAsyncCache<TValue>
};

dispose = async (): Promise<void> => {
this._onDidInvalidate.dispose();

const promises = [...this._promiseMap.values()];
this._promiseMap.clear();

Expand Down

0 comments on commit 9409f84

Please sign in to comment.