diff --git a/packages/filesystem/src/node/filesystem-backend-module.ts b/packages/filesystem/src/node/filesystem-backend-module.ts index f60858386add5..084f9a37725a9 100644 --- a/packages/filesystem/src/node/filesystem-backend-module.ts +++ b/packages/filesystem/src/node/filesystem-backend-module.ts @@ -19,7 +19,7 @@ import { ContainerModule, interfaces } from 'inversify'; import { ConnectionHandler, JsonRpcConnectionHandler, ILogger } from '@theia/core/lib/common'; import { FileSystemWatcherServer, FileSystemWatcherService } from '../common/filesystem-watcher-protocol'; import { FileSystemWatcherServerClient } from './filesystem-watcher-client'; -import { NsfwFileSystemWatcherService } from './nsfw-watcher/nsfw-filesystem-service'; +import { NsfwFileSystemWatcherService, NsfwFileSystemWatcherServerOptions } from './nsfw-watcher/nsfw-filesystem-service'; import { MessagingService } from '@theia/core/lib/node/messaging/messaging-service'; import { NodeFileUploadService } from './node-file-upload-service'; import { NsfwOptions } from './nsfw-watcher/nsfw-options'; @@ -46,16 +46,20 @@ export function bindFileSystemWatcherServer(bind: interfaces.Bind, { singleThrea if (singleThreaded) { // Bind and run the watch server in the current process: - bind(FileSystemWatcherService).toDynamicValue(ctx => { + bind(NsfwFileSystemWatcherServerOptions).toDynamicValue(ctx => { const logger = ctx.container.get(ILogger); const nsfwOptions = ctx.container.get(NsfwOptions); - const dispatcher = ctx.container.get(FileSystemWatcherServiceDispatcher); - const server = new NsfwFileSystemWatcherService({ + return { nsfwOptions, verbose: NSFW_WATCHER_VERBOSE, info: (message, ...args) => logger.info(message, ...args), error: (message, ...args) => logger.error(message, ...args) - }); + } as NsfwFileSystemWatcherServerOptions; + }).inSingletonScope(); + bind(FileSystemWatcherService).toDynamicValue(ctx => { + const watcherOptions = ctx.container.get(NsfwFileSystemWatcherServerOptions); + const dispatcher = ctx.container.get(FileSystemWatcherServiceDispatcher); + const server = new NsfwFileSystemWatcherService(watcherOptions); server.setClient(dispatcher); return server; }).inSingletonScope(); @@ -66,6 +70,7 @@ export function bindFileSystemWatcherServer(bind: interfaces.Bind, { singleThrea const serverName = 'nsfw-watcher'; const logger = ctx.container.get(ILogger); const nsfwOptions = ctx.container.get(NsfwOptions); + const watcherOptions = ctx.container.get(NsfwFileSystemWatcherServerOptions); const ipcConnectionProvider = ctx.container.get(IPCConnectionProvider); const dispatcher = ctx.container.get(FileSystemWatcherServiceDispatcher); const proxyFactory = new JsonRpcProxyFactory(); @@ -80,7 +85,7 @@ export function bindFileSystemWatcherServer(bind: interfaces.Bind, { singleThrea } ipcConnectionProvider.listen({ serverName, - entryPoint: path.resolve(__dirname, serverName), + entryPoint: watcherOptions.entryPoint || path.resolve(__dirname, 'nsfw-watcher'), errorHandler: new ConnectionErrorHandler({ serverName, logger, diff --git a/packages/filesystem/src/node/nsfw-watcher/nsfw-filesystem-service.ts b/packages/filesystem/src/node/nsfw-watcher/nsfw-filesystem-service.ts index 62fb47aa8199c..c51ef4e1a6795 100644 --- a/packages/filesystem/src/node/nsfw-watcher/nsfw-filesystem-service.ts +++ b/packages/filesystem/src/node/nsfw-watcher/nsfw-filesystem-service.ts @@ -29,6 +29,7 @@ export interface NsfwWatcherOptions { ignored: IMinimatch[] } +export const NsfwFileSystemWatcherServerOptions = Symbol('NsfwFileSystemWatcherServerOptions'); export interface NsfwFileSystemWatcherServerOptions { verbose: boolean; // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -36,6 +37,7 @@ export interface NsfwFileSystemWatcherServerOptions { // eslint-disable-next-line @typescript-eslint/no-explicit-any error: (message: string, ...args: any[]) => void; nsfwOptions: nsfw.Options; + entryPoint?: string; } /** @@ -422,11 +424,7 @@ export class NsfwFileSystemWatcherService implements FileSystemWatcherService { let watcher = this.watchers.get(watcherKey); if (watcher === undefined) { const fsPath = FileUri.fsPath(uri); - const watcherOptions: NsfwWatcherOptions = { - ignored: resolvedOptions.ignored - .map(pattern => new Minimatch(pattern, { dot: true })), - }; - watcher = new NsfwWatcher(clientId, fsPath, watcherOptions, this.options, this.maybeClient); + watcher = this.createWatcher(clientId, fsPath, resolvedOptions); watcher.whenDisposed.then(() => this.watchers.delete(watcherKey)); this.watchers.set(watcherKey, watcher); } else { @@ -438,6 +436,14 @@ export class NsfwFileSystemWatcherService implements FileSystemWatcherService { return watcherId; } + protected createWatcher(clientId: number, fsPath: string, resolvedOptions: WatchOptions): NsfwWatcher { + const watcherOptions: NsfwWatcherOptions = { + ignored: resolvedOptions.ignored + .map(pattern => new Minimatch(pattern, { dot: true })), + }; + return new NsfwWatcher(clientId, fsPath, watcherOptions, this.options, this.maybeClient); + } + async unwatchFileChanges(watcherId: number): Promise { const handle = this.watcherHandles.get(watcherId); if (handle === undefined) {