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

chore: migrate config settings to workspaceState #480

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
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class Extension implements RunHooks {
},
});

this._settingsModel = new SettingsModel(vscode);
this._settingsModel = new SettingsModel(vscode, context);
this._models = new TestModelCollection(vscode, context);
this._reusedBrowser = new ReusedBrowser(this._vscode, this._settingsModel, this._envProvider.bind(this));
this._traceViewer = new TraceViewer(this._vscode, this._settingsModel, this._envProvider.bind(this));
Expand Down
16 changes: 15 additions & 1 deletion src/settingsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,21 @@ export type WorkspaceSettings = {
configs?: ConfigSettings[];
};

export const workspaceStateKey = 'pw.workspace-settings';

export class SettingsModel extends DisposableBase {
private _vscode: vscodeTypes.VSCode;
private _settings = new Map<string, Setting<any>>();
private _context: vscodeTypes.ExtensionContext;
readonly onChange: vscodeTypes.Event<void>;
private _onChange: vscodeTypes.EventEmitter<void>;
showBrowser: Setting<boolean>;
showTrace: Setting<boolean>;

constructor(vscode: vscodeTypes.VSCode) {
constructor(vscode: vscodeTypes.VSCode, context: vscodeTypes.ExtensionContext) {
super();
this._vscode = vscode;
this._context = context;
this._onChange = new vscode.EventEmitter();
this.onChange = this._onChange.event;

Expand All @@ -58,6 +62,16 @@ export class SettingsModel extends DisposableBase {
if (enabled && this.showBrowser.get())
this.showBrowser.set(false);
});

this._modernize();
}

private _modernize() {
const workspaceSettings = this._vscode.workspace.getConfiguration('playwright').get('workspaceSettings') as any;
if (workspaceSettings?.configs && !this._context.workspaceState.get(workspaceStateKey)) {
this._context.workspaceState.update(workspaceStateKey, { configs: workspaceSettings.configs });
this._vscode.workspace.getConfiguration('playwright').update('workspaceSettings', undefined);
}
}

private _createSetting<T>(settingName: string): Setting<T> {
Expand Down
3 changes: 1 addition & 2 deletions src/testModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { resolveSourceMap } from './utils';
import { ConfigListFilesReport, ProjectConfigWithFiles } from './listTests';
import * as reporterTypes from './upstream/reporter';
import { TeleSuite } from './upstream/teleReceiver';
import { workspaceStateKey } from './settingsModel';
import type { SettingsModel, WorkspaceSettings } from './settingsModel';
import path from 'path';
import { DisposableBase } from './disposableBase';
Expand Down Expand Up @@ -744,8 +745,6 @@ export function projectFiles(project: TestProject): Map<string, reporterTypes.Su
return files;
}

const workspaceStateKey = 'pw.workspace-settings';

const listFilesFlag = Symbol('listFilesFlag');

function isAncestorOf(root: vscodeTypes.TestItem, descendent: vscodeTypes.TestItem) {
Expand Down