From 985d48f6c848ffa16bed111ed1f23210abe687a7 Mon Sep 17 00:00:00 2001 From: Sysix <3897725+Sysix@users.noreply.github.com> Date: Tue, 18 Nov 2025 12:19:49 +0000 Subject: [PATCH] refactor(vscode): add `WorkspaceConfig` methods for different lsp tools (#15788) In the future, the VSCode extension will call 2 language servers. Added a method to get different LSP configs for the different tools. --- editors/vscode/client/WorkspaceConfig.ts | 16 ++++- editors/vscode/tests/WorkspaceConfig.spec.ts | 68 ++++++++++++++++++++ 2 files changed, 82 insertions(+), 2 deletions(-) diff --git a/editors/vscode/client/WorkspaceConfig.ts b/editors/vscode/client/WorkspaceConfig.ts index c2e6bf4310c29..c7e12effe768b 100644 --- a/editors/vscode/client/WorkspaceConfig.ts +++ b/editors/vscode/client/WorkspaceConfig.ts @@ -268,6 +268,13 @@ export class WorkspaceConfig { } public toLanguageServerConfig(): WorkspaceConfigInterface { + return { + ...this.toOxlintConfig(), + ...this.toOxfmtConfig(), + }; + } + + public toOxlintConfig(): Omit { return { run: this.runTrigger, configPath: this.configPath ?? null, @@ -276,8 +283,6 @@ export class WorkspaceConfig { typeAware: this.typeAware, disableNestedConfig: this.disableNestedConfig, fixKind: this.fixKind, - ['fmt.experimental']: this.formattingExperimental, - ['fmt.configPath']: this.formattingConfigPath ?? null, // deprecated, kept for backward compatibility flags: { disable_nested_config: this.disableNestedConfig ? 'true' : 'false', @@ -285,4 +290,11 @@ export class WorkspaceConfig { }, }; } + + public toOxfmtConfig(): Pick { + return { + ['fmt.experimental']: this.formattingExperimental, + ['fmt.configPath']: this.formattingConfigPath ?? null, + }; + } } diff --git a/editors/vscode/tests/WorkspaceConfig.spec.ts b/editors/vscode/tests/WorkspaceConfig.spec.ts index 6919c1a12cd58..d8a069d6ca35b 100644 --- a/editors/vscode/tests/WorkspaceConfig.spec.ts +++ b/editors/vscode/tests/WorkspaceConfig.spec.ts @@ -90,4 +90,72 @@ suite('WorkspaceConfig', () => { strictEqual(wsConfig.get('fmt.experimental'), true); strictEqual(wsConfig.get('fmt.configPath'), './oxfmt.json'); }); + + test('toLanguageServerConfig method', async () => { + const config = new WorkspaceConfig(WORKSPACE_FOLDER); + + await Promise.all([ + config.updateRunTrigger('onSave'), + config.updateConfigPath('./somewhere'), + config.updateTsConfigPath('./tsconfig.json'), + config.updateUnusedDisableDirectives('deny'), + config.updateTypeAware(true), + config.updateDisableNestedConfig(true), + config.updateFixKind(FixKind.DangerousFix), + config.updateFormattingExperimental(true), + config.updateFormattingConfigPath('./oxfmt.json'), + ]); + + const lsConfig = config.toLanguageServerConfig(); + + strictEqual(lsConfig.run, 'onSave'); + strictEqual(lsConfig.configPath, './somewhere'); + strictEqual(lsConfig.tsConfigPath, './tsconfig.json'); + strictEqual(lsConfig.unusedDisableDirectives, 'deny'); + strictEqual(lsConfig.typeAware, true); + strictEqual(lsConfig.disableNestedConfig, true); + strictEqual(lsConfig.fixKind, 'dangerous_fix'); + strictEqual(lsConfig['fmt.experimental'], true); + strictEqual(lsConfig['fmt.configPath'], './oxfmt.json'); + }); + + test('toOxlintConfig method', async () => { + const config = new WorkspaceConfig(WORKSPACE_FOLDER); + + await Promise.all([ + config.updateRunTrigger('onSave'), + config.updateConfigPath('./somewhere'), + config.updateTsConfigPath('./tsconfig.json'), + config.updateUnusedDisableDirectives('deny'), + config.updateTypeAware(true), + config.updateDisableNestedConfig(true), + config.updateFixKind(FixKind.DangerousFix), + config.updateFormattingExperimental(true), + config.updateFormattingConfigPath('./oxfmt.json'), + ]); + + const oxlintConfig = config.toOxlintConfig(); + + strictEqual(oxlintConfig.run, 'onSave'); + strictEqual(oxlintConfig.configPath, './somewhere'); + strictEqual(oxlintConfig.tsConfigPath, './tsconfig.json'); + strictEqual(oxlintConfig.unusedDisableDirectives, 'deny'); + strictEqual(oxlintConfig.typeAware, true); + strictEqual(oxlintConfig.disableNestedConfig, true); + strictEqual(oxlintConfig.fixKind, 'dangerous_fix'); + }); + + test('toOxfmtConfig method', async () => { + const config = new WorkspaceConfig(WORKSPACE_FOLDER); + + await Promise.all([ + config.updateFormattingExperimental(true), + config.updateFormattingConfigPath('./oxfmt.json'), + ]); + + const oxfmtConfig = config.toOxfmtConfig(); + + strictEqual(oxfmtConfig['fmt.experimental'], true); + strictEqual(oxfmtConfig['fmt.configPath'], './oxfmt.json'); + }); });