From ba0b2ff85622bf0485c1bd6993c23ba4cb48e0b0 Mon Sep 17 00:00:00 2001 From: "Alexander S." Date: Sat, 16 Nov 2024 06:34:44 +0100 Subject: [PATCH] fix(editor): reload workspace configuration after change (#7302) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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> --- editors/vscode/client/config.ts | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/editors/vscode/client/config.ts b/editors/vscode/client/config.ts index ba553afb1..d2eabe94e 100644 --- a/editors/vscode/client/config.ts +++ b/editors/vscode/client/config.ts @@ -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('lint.run') || 'onType'; - this._enable = this._inner.get('enable') ?? true; - this._trace = this._inner.get('trace.server') || 'off'; - this._configPath = this._inner.get('configPath') || '.eslintrc'; - this._binPath = this._inner.get('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('lint.run') || 'onType'; + this._enable = this._inner.get('enable') ?? true; + this._trace = this._inner.get('trace.server') || 'off'; + this._configPath = this._inner.get('configPath') || '.eslintrc'; + this._binPath = this._inner.get('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('lint.run') || 'onType'; - this._enable = this._inner.get('enable') ?? true; - this._trace = this._inner.get('trace.server') || 'off'; - this._configPath = this._inner.get('configPath') || '.eslintrc'; - this._binPath = this._inner.get('path.server'); + this.setSettingsFromWorkspace(); this.onConfigChange?.call(this, event); } }