fix(editor): reload workspace configuration after change (#7302)

after changing `settings.json`, the changes whould not to updated
internally.

With this PR the updated values get passed to the language-server. 🥳 

probably closes https://github.com/oxc-project/backlog/issues/132
because we also support the oxlint config

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Alexander S. 2024-11-16 06:34:44 +01:00 committed by GitHub
parent 1cbc624a8b
commit ba0b2ff856
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4,11 +4,11 @@ import { IDisposable } from './types';
export class ConfigService implements Config, IDisposable {
private static readonly _namespace = 'oxc';
private readonly _disposables: IDisposable[] = [];
private _inner: WorkspaceConfiguration;
private _runTrigger: Trigger;
private _enable: boolean;
private _trace: TraceLevel;
private _configPath: string;
private _inner!: WorkspaceConfiguration;
private _runTrigger!: Trigger;
private _enable!: boolean;
private _trace!: TraceLevel;
private _configPath!: string;
private _binPath: string | undefined;
public onConfigChange:
@ -16,12 +16,7 @@ export class ConfigService implements Config, IDisposable {
| undefined;
constructor() {
this._inner = workspace.getConfiguration(ConfigService._namespace);
this._runTrigger = this._inner.get<Trigger>('lint.run') || 'onType';
this._enable = this._inner.get<boolean>('enable') ?? true;
this._trace = this._inner.get<TraceLevel>('trace.server') || 'off';
this._configPath = this._inner.get<string>('configPath') || '.eslintrc';
this._binPath = this._inner.get<string>('path.server');
this.setSettingsFromWorkspace();
this.onConfigChange = undefined;
const disposeChangeListener = workspace.onDidChangeConfiguration(
@ -30,6 +25,16 @@ export class ConfigService implements Config, IDisposable {
this._disposables.push(disposeChangeListener);
}
private setSettingsFromWorkspace(): void {
this._inner = workspace.getConfiguration(ConfigService._namespace);
this._runTrigger = this._inner.get<Trigger>('lint.run') || 'onType';
this._enable = this._inner.get<boolean>('enable') ?? true;
this._trace = this._inner.get<TraceLevel>('trace.server') || 'off';
this._configPath = this._inner.get<string>('configPath') || '.eslintrc';
this._binPath = this._inner.get<string>('path.server');
}
get runTrigger(): Trigger {
return this._runTrigger;
}
@ -87,11 +92,7 @@ export class ConfigService implements Config, IDisposable {
private onVscodeConfigChange(event: ConfigurationChangeEvent): void {
if (event.affectsConfiguration(ConfigService._namespace)) {
this._runTrigger = this._inner.get<Trigger>('lint.run') || 'onType';
this._enable = this._inner.get<boolean>('enable') ?? true;
this._trace = this._inner.get<TraceLevel>('trace.server') || 'off';
this._configPath = this._inner.get<string>('configPath') || '.eslintrc';
this._binPath = this._inner.get<string>('path.server');
this.setSettingsFromWorkspace();
this.onConfigChange?.call(this, event);
}
}