Skip to content

Commit

Permalink
chore: ensure disposables are disposed (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruifigueira authored Sep 10, 2024
1 parent 4328be9 commit 1296c74
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/debugHighlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export class DebugHighlight {

const self = this;
this._disposables = [
this._onErrorInDebuggerEmitter,
this._onStdOutEmitter,
vscode.debug.onDidStartDebugSession(session => {
if (isPlaywrightSession(session))
this._debugSessions.set(session.id, session);
Expand Down
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export class Extension implements RunHooks {
if (event.affectsConfiguration('playwright.env'))
this._rebuildModels(false);
}),
this._testTree,
this._models,
this._models.onUpdated(() => this._modelsUpdated()),
this._treeItemObserver.onTreeItemSelected(item => this._treeItemSelected(item)),
Expand Down Expand Up @@ -812,6 +813,7 @@ class TreeItemObserver implements vscodeTypes.Disposable{

dispose() {
clearTimeout(this._timeout);
this._treeItemSelected.dispose();
}

selectedTreeItem(): vscodeTypes.TreeItem | null {
Expand Down
13 changes: 9 additions & 4 deletions src/reusedBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,15 @@ export class ReusedBrowser implements vscodeTypes.Disposable {
this.onHighlightRequestedForTest = this._onHighlightRequestedForTestEvent.event;
this._settingsModel = settingsModel;

this._disposables.push(settingsModel.showBrowser.onChange(value => {
if (!value)
this.closeAllBrowsers();
}));
this._disposables.push(
this._onPageCountChangedEvent,
this._onHighlightRequestedForTestEvent,
this._onRunningTestsChangedEvent,
settingsModel.showBrowser.onChange(value => {
if (!value)
this.closeAllBrowsers();
}),
);
}

dispose() {
Expand Down
20 changes: 12 additions & 8 deletions src/settingsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,17 @@ export class SettingsModel extends DisposableBase {
this.runGlobalSetupOnEachRun = this._createSetting('runGlobalSetupOnEachRun');
this.embeddedTraceViewer = this._createHiddenSetting('embeddedTraceViewer', false);

this.showBrowser.onChange(enabled => {
if (enabled && this.showTrace.get())
this.showTrace.set(false);
});
this.showTrace.onChange(enabled => {
if (enabled && this.showBrowser.get())
this.showBrowser.set(false);
});
this._disposables.push(
this._onChange,
this.showBrowser.onChange(enabled => {
if (enabled && this.showTrace.get())
this.showTrace.set(false);
}),
this.showTrace.onChange(enabled => {
if (enabled && this.showBrowser.get())
this.showBrowser.set(false);
}),
);

this._modernize();
}
Expand Down Expand Up @@ -140,6 +143,7 @@ class PersistentSetting<T> extends SettingBase<T> {

const settingFQN = `playwright.${settingName}`;
this._disposables = [
this._onChange,
vscode.workspace.onDidChangeConfiguration(event => {
if (event.affectsConfiguration(settingFQN))
this._onChange.fire(this.get());
Expand Down
3 changes: 3 additions & 0 deletions src/testModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,9 @@ export class TestModelCollection extends DisposableBase {
this.embedder = embedder;
this._didUpdate = new vscode.EventEmitter();
this.onUpdated = this._didUpdate.event;
this._disposables = [
this._didUpdate,
];
}

setModelEnabled(configFile: string, enabled: boolean, userGesture?: boolean) {
Expand Down
24 changes: 24 additions & 0 deletions tests/mock/vscode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ class TestRunProfile {

dispose() {
this.runProfiles.splice(this.runProfiles.indexOf(this), 1);
this.didChangeDefault.dispose();
}
}

Expand Down Expand Up @@ -559,6 +560,11 @@ export class TestController {
const profile = this.runProfiles.find(p => p.kind === this.vscode.TestRunProfileKind.Debug)!;
return profile.run(include, exclude);
}

dispose() {
this.didChangeTestItem.dispose();
this._didCreateTestRun.dispose();
}
}

type Decoration = { type?: number, range: Range, renderOptions?: any };
Expand Down Expand Up @@ -653,6 +659,9 @@ class FileSystemWatcher {

dispose() {
this.vscode.fsWatchers.delete(this);
this.didCreate.dispose();
this.didChange.dispose();
this.didDelete.dispose();
}
}

Expand Down Expand Up @@ -746,6 +755,11 @@ class Debug {
}
});
}

dispose() {
this._didStartDebugSession.dispose();
this._didTerminateDebugSession.dispose();
}
}

export class DebugSession {
Expand Down Expand Up @@ -913,6 +927,16 @@ export class VSCode {
this.commandLog.push(name);
};
this.debug = new Debug();
this.context.subscriptions.push(
this.debug,
this._didChangeActiveTextEditor,
this._didChangeVisibleTextEditors,
this._didChangeTextEditorSelection,
this._didChangeWorkspaceFolders,
this._didChangeTextDocument,
this._didChangeConfiguration,
this._didShowInputBox,
);

const diagnosticsCollections: DiagnosticsCollection[] = [];
this.languages.registerHoverProvider = (language: string, provider: HoverProvider) => {
Expand Down

0 comments on commit 1296c74

Please sign in to comment.