oxc/editors/vscode/client/ConfigService.ts
Alexander S. 259a47b2ac
refactor(vscode): move commands and findBinary to separate files (#8605)
pure refactor. wanted to add tests but needs to mocks :/
2025-01-20 09:06:06 +08:00

37 lines
1 KiB
TypeScript

import { ConfigurationChangeEvent, workspace } from 'vscode';
import { Config } from './Config';
import { IDisposable } from './types';
export class ConfigService implements IDisposable {
private static readonly _namespace = 'oxc';
private readonly _disposables: IDisposable[] = [];
public readonly config: Config;
public onConfigChange:
| ((this: ConfigService, config: ConfigurationChangeEvent) => void)
| undefined;
constructor() {
this.config = new Config();
this.onConfigChange = undefined;
const disposeChangeListener = workspace.onDidChangeConfiguration(
this.onVscodeConfigChange.bind(this),
);
this._disposables.push(disposeChangeListener);
}
private onVscodeConfigChange(event: ConfigurationChangeEvent): void {
if (event.affectsConfiguration(ConfigService._namespace)) {
this.config.refresh();
this.onConfigChange?.call(this, event);
}
}
dispose() {
for (const disposable of this._disposables) {
disposable.dispose();
}
}
}