@@ -3,7 +3,6 @@ import { promises as fsPromises } from 'node:fs';
33import {
44 commands ,
55 ExtensionContext ,
6- FileSystemWatcher ,
76 StatusBarAlignment ,
87 StatusBarItem ,
98 ThemeColor ,
@@ -23,7 +22,6 @@ import { Executable, LanguageClient, LanguageClientOptions, ServerOptions } from
2322
2423import { join } from 'node:path' ;
2524import { ConfigService } from './ConfigService' ;
26- import { oxlintConfigFileName } from './WorkspaceConfig' ;
2725
2826const languageClientName = 'oxc' ;
2927const outputChannelName = 'Oxc' ;
@@ -44,8 +42,6 @@ let client: LanguageClient | undefined;
4442
4543let myStatusBarItem : StatusBarItem ;
4644
47- const globalWatchers : FileSystemWatcher [ ] = [ ] ;
48-
4945export async function activate ( context : ExtensionContext ) {
5046 const configService = new ConfigService ( ) ;
5147 const restartCommand = commands . registerCommand (
@@ -122,7 +118,6 @@ export async function activate(context: ExtensionContext) {
122118 ) ;
123119
124120 const outputChannel = window . createOutputChannel ( outputChannelName , { log : true } ) ;
125- const fileWatchers = createFileEventWatchers ( configService . getOxlintCustomConfigs ( ) ) ;
126121
127122 context . subscriptions . push (
128123 applyAllFixesFile ,
@@ -131,11 +126,6 @@ export async function activate(context: ExtensionContext) {
131126 toggleEnable ,
132127 configService ,
133128 outputChannel ,
134- {
135- dispose : ( ) => {
136- globalWatchers . forEach ( ( watcher ) => watcher . dispose ( ) ) ;
137- } ,
138- } ,
139129 ) ;
140130
141131 async function findBinary ( ) : Promise < string > {
@@ -209,10 +199,6 @@ export async function activate(context: ExtensionContext) {
209199 language : lang ,
210200 scheme : 'file' ,
211201 } ) ) ,
212- synchronize : {
213- // Notify the server about file config changes in the workspace
214- fileEvents : fileWatchers ,
215- } ,
216202 initializationOptions : configService . languageServerConfig ,
217203 outputChannel,
218204 traceOutputChannel : outputChannel ,
@@ -294,13 +280,9 @@ export async function activate(context: ExtensionContext) {
294280 return ;
295281 }
296282
297- if ( needRestart ) {
298- client . clientOptions . synchronize = client . clientOptions . synchronize ?? { } ;
299- client . clientOptions . synchronize . fileEvents = createFileEventWatchers ( configService . getOxlintCustomConfigs ( ) ) ;
300-
301- if ( client . isRunning ( ) ) {
302- await client . restart ( ) ;
303- }
283+ // Server does not support currently adding/removing watchers on the fly
284+ if ( needRestart && client . isRunning ( ) ) {
285+ await client . restart ( ) ;
304286 }
305287 } ) ;
306288
@@ -317,9 +299,7 @@ export async function activate(context: ExtensionContext) {
317299 client . clientOptions . initializationOptions = this . languageServerConfig ;
318300
319301 if ( configService . effectsWorkspaceConfigPathChange ( event ) ) {
320- client . clientOptions . synchronize = client . clientOptions . synchronize ?? { } ;
321- client . clientOptions . synchronize . fileEvents = createFileEventWatchers ( this . getOxlintCustomConfigs ( ) ) ;
322-
302+ // Server does not support currently adding/removing watchers on the fly
323303 if ( client . isRunning ( ) ) {
324304 await client . restart ( ) ;
325305 }
@@ -366,23 +346,3 @@ export async function deactivate(): Promise<void> {
366346 await client . stop ( ) ;
367347 client = undefined ;
368348}
369-
370- // FileSystemWatcher are not ready on the start and can take some seconds on bigger repositories
371- function createFileEventWatchers ( configAbsolutePaths : string [ ] ) : FileSystemWatcher [ ] {
372- // cleanup old watchers
373- globalWatchers . forEach ( ( watcher ) => watcher . dispose ( ) ) ;
374- globalWatchers . length = 0 ;
375-
376- // create new watchers
377- let localWatchers : FileSystemWatcher [ ] = [ ] ;
378- if ( configAbsolutePaths . length ) {
379- localWatchers = configAbsolutePaths . map ( ( path ) => workspace . createFileSystemWatcher ( path ) ) ;
380- }
381-
382- localWatchers . push ( workspace . createFileSystemWatcher ( `**/${ oxlintConfigFileName } ` ) ) ;
383-
384- // assign watchers to global variable, so we can cleanup them on next call
385- globalWatchers . push ( ...localWatchers ) ;
386-
387- return localWatchers ;
388- }
0 commit comments