Skip to content

Commit 70bbf07

Browse files
committed
feat(editor): add oxc.fmt.experimental flag
1 parent c1e00fd commit 70bbf07

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

editors/vscode/client/WorkspaceConfig.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ export interface WorkspaceConfigInterface {
6161
* @default {}
6262
*/
6363
flags: Record<string, string>;
64+
65+
/**
66+
* Enable formatting experiment
67+
* `oxc.fmt.experimental`
68+
*
69+
* @default false
70+
*/
71+
['fmt.experimental']: boolean;
6472
}
6573

6674
export class WorkspaceConfig {
@@ -70,6 +78,7 @@ export class WorkspaceConfig {
7078
private _unusedDisableDirectives: UnusedDisableDirectives = 'allow';
7179
private _typeAware: boolean = false;
7280
private _flags: Record<string, string> = {};
81+
private _formattingExperimental: boolean = false;
7382

7483
constructor(private readonly workspace: WorkspaceFolder) {
7584
this.refresh();
@@ -91,6 +100,7 @@ export class WorkspaceConfig {
91100
'allow';
92101
this._typeAware = this.configuration.get<boolean>('typeAware') ?? false;
93102
this._flags = flags;
103+
this._formattingExperimental = this.configuration.get<boolean>('fmt.experimental') ?? false;
94104
}
95105

96106
public effectsConfigChange(event: ConfigurationChangeEvent): boolean {
@@ -112,6 +122,9 @@ export class WorkspaceConfig {
112122
if (event.affectsConfiguration(`${ConfigService.namespace}.flags`, this.workspace)) {
113123
return true;
114124
}
125+
if (event.affectsConfiguration(`${ConfigService.namespace}.fmt.experimental`, this.workspace)) {
126+
return true;
127+
}
115128
return false;
116129
}
117130

@@ -173,6 +186,15 @@ export class WorkspaceConfig {
173186
return this.configuration.update('flags', value, ConfigurationTarget.WorkspaceFolder);
174187
}
175188

189+
get formattingExperimental(): boolean {
190+
return this._formattingExperimental;
191+
}
192+
193+
updateFormattingExperimental(value: boolean): PromiseLike<void> {
194+
this._formattingExperimental = value;
195+
return this.configuration.update('fmt.experimental', value, ConfigurationTarget.WorkspaceFolder);
196+
}
197+
176198
public toLanguageServerConfig(): WorkspaceConfigInterface {
177199
return {
178200
run: this.runTrigger,
@@ -181,6 +203,7 @@ export class WorkspaceConfig {
181203
unusedDisableDirectives: this.unusedDisableDirectives,
182204
typeAware: this.typeAware,
183205
flags: this.flags,
206+
['fmt.experimental']: this.formattingExperimental,
184207
};
185208
}
186209
}

editors/vscode/tests/WorkspaceConfig.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ConfigurationTarget, workspace } from 'vscode';
33
import { WorkspaceConfig } from '../client/WorkspaceConfig.js';
44
import { WORKSPACE_FOLDER } from './test-helpers.js';
55

6-
const keys = ['lint.run', 'configPath', 'tsConfigPath', 'flags', 'unusedDisableDirectives', 'typeAware'];
6+
const keys = ['lint.run', 'configPath', 'tsConfigPath', 'flags', 'unusedDisableDirectives', 'typeAware', 'fmt.experimental'];
77

88
suite('WorkspaceConfig', () => {
99
setup(async () => {
@@ -35,6 +35,7 @@ suite('WorkspaceConfig', () => {
3535
strictEqual(config.unusedDisableDirectives, 'allow');
3636
strictEqual(config.typeAware, false);
3737
deepStrictEqual(config.flags, {});
38+
strictEqual(config.formattingExperimental, false);
3839
});
3940

4041
test('configPath defaults to null when using nested configs and configPath is empty', async () => {
@@ -69,6 +70,7 @@ suite('WorkspaceConfig', () => {
6970
config.updateUnusedDisableDirectives('deny'),
7071
config.updateTypeAware(true),
7172
config.updateFlags({ test: 'value' }),
73+
config.updateFormattingExperimental(true),
7274
]);
7375

7476
const wsConfig = workspace.getConfiguration('oxc', WORKSPACE_FOLDER);
@@ -79,5 +81,6 @@ suite('WorkspaceConfig', () => {
7981
strictEqual(wsConfig.get('unusedDisableDirectives'), 'deny');
8082
strictEqual(wsConfig.get('typeAware'), true);
8183
deepStrictEqual(wsConfig.get('flags'), { test: 'value' });
84+
strictEqual(wsConfig.get('fmt.experimental'), true);
8285
});
8386
});

0 commit comments

Comments
 (0)