From 1fb7fc0de7905852befbd0a72cae3818c20d9247 Mon Sep 17 00:00:00 2001
From: Sysix <sysix@sysix-coding.de>
Date: Wed, 20 Nov 2024 16:48:08 +0100
Subject: [PATCH 1/5] refactor(vscode): split `ConfigService` and `Config`

---
 .../vscode/client/{config.ts => Config.ts}    | 65 +++++++------------
 editors/vscode/client/ConfigService.ts        | 37 +++++++++++
 editors/vscode/client/config.spec.ts          | 14 ++--
 editors/vscode/client/extension.ts            | 18 ++---
 4 files changed, 75 insertions(+), 59 deletions(-)
 rename editors/vscode/client/{config.ts => Config.ts} (55%)
 create mode 100644 editors/vscode/client/ConfigService.ts

diff --git a/editors/vscode/client/config.ts b/editors/vscode/client/Config.ts
similarity index 55%
rename from editors/vscode/client/config.ts
rename to editors/vscode/client/Config.ts
index d2eabe94ec753..e9cf661ee3bb0 100644
--- a/editors/vscode/client/config.ts
+++ b/editors/vscode/client/Config.ts
@@ -1,38 +1,31 @@
-import { ConfigurationChangeEvent, workspace, WorkspaceConfiguration } from 'vscode';
+import { workspace } from 'vscode';
 import { IDisposable } from './types';
 
-export class ConfigService implements Config, IDisposable {
+export class Config implements ConfigInterface, 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 _binPath: string | undefined;
 
-  public onConfigChange:
-    | ((this: ConfigService, config: ConfigurationChangeEvent) => void)
-    | undefined;
-
   constructor() {
-    this.setSettingsFromWorkspace();
-    this.onConfigChange = undefined;
+    this.refresh();
+  }
 
-    const disposeChangeListener = workspace.onDidChangeConfiguration(
-      this.onVscodeConfigChange.bind(this),
-    );
-    this._disposables.push(disposeChangeListener);
+  dispose(): void | Promise<void> {
+    throw new Error('Method not implemented.');
   }
 
-  private setSettingsFromWorkspace(): void {
-    this._inner = workspace.getConfiguration(ConfigService._namespace);
+  public refresh(): void {
+    const conf = workspace.getConfiguration(Config._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._runTrigger = conf.get<Trigger>('lint.run') || 'onType';
+    this._enable = conf.get<boolean>('enable') ?? true;
+    this._trace = conf.get<TraceLevel>('trace.server') || 'off';
+    this._configPath = conf.get<string>('configPath') || '.eslintrc';
+    this._binPath = conf.get<string>('path.server');
   }
 
   get runTrigger(): Trigger {
@@ -42,7 +35,7 @@ export class ConfigService implements Config, IDisposable {
   set runTrigger(value: Trigger) {
     this._runTrigger = value;
     workspace
-      .getConfiguration(ConfigService._namespace)
+      .getConfiguration(Config._namespace)
       .update('lint.run', value);
   }
 
@@ -53,7 +46,7 @@ export class ConfigService implements Config, IDisposable {
   set enable(value: boolean) {
     this._enable = value;
     workspace
-      .getConfiguration(ConfigService._namespace)
+      .getConfiguration(Config._namespace)
       .update('enable', value);
   }
 
@@ -64,7 +57,7 @@ export class ConfigService implements Config, IDisposable {
   set trace(value: TraceLevel) {
     this._trace = value;
     workspace
-      .getConfiguration(ConfigService._namespace)
+      .getConfiguration(Config._namespace)
       .update('trace.server', value);
   }
 
@@ -75,7 +68,7 @@ export class ConfigService implements Config, IDisposable {
   set configPath(value: string) {
     this._configPath = value;
     workspace
-      .getConfiguration(ConfigService._namespace)
+      .getConfiguration(Config._namespace)
       .update('configPath', value);
   }
 
@@ -86,23 +79,10 @@ export class ConfigService implements Config, IDisposable {
   set binPath(value: string | undefined) {
     this._binPath = value;
     workspace
-      .getConfiguration(ConfigService._namespace)
+      .getConfiguration(Config._namespace)
       .update('path.server', value);
   }
 
-  private onVscodeConfigChange(event: ConfigurationChangeEvent): void {
-    if (event.affectsConfiguration(ConfigService._namespace)) {
-      this.setSettingsFromWorkspace();
-      this.onConfigChange?.call(this, event);
-    }
-  }
-
-  dispose() {
-    for (const disposable of this._disposables) {
-      disposable.dispose();
-    }
-  }
-
   public toLanguageServerConfig(): LanguageServerConfig {
     return {
       run: this.runTrigger,
@@ -112,19 +92,18 @@ export class ConfigService implements Config, IDisposable {
   }
 }
 
-type Trigger = 'onSave' | 'onType';
-type TraceLevel = 'off' | 'messages' | 'verbose';
-
 interface LanguageServerConfig {
   configPath: string;
   enable: boolean;
   run: Trigger;
 }
 
+export type Trigger = 'onSave' | 'onType';
+type TraceLevel = 'off' | 'messages' | 'verbose';
 /**
  * See `"contributes.configuration"` in `package.json`
  */
-interface Config {
+interface ConfigInterface {
   /**
    * When to run the linter and generate diagnostics
    * `oxc.lint.run`
diff --git a/editors/vscode/client/ConfigService.ts b/editors/vscode/client/ConfigService.ts
new file mode 100644
index 0000000000000..801cdb106348d
--- /dev/null
+++ b/editors/vscode/client/ConfigService.ts
@@ -0,0 +1,37 @@
+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();
+    }
+  }
+}
diff --git a/editors/vscode/client/config.spec.ts b/editors/vscode/client/config.spec.ts
index 5b71a5f6537c3..f61f0c9bf017d 100644
--- a/editors/vscode/client/config.spec.ts
+++ b/editors/vscode/client/config.spec.ts
@@ -1,12 +1,12 @@
 import { strictEqual } from 'assert';
-import { ConfigService } from './config.js';
+import { Config } from './Config.js';
 
 suite('default values on initialization', () => {
-  const service = new ConfigService();
+  const config = new Config();
 
-  strictEqual(service.runTrigger, 'onType');
-  strictEqual(service.enable, true);
-  strictEqual(service.trace, 'off');
-  strictEqual(service.configPath, '.eslintrc');
-  strictEqual(service.binPath, '');
+  strictEqual(config.runTrigger, 'onType');
+  strictEqual(config.enable, true);
+  strictEqual(config.trace, 'off');
+  strictEqual(config.configPath, '.eslintrc');
+  strictEqual(config.binPath, '');
 });
diff --git a/editors/vscode/client/extension.ts b/editors/vscode/client/extension.ts
index 53a47dd1e4afc..8d5223494a8f7 100644
--- a/editors/vscode/client/extension.ts
+++ b/editors/vscode/client/extension.ts
@@ -7,7 +7,7 @@ import { MessageType, ShowMessageNotification } from 'vscode-languageclient';
 import { Executable, LanguageClient, LanguageClientOptions, ServerOptions } from 'vscode-languageclient/node';
 
 import { join } from 'node:path';
-import { ConfigService } from './config';
+import { ConfigService } from './ConfigService';
 
 const languageClientName = 'oxc';
 const outputChannelName = 'Oxc';
@@ -25,7 +25,7 @@ let client: LanguageClient;
 let myStatusBarItem: StatusBarItem;
 
 export async function activate(context: ExtensionContext) {
-  const config = new ConfigService();
+  const configService = new ConfigService();
   const restartCommand = commands.registerCommand(
     OxcCommands.RestartServer,
     async () => {
@@ -58,7 +58,7 @@ export async function activate(context: ExtensionContext) {
   const toggleEnable = commands.registerCommand(
     OxcCommands.ToggleEnable,
     () => {
-      config.enable = !config.enable;
+      configService.config.enable = !configService.config.enable;
     },
   );
 
@@ -66,13 +66,13 @@ export async function activate(context: ExtensionContext) {
     restartCommand,
     showOutputCommand,
     toggleEnable,
-    config,
+    configService,
   );
 
   const outputChannel = window.createOutputChannel(outputChannelName, { log: true });
 
   async function findBinary(): Promise<string> {
-    let bin = config.binPath;
+    let bin = configService.config.binPath;
     if (bin) {
       try {
         await fsPromises.access(bin);
@@ -148,7 +148,7 @@ export async function activate(context: ExtensionContext) {
       ],
     },
     initializationOptions: {
-      settings: config.toLanguageServerConfig(),
+      settings: configService.config.toLanguageServerConfig(),
     },
     outputChannel,
     traceOutputChannel: outputChannel,
@@ -188,8 +188,8 @@ export async function activate(context: ExtensionContext) {
     });
   });
 
-  config.onConfigChange = function onConfigChange() {
-    let settings = this.toLanguageServerConfig();
+  configService.onConfigChange = function onConfigChange() {
+    let settings = this.config.toLanguageServerConfig();
     updateStatsBar(settings.enable);
     client.sendNotification('workspace/didChangeConfiguration', { settings });
   };
@@ -213,7 +213,7 @@ export async function activate(context: ExtensionContext) {
 
     myStatusBarItem.backgroundColor = bgColor;
   }
-  updateStatsBar(config.enable);
+  updateStatsBar(configService.config.enable);
   client.start();
 }
 

From ea7318628e7a860aa6c9971e557d984b4b4a112c Mon Sep 17 00:00:00 2001
From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com>
Date: Wed, 20 Nov 2024 15:49:34 +0000
Subject: [PATCH 2/5] [autofix.ci] apply automated fixes

---
 editors/vscode/client/ConfigService.ts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/editors/vscode/client/ConfigService.ts b/editors/vscode/client/ConfigService.ts
index 801cdb106348d..7d84f09708085 100644
--- a/editors/vscode/client/ConfigService.ts
+++ b/editors/vscode/client/ConfigService.ts
@@ -5,7 +5,7 @@ import { IDisposable } from './types';
 export class ConfigService implements IDisposable {
   private static readonly _namespace = 'oxc';
   private readonly _disposables: IDisposable[] = [];
-  
+
   public config: Config;
 
   public onConfigChange:

From 94f5275350de9f6e8fa87fc5c4afa8dc017462ac Mon Sep 17 00:00:00 2001
From: Sysix <sysix@sysix-coding.de>
Date: Wed, 20 Nov 2024 17:21:26 +0100
Subject: [PATCH 3/5] refactor(vscode): split ConfigService and Config

---
 editors/vscode/client/Config.ts | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/editors/vscode/client/Config.ts b/editors/vscode/client/Config.ts
index e9cf661ee3bb0..2f19fdf75ac20 100644
--- a/editors/vscode/client/Config.ts
+++ b/editors/vscode/client/Config.ts
@@ -1,7 +1,6 @@
 import { workspace } from 'vscode';
-import { IDisposable } from './types';
 
-export class Config implements ConfigInterface, IDisposable {
+export class Config implements ConfigInterface {
   private static readonly _namespace = 'oxc';
 
   private _runTrigger!: Trigger;
@@ -14,10 +13,6 @@ export class Config implements ConfigInterface, IDisposable {
     this.refresh();
   }
 
-  dispose(): void | Promise<void> {
-    throw new Error('Method not implemented.');
-  }
-
   public refresh(): void {
     const conf = workspace.getConfiguration(Config._namespace);
 

From 878e7703ef1131d3456e2dcc200e1984bd5c8b9f Mon Sep 17 00:00:00 2001
From: Sysix <sysix@sysix-coding.de>
Date: Wed, 20 Nov 2024 20:13:08 +0100
Subject: [PATCH 4/5] refactor(vscode): split ConfigService and Config

---
 editors/vscode/client/config.spec.ts | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/editors/vscode/client/config.spec.ts b/editors/vscode/client/config.spec.ts
index f61f0c9bf017d..c2a44e8207ae7 100644
--- a/editors/vscode/client/config.spec.ts
+++ b/editors/vscode/client/config.spec.ts
@@ -1,12 +1,16 @@
 import { strictEqual } from 'assert';
 import { Config } from './Config.js';
 
-suite('default values on initialization', () => {
-  const config = new Config();
+suite('Config', () => {
 
-  strictEqual(config.runTrigger, 'onType');
-  strictEqual(config.enable, true);
-  strictEqual(config.trace, 'off');
-  strictEqual(config.configPath, '.eslintrc');
-  strictEqual(config.binPath, '');
-});
+  test('default values on initialization', () => {
+    const config = new Config();
+  
+    strictEqual(config.runTrigger, 'onType');
+    strictEqual(config.enable, true);
+    strictEqual(config.trace, 'off');
+    strictEqual(config.configPath, '.eslintrc');
+    strictEqual(config.binPath, '');
+  });
+  
+})
\ No newline at end of file

From e62b2deba0ca16b4a84bedcca2b4ce6b6c009120 Mon Sep 17 00:00:00 2001
From: Sysix <sysix@sysix-coding.de>
Date: Wed, 20 Nov 2024 20:14:35 +0100
Subject: [PATCH 5/5] refactor(vscode): split ConfigService and Config

---
 editors/vscode/client/config.spec.ts | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/editors/vscode/client/config.spec.ts b/editors/vscode/client/config.spec.ts
index c2a44e8207ae7..b2c97b22f4683 100644
--- a/editors/vscode/client/config.spec.ts
+++ b/editors/vscode/client/config.spec.ts
@@ -2,15 +2,13 @@ import { strictEqual } from 'assert';
 import { Config } from './Config.js';
 
 suite('Config', () => {
-
   test('default values on initialization', () => {
     const config = new Config();
-  
+
     strictEqual(config.runTrigger, 'onType');
     strictEqual(config.enable, true);
     strictEqual(config.trace, 'off');
     strictEqual(config.configPath, '.eslintrc');
     strictEqual(config.binPath, '');
   });
-  
-})
\ No newline at end of file
+});