oxc/editors/vscode/client/ConfigService.ts
Alexander S. 466f395816
refactor(vscode): split ConfigService and Config (#7376)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-11-21 09:57:09 +08:00

37 lines
1,021 B
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 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();
}
}
}