Skip to content

Commit 27d6e9b

Browse files
authoredMar 13, 2025··
feat(editor): Only watch .oxlintrc.json or user supplied config paths (#9731)
This works by detecting if the user changes the config setting and restarting the language client to pick up the new watchers.
1 parent 9df5565 commit 27d6e9b

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed
 

‎editors/vscode/client/Config.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { workspace } from 'vscode';
22

3+
export const oxlintConfigFileName = '.oxlintrc.json';
4+
35
export class Config implements ConfigInterface {
46
private static readonly _namespace = 'oxc';
57

@@ -19,7 +21,7 @@ export class Config implements ConfigInterface {
1921
this._runTrigger = conf.get<Trigger>('lint.run') || 'onType';
2022
this._enable = conf.get<boolean>('enable') ?? true;
2123
this._trace = conf.get<TraceLevel>('trace.server') || 'off';
22-
this._configPath = conf.get<string>('configPath') || '.oxlintrc.json';
24+
this._configPath = conf.get<string>('configPath') || oxlintConfigFileName;
2325
this._binPath = conf.get<string>('path.server');
2426
}
2527

‎editors/vscode/client/extension.ts

+32-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
import { promises as fsPromises } from 'node:fs';
22

3-
import { commands, ExtensionContext, StatusBarAlignment, StatusBarItem, ThemeColor, window, workspace } from 'vscode';
3+
import {
4+
commands,
5+
ExtensionContext,
6+
RelativePattern,
7+
StatusBarAlignment,
8+
StatusBarItem,
9+
ThemeColor,
10+
window,
11+
workspace,
12+
} from 'vscode';
413

514
import { ExecuteCommandRequest, MessageType, ShowMessageNotification } from 'vscode-languageclient';
615

716
import { Executable, LanguageClient, LanguageClientOptions, ServerOptions } from 'vscode-languageclient/node';
817

918
import { join } from 'node:path';
19+
import { oxlintConfigFileName } from './Config';
1020
import { ConfigService } from './ConfigService';
1121

1222
const languageClientName = 'oxc';
@@ -170,10 +180,7 @@ export async function activate(context: ExtensionContext) {
170180
})),
171181
synchronize: {
172182
// Notify the server about file config changes in the workspace
173-
fileEvents: [
174-
workspace.createFileSystemWatcher('**/.oxlint{.json,rc.json}'),
175-
workspace.createFileSystemWatcher('**/oxlint{.json,rc.json}'),
176-
],
183+
fileEvents: createFileEventWatchers(configService.config.configPath),
177184
},
178185
initializationOptions: {
179186
settings: configService.config.toLanguageServerConfig(),
@@ -216,10 +223,16 @@ export async function activate(context: ExtensionContext) {
216223
});
217224
});
218225

219-
configService.onConfigChange = function onConfigChange() {
226+
configService.onConfigChange = function onConfigChange(event) {
220227
let settings = this.config.toLanguageServerConfig();
221228
updateStatsBar(settings.enable);
222229
client.sendNotification('workspace/didChangeConfiguration', { settings });
230+
231+
if (event.affectsConfiguration('oxc.configPath')) {
232+
client.clientOptions.synchronize = client.clientOptions.synchronize ?? {};
233+
client.clientOptions.synchronize.fileEvents = createFileEventWatchers(configService.config.configPath);
234+
client.restart();
235+
}
223236
};
224237

225238
function updateStatsBar(enable: boolean) {
@@ -251,3 +264,16 @@ export function deactivate(): Thenable<void> | undefined {
251264
}
252265
return client.stop();
253266
}
267+
268+
function createFileEventWatchers(configRelativePath: string) {
269+
const workspaceConfigPatterns = (workspace.workspaceFolders || []).map((workspaceFolder) =>
270+
new RelativePattern(workspaceFolder, configRelativePath)
271+
);
272+
273+
return [
274+
workspace.createFileSystemWatcher(`**/${oxlintConfigFileName}`),
275+
...workspaceConfigPatterns.map((pattern) => {
276+
return workspace.createFileSystemWatcher(pattern);
277+
}),
278+
];
279+
}

0 commit comments

Comments
 (0)
Please sign in to comment.