Skip to content

Commit

Permalink
fix(editor): reload workspace configuration after change (#7302)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Sysix and autofix-ci[bot] authored Nov 16, 2024
1 parent 1cbc624 commit ba0b2ff
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions editors/vscode/client/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,19 @@ 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:
| ((this: ConfigService, config: ConfigurationChangeEvent) => void)
| 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(
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit ba0b2ff

Please sign in to comment.