diff --git a/editors/vscode/client/extension.ts b/editors/vscode/client/extension.ts index a61c3802a0552..25f2780307c27 100644 --- a/editors/vscode/client/extension.ts +++ b/editors/vscode/client/extension.ts @@ -331,9 +331,8 @@ function updateStatsBar( } function generateActivatorByConfig(config: VSCodeConfig, context: ExtensionContext): void { - const watcher = workspace.createFileSystemWatcher('**/.oxlintrc.json', false, true, true); + const watcher = workspace.createFileSystemWatcher('**/.oxlintrc.json', false, true, !config.requireConfig); watcher.onDidCreate(async () => { - watcher.dispose(); allowedToStartServer = true; updateStatsBar(context, config.enable); if (client && !client.isRunning() && config.enable) { @@ -341,5 +340,16 @@ function generateActivatorByConfig(config: VSCodeConfig, context: ExtensionConte } }); + watcher.onDidDelete(async () => { + // only can be called when config.requireConfig + allowedToStartServer = (await workspace.findFiles(`**/.oxlintrc.json`, '**/node_modules/**', 1)).length > 0; + if (!allowedToStartServer) { + updateStatsBar(context, false); + if (client && client.isRunning()) { + await client.stop(); + } + } + }); + context.subscriptions.push(watcher); }