|
1 | 1 | import { promises as fsPromises } from 'node:fs';
|
2 | 2 |
|
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'; |
4 | 13 |
|
5 | 14 | import { ExecuteCommandRequest, MessageType, ShowMessageNotification } from 'vscode-languageclient';
|
6 | 15 |
|
7 | 16 | import { Executable, LanguageClient, LanguageClientOptions, ServerOptions } from 'vscode-languageclient/node';
|
8 | 17 |
|
9 | 18 | import { join } from 'node:path';
|
| 19 | +import { oxlintConfigFileName } from './Config'; |
10 | 20 | import { ConfigService } from './ConfigService';
|
11 | 21 |
|
12 | 22 | const languageClientName = 'oxc';
|
@@ -170,10 +180,7 @@ export async function activate(context: ExtensionContext) {
|
170 | 180 | })),
|
171 | 181 | synchronize: {
|
172 | 182 | // 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), |
177 | 184 | },
|
178 | 185 | initializationOptions: {
|
179 | 186 | settings: configService.config.toLanguageServerConfig(),
|
@@ -216,10 +223,16 @@ export async function activate(context: ExtensionContext) {
|
216 | 223 | });
|
217 | 224 | });
|
218 | 225 |
|
219 |
| - configService.onConfigChange = function onConfigChange() { |
| 226 | + configService.onConfigChange = function onConfigChange(event) { |
220 | 227 | let settings = this.config.toLanguageServerConfig();
|
221 | 228 | updateStatsBar(settings.enable);
|
222 | 229 | 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 | + } |
223 | 236 | };
|
224 | 237 |
|
225 | 238 | function updateStatsBar(enable: boolean) {
|
@@ -251,3 +264,16 @@ export function deactivate(): Thenable<void> | undefined {
|
251 | 264 | }
|
252 | 265 | return client.stop();
|
253 | 266 | }
|
| 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