diff --git a/editors/vscode/.vscode-test.mjs b/editors/vscode/.vscode-test.mjs index 40edc76ef..44f1d6165 100644 --- a/editors/vscode/.vscode-test.mjs +++ b/editors/vscode/.vscode-test.mjs @@ -2,4 +2,5 @@ import { defineConfig } from '@vscode/test-cli'; export default defineConfig({ files: 'out/**/*.spec.js', + workspaceFolder: './test_workspace', }); diff --git a/editors/vscode/client/Config.ts b/editors/vscode/client/Config.ts index 2f19fdf75..a53e8126c 100644 --- a/editors/vscode/client/Config.ts +++ b/editors/vscode/client/Config.ts @@ -27,9 +27,9 @@ export class Config implements ConfigInterface { return this._runTrigger; } - set runTrigger(value: Trigger) { + updateRunTrigger(value: Trigger): PromiseLike { this._runTrigger = value; - workspace + return workspace .getConfiguration(Config._namespace) .update('lint.run', value); } @@ -38,9 +38,9 @@ export class Config implements ConfigInterface { return this._enable; } - set enable(value: boolean) { + updateEnable(value: boolean): PromiseLike { this._enable = value; - workspace + return workspace .getConfiguration(Config._namespace) .update('enable', value); } @@ -49,9 +49,9 @@ export class Config implements ConfigInterface { return this._trace; } - set trace(value: TraceLevel) { + updateTrace(value: TraceLevel): PromiseLike { this._trace = value; - workspace + return workspace .getConfiguration(Config._namespace) .update('trace.server', value); } @@ -60,9 +60,9 @@ export class Config implements ConfigInterface { return this._configPath; } - set configPath(value: string) { + updateConfigPath(value: string): PromiseLike { this._configPath = value; - workspace + return workspace .getConfiguration(Config._namespace) .update('configPath', value); } @@ -71,9 +71,9 @@ export class Config implements ConfigInterface { return this._binPath; } - set binPath(value: string | undefined) { + updateBinPath(value: string | undefined): PromiseLike { this._binPath = value; - workspace + return workspace .getConfiguration(Config._namespace) .update('path.server', value); } diff --git a/editors/vscode/client/config.spec.ts b/editors/vscode/client/config.spec.ts index b2c97b22f..266bf4491 100644 --- a/editors/vscode/client/config.spec.ts +++ b/editors/vscode/client/config.spec.ts @@ -1,7 +1,15 @@ import { strictEqual } from 'assert'; +import { workspace } from 'vscode'; import { Config } from './Config.js'; suite('Config', () => { + setup(async () => { + const wsConfig = workspace.getConfiguration('oxc'); + const keys = ['lint.run', 'enable', 'trace.server', 'configPath', 'path.server']; + + await Promise.all(keys.map(key => wsConfig.update(key, undefined))); + }); + test('default values on initialization', () => { const config = new Config(); @@ -11,4 +19,24 @@ suite('Config', () => { strictEqual(config.configPath, '.eslintrc'); strictEqual(config.binPath, ''); }); + + test('updating values updates the workspace configuration', async () => { + const config = new Config(); + + await Promise.all([ + config.updateRunTrigger('onSave'), + config.updateEnable(false), + config.updateTrace('messages'), + config.updateConfigPath('./somewhere'), + config.updateBinPath('./binary'), + ]); + + const wsConfig = workspace.getConfiguration('oxc'); + + strictEqual(wsConfig.get('lint.run'), 'onSave'); + strictEqual(wsConfig.get('enable'), false); + strictEqual(wsConfig.get('trace.server'), 'messages'); + strictEqual(wsConfig.get('configPath'), './somewhere'); + strictEqual(wsConfig.get('path.server'), './binary'); + }); }); diff --git a/editors/vscode/client/extension.ts b/editors/vscode/client/extension.ts index 8d5223494..d8417b081 100644 --- a/editors/vscode/client/extension.ts +++ b/editors/vscode/client/extension.ts @@ -58,7 +58,7 @@ export async function activate(context: ExtensionContext) { const toggleEnable = commands.registerCommand( OxcCommands.ToggleEnable, () => { - configService.config.enable = !configService.config.enable; + configService.config.updateEnable(!configService.config.enable); }, ); diff --git a/editors/vscode/test_workspace/.gitignore b/editors/vscode/test_workspace/.gitignore new file mode 100644 index 000000000..d29675e53 --- /dev/null +++ b/editors/vscode/test_workspace/.gitignore @@ -0,0 +1,2 @@ +** +!.gitignore \ No newline at end of file