mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 20:28:58 +00:00
37 lines
1,021 B
TypeScript
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();
|
|
}
|
|
}
|
|
}
|