Skip to content

Commit dd99b5c

Browse files
committed
feat(editor): add oxc.typeAware option for workspaces
1 parent 7be0a93 commit dd99b5c

File tree

6 files changed

+58
-2
lines changed

6 files changed

+58
-2
lines changed

editors/vscode/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Following configuration are supported via `settings.json` and can be changed for
4444
| `oxc.configPath` | `null` | `null` \| `<string>` | Path to ESlint configuration. Keep it empty to enable nested configuration. |
4545
| `oxc.tsConfigPath` | `null` | `null` \| `<string>` | Path to TypeScript configuration. If your `tsconfig.json` is not at the root, alias paths will not be resolve correctly for the `import` plugin. |
4646
| `oxc.unusedDisableDirectives` | `allow` | `allow` \| `warn` \| `deny` | Define how directive comments like `// oxlint-disable-line` should be reported, when no errors would have been reported on that line anyway. |
47+
| `oxc.typeAware` | `false` | `false` \| `true` | Enable type aware linting. |
4748
| `oxc.flags` | - | `Record<string, string>` | Custom flags passed to the language server. |
4849

4950
#### Flags

editors/vscode/client/WorkspaceConfig.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ export interface WorkspaceConfigInterface {
4444
* @default 'allow'
4545
*/
4646
unusedDisableDirectives: UnusedDisableDirectives;
47+
48+
/**
49+
* Whether to enable type-aware linting
50+
*
51+
* `oxc.typeAware`
52+
*
53+
* @default false
54+
*/
55+
typeAware: boolean;
56+
4757
/**
4858
* Additional flags to pass to the LSP binary
4959
* `oxc.flags`
@@ -58,6 +68,7 @@ export class WorkspaceConfig {
5868
private _tsConfigPath: string | null = null;
5969
private _runTrigger: Trigger = 'onType';
6070
private _unusedDisableDirectives: UnusedDisableDirectives = 'allow';
71+
private _typeAware: boolean = false;
6172
private _flags: Record<string, string> = {};
6273

6374
constructor(private readonly workspace: WorkspaceFolder) {
@@ -78,6 +89,7 @@ export class WorkspaceConfig {
7889
this._tsConfigPath = this.configuration.get<string | null>('tsConfigPath') ?? null;
7990
this._unusedDisableDirectives = this.configuration.get<UnusedDisableDirectives>('unusedDisableDirectives') ??
8091
'allow';
92+
this._typeAware = this.configuration.get<boolean>('typeAware') ?? false;
8193
this._flags = flags;
8294
}
8395

@@ -94,6 +106,9 @@ export class WorkspaceConfig {
94106
if (event.affectsConfiguration(`${ConfigService.namespace}.unusedDisableDirectives`, this.workspace)) {
95107
return true;
96108
}
109+
if (event.affectsConfiguration(`${ConfigService.namespace}.typeAware`, this.workspace)) {
110+
return true;
111+
}
97112
if (event.affectsConfiguration(`${ConfigService.namespace}.flags`, this.workspace)) {
98113
return true;
99114
}
@@ -140,6 +155,15 @@ export class WorkspaceConfig {
140155
return this.configuration.update('unusedDisableDirectives', value, ConfigurationTarget.WorkspaceFolder);
141156
}
142157

158+
get typeAware(): boolean {
159+
return this._typeAware;
160+
}
161+
162+
updateTypeAware(value: boolean): PromiseLike<void> {
163+
this._typeAware = value;
164+
return this.configuration.update('typeAware', value, ConfigurationTarget.WorkspaceFolder);
165+
}
166+
143167
get flags(): Record<string, string> {
144168
return this._flags;
145169
}
@@ -155,6 +179,7 @@ export class WorkspaceConfig {
155179
configPath: this.configPath ?? null,
156180
tsConfigPath: this.tsConfigPath ?? null,
157181
unusedDisableDirectives: this.unusedDisableDirectives,
182+
typeAware: this.typeAware,
158183
flags: this.flags,
159184
};
160185
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
async function returnsPromise() {
2+
return "value";
3+
}
4+
5+
returnsPromise().then(() => {});

editors/vscode/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@
141141
"default": "allow",
142142
"description": "Define how directive comments like `// oxlint-disable-line` should be reported, when no errors would have been reported on that line anyway."
143143
},
144+
"oxc.typeAware": {
145+
"type": "boolean",
146+
"scope": "resource",
147+
"default": false,
148+
"description": "Enable type-aware linting."
149+
},
144150
"oxc.flags": {
145151
"type": "object",
146152
"scope": "resource",

editors/vscode/tests/WorkspaceConfig.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ 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'];
7+
68
suite('WorkspaceConfig', () => {
79
setup(async () => {
810
const workspaceConfig = workspace.getConfiguration('oxc', WORKSPACE_FOLDER);
911
const globalConfig = workspace.getConfiguration('oxc');
10-
const keys = ['lint.run', 'configPath', 'tsConfigPath', 'flags', 'unusedDisableDirectives'];
12+
1113

1214
await Promise.all(keys.map(key => workspaceConfig.update(key, undefined, ConfigurationTarget.WorkspaceFolder)));
1315
// VSCode will not save different workspace configuration inside a `.code-workspace` file.
@@ -18,7 +20,6 @@ suite('WorkspaceConfig', () => {
1820
teardown(async () => {
1921
const workspaceConfig = workspace.getConfiguration('oxc', WORKSPACE_FOLDER);
2022
const globalConfig = workspace.getConfiguration('oxc');
21-
const keys = ['lint.run', 'configPath', 'tsConfigPath', 'flags', 'unusedDisableDirectives'];
2223

2324
await Promise.all(keys.map(key => workspaceConfig.update(key, undefined, ConfigurationTarget.WorkspaceFolder)));
2425
// VSCode will not save different workspace configuration inside a `.code-workspace` file.
@@ -32,6 +33,7 @@ suite('WorkspaceConfig', () => {
3233
strictEqual(config.configPath, null);
3334
strictEqual(config.tsConfigPath, null);
3435
strictEqual(config.unusedDisableDirectives, 'allow');
36+
strictEqual(config.typeAware, false);
3537
deepStrictEqual(config.flags, {});
3638
});
3739

@@ -65,6 +67,7 @@ suite('WorkspaceConfig', () => {
6567
config.updateConfigPath('./somewhere'),
6668
config.updateTsConfigPath('./tsconfig.json'),
6769
config.updateUnusedDisableDirectives('deny'),
70+
config.updateTypeAware(true),
6871
config.updateFlags({ test: 'value' }),
6972
]);
7073

@@ -74,6 +77,7 @@ suite('WorkspaceConfig', () => {
7477
strictEqual(wsConfig.get('configPath'), './somewhere');
7578
strictEqual(wsConfig.get('tsConfigPath'), './tsconfig.json');
7679
strictEqual(wsConfig.get('unusedDisableDirectives'), 'deny');
80+
strictEqual(wsConfig.get('typeAware'), true);
7781
deepStrictEqual(wsConfig.get('flags'), { test: 'value' });
7882
});
7983
});

editors/vscode/tests/e2e_server.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ suiteSetup(async () => {
3232
teardown(async () => {
3333
await workspace.getConfiguration('oxc').update('flags', undefined);
3434
await workspace.getConfiguration('oxc').update('tsConfigPath', undefined);
35+
await workspace.getConfiguration('oxc').update('typeAware', undefined);
3536
await workspace.saveAll();
3637
});
3738

@@ -237,6 +238,20 @@ suite('E2E Diagnostics', () => {
237238
strictEqual(secondDiagnostics[0].severity, DiagnosticSeverity.Error);
238239
});
239240

241+
testSingleFolderMode('changing oxc.typeAware will revalidate the tsgolint diagnostics', async () => {
242+
await loadFixture('type_aware');
243+
const firstDiagnostics = await getDiagnostics('index.ts');
244+
245+
strictEqual(firstDiagnostics.length, 0);
246+
247+
await workspace.getConfiguration('oxc').update('typeAware', true);
248+
await workspace.saveAll();
249+
await waitForDiagnosticChange();
250+
251+
const secondDiagnostics = await getDiagnostics('index.ts');
252+
assert(secondDiagnostics.length != 0);
253+
});
254+
240255
test('cross module', async () => {
241256
await loadFixture('cross_module');
242257
const diagnostics = await getDiagnostics('dep-a.ts');

0 commit comments

Comments
 (0)