Skip to content

Commit

Permalink
feat: add recursiveWatcherBackend option
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaaaash committed Jan 3, 2025
1 parent e747c92 commit fac07f6
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 26 deletions.
8 changes: 8 additions & 0 deletions packages/core-browser/src/react-providers/config-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
ExtensionCandidate,
ExtensionConnectOption,
IDesignLayoutConfig,
RecursiveWatcherBackend,
UrlProvider,
} from '@opensumi/ide-core-common';

Expand Down Expand Up @@ -317,6 +318,13 @@ export interface AppConfig {
* Unrecursive directories
*/
unRecursiveDirectories?: string[];

/**
* Recursive watcher backend type
*
* Default value is `nsfw`
*/
recursiveWatcherBackend?: RecursiveWatcherBackend;
}

export interface ICollaborationClientOpts {
Expand Down
5 changes: 5 additions & 0 deletions packages/core-common/src/types/file-watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,8 @@ export enum VSCFileChangeType {
*/
Deleted = 3,
}

export enum RecursiveWatcherBackend {
NSFW = 'nsfw',
PARCEL = 'parcel',
}
2 changes: 1 addition & 1 deletion packages/file-service/src/browser/file-service-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class FileServiceClient implements IFileServiceClient, IDisposable {
async initialize() {
const provider = await this.getProvider(Schemes.file);
if (provider.initialize) {
await provider.initialize(this.clientId);
await provider.initialize(this.clientId, this.appConfig.recursiveWatcherBackend);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Emitter,
Event,
FileSystemProviderCapabilities,
RecursiveWatcherBackend,
Uri,
debounce,
getDebugLogger,
Expand Down Expand Up @@ -106,10 +107,10 @@ export class DiskFsProviderClient extends CoreFileServiceProviderClient implemen
return this._capabilities;
}

async initialize(clientId: string) {
async initialize(clientId: string, backend?: RecursiveWatcherBackend) {
if (this.fileServiceProvider?.initialize) {
try {
await this.fileServiceProvider?.initialize(clientId);
await this.fileServiceProvider?.initialize(clientId, backend);
} catch (err) {
getDebugLogger('fileService.fsProvider').error('initialize error', err);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/file-service/src/common/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
isFunction,
isUndefinedOrNull,
} from '@opensumi/ide-core-common';
import { FileStat, FileSystemProvider } from '@opensumi/ide-core-common/lib/types/file';
import { FileStat, FileSystemProvider, RecursiveWatcherBackend } from '@opensumi/ide-core-common/lib/types/file';

import type { Range } from 'vscode-languageserver-types';
export {
Expand Down Expand Up @@ -420,7 +420,7 @@ export function containsExtraFileMethod<X extends {}, Y extends keyof ExtendedFi
}

export interface IDiskFileProvider extends FileSystemProvider {
initialize?: (clientid: string) => Promise<void>;
initialize?: (clientid: string, backend?: RecursiveWatcherBackend) => Promise<void>;
copy: FileCopyFn;
access: FileAccessFn;
getCurrentUserHome: FileGetCurrentUserHomeFn;
Expand Down
8 changes: 6 additions & 2 deletions packages/file-service/src/common/watcher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { ProxyIdentifier } from '@opensumi/ide-connection/lib/common/rpc/multiplexer';
import { Event, FileChange, IRelativePattern, URI, UriComponents } from '@opensumi/ide-core-common';
import { DidFilesChangedParams, FileSystemWatcherClient } from '@opensumi/ide-core-common/lib/types/file-watch';
import {
DidFilesChangedParams,
FileSystemWatcherClient,
RecursiveWatcherBackend,
} from '@opensumi/ide-core-common/lib/types/file-watch';

import { IFileServiceClient } from './file-service-client';

Expand Down Expand Up @@ -75,7 +79,7 @@ export const WatcherProcessManagerProxy = new ProxyIdentifier('WatcherProcessMan
export interface IWatcherProcessManager {
whenReady: Promise<void>;

createProcess(clientId: string): Promise<number | undefined>;
createProcess(clientId: string, backend?: RecursiveWatcherBackend): Promise<number | undefined>;
setClient(client: FileSystemWatcherClient): void;
dispose(): Promise<void>;

Expand Down
5 changes: 3 additions & 2 deletions packages/file-service/src/node/disk-file-system.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
FileType,
IDiskFileProvider,
IWatcherProcessManager,
RecursiveWatcherBackend,
handleError,
isErrnoException,
notEmpty,
Expand Down Expand Up @@ -105,8 +106,8 @@ export class DiskFileSystemProvider extends RPCService<IRPCDiskFileSystemProvide
});
}

async initialize(clientId: string) {
await this.watcherProcessManager.createProcess(clientId);
async initialize(clientId: string, backend?: RecursiveWatcherBackend) {
await this.watcherProcessManager.createProcess(clientId, backend);
}

get whenReady() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ import fs from 'fs-extra';
import debounce from 'lodash/debounce';
import uniqBy from 'lodash/uniqBy';

import {
FileChangeType,
FileSystemWatcherClient,
IFileSystemWatcherServer,
INsfw,

Check failure on line 12 in packages/file-service/src/node/hosted/recursive/file-service-watcher.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest, Node.js 20.x

Module '"@opensumi/ide-core-common"' has no exported member 'INsfw'.

Check failure on line 12 in packages/file-service/src/node/hosted/recursive/file-service-watcher.ts

View workflow job for this annotation

GitHub Actions / unittest (macos-latest, 18.x, node)

Module '"@opensumi/ide-core-common"' has no exported member 'INsfw'.

Check failure on line 12 in packages/file-service/src/node/hosted/recursive/file-service-watcher.ts

View workflow job for this annotation

GitHub Actions / build (macos-latest, 20.x)

Module '"@opensumi/ide-core-common"' has no exported member 'INsfw'.

Check failure on line 12 in packages/file-service/src/node/hosted/recursive/file-service-watcher.ts

View workflow job for this annotation

GitHub Actions / build-windows

Module '"@opensumi/ide-core-common"' has no exported member 'INsfw'.

Check failure on line 12 in packages/file-service/src/node/hosted/recursive/file-service-watcher.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 20.x)

Module '"@opensumi/ide-core-common"' has no exported member 'INsfw'.

Check failure on line 12 in packages/file-service/src/node/hosted/recursive/file-service-watcher.ts

View workflow job for this annotation

GitHub Actions / unittest (ubuntu-latest, 18.x, node)

Module '"@opensumi/ide-core-common"' has no exported member 'INsfw'.

Check failure on line 12 in packages/file-service/src/node/hosted/recursive/file-service-watcher.ts

View workflow job for this annotation

GitHub Actions / unittest (ubuntu-latest, 18.x, jsdom)

Module '"@opensumi/ide-core-common"' has no exported member 'INsfw'.
RecursiveWatcherBackend,
WatchOptions,
} from '@opensumi/ide-core-common';
import { ILogService } from '@opensumi/ide-core-common/lib/log';
import {
Disposable,
Expand All @@ -17,13 +25,6 @@ import {
parseGlob,
} from '@opensumi/ide-core-common/lib/utils';

import {
FileChangeType,
FileSystemWatcherClient,
IFileSystemWatcherServer,
INsfw,
WatchOptions,
} from '../../../common';
import { FileChangeCollection } from '../../file-change-collection';
import { shouldIgnorePath } from '../shared';

Expand Down Expand Up @@ -62,7 +63,11 @@ export class FileSystemWatcherServer extends Disposable implements IFileSystemWa

protected changes = new FileChangeCollection();

constructor(private excludes: string[] = [], private readonly logger: ILogService) {
constructor(
private excludes: string[] = [],
private readonly logger: ILogService,
private backend: RecursiveWatcherBackend = RecursiveWatcherBackend.NSFW,
) {
super();
this.addDispose(
Disposable.create(() => {
Expand Down Expand Up @@ -301,7 +306,7 @@ export class FileSystemWatcherServer extends Disposable implements IFileSystemWa
* 社区相关 issue: https://github.com/parcel-bundler/watcher/issues/49
*/
private isEnableNSFW(): boolean {
return isLinux;
return this.backend === RecursiveWatcherBackend.NSFW || isLinux;
}

private async handleNSFWEvents(events: INsfw.ChangeEvent[], watcherId: number): Promise<void> {
Expand Down
10 changes: 7 additions & 3 deletions packages/file-service/src/node/hosted/watcher.host.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SumiConnectionMultiplexer } from '@opensumi/ide-connection';
import { DidFilesChangedParams } from '@opensumi/ide-core-common';
import { DidFilesChangedParams, RecursiveWatcherBackend } from '@opensumi/ide-core-common';
import { defaultFilesWatcherExcludes, flattenExcludes } from '@opensumi/ide-core-common/lib/preferences/file-watch';
import { URI, Uri, UriComponents } from '@opensumi/ide-utils/lib/uri';

Expand Down Expand Up @@ -27,7 +27,11 @@ export class WatcherHostServiceImpl implements IWatcherHostService {

private watchedDirs: Set<string> = new Set();

constructor(private rpcProtocol: SumiConnectionMultiplexer, private logger: WatcherProcessLogger) {
constructor(
private rpcProtocol: SumiConnectionMultiplexer,
private logger: WatcherProcessLogger,
private backend: RecursiveWatcherBackend,
) {
this.rpcProtocol.set(WatcherServiceProxy, this);
this.defaultExcludes = flattenExcludes(defaultFilesWatcherExcludes);
this.initWatcherServer(this.defaultExcludes);
Expand All @@ -54,7 +58,7 @@ export class WatcherHostServiceImpl implements IWatcherHostService {
}
}

this.recursiveFileSystemWatcher = new FileSystemWatcherServer(excludes, this.logger);
this.recursiveFileSystemWatcher = new FileSystemWatcherServer(excludes, this.logger, this.backend);
this.unrecursiveFileSystemWatcher = new UnRecursiveFileSystemWatcher(this.logger);

const watcherClient = {
Expand Down
2 changes: 1 addition & 1 deletion packages/file-service/src/node/hosted/watcher.process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async function initWatcherProcess() {
});

const logger = new WatcherProcessLogger(watcherInjector, initData.logDir, initData.logLevel);
const watcherHostService = new WatcherHostServiceImpl(watcherProtocol, logger);
const watcherHostService = new WatcherHostServiceImpl(watcherProtocol, logger, initData.backend);
watcherHostService.initWatcherServer();
}

Expand Down
13 changes: 9 additions & 4 deletions packages/file-service/src/node/watcher-process-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { IRPCProtocol } from '@opensumi/ide-connection';
import { NetSocketConnection } from '@opensumi/ide-connection/lib/common/connection/drivers/socket';
import { SumiConnectionMultiplexer } from '@opensumi/ide-connection/lib/common/rpc/multiplexer';
import { ILogServiceManager, SupportLogNamespace } from '@opensumi/ide-core-common/lib/log';
import { DidFilesChangedParams, FileSystemWatcherClient } from '@opensumi/ide-core-common/lib/types/file-watch';
import {
DidFilesChangedParams,
FileSystemWatcherClient,
RecursiveWatcherBackend,
} from '@opensumi/ide-core-common/lib/types/file-watch';
import { normalizedIpcHandlerPathAsync } from '@opensumi/ide-core-common/lib/utils/ipc';
import { AppConfig, Deferred, ILogService, UriComponents } from '@opensumi/ide-core-node';
import { process as processUtil } from '@opensumi/ide-utils';
Expand Down Expand Up @@ -110,14 +114,15 @@ export class WatcherProcessManagerImpl implements IWatcherProcessManager {
);
}

private async createWatcherProcess(clientId: string, ipcHandlerPath: string) {
private async createWatcherProcess(clientId: string, ipcHandlerPath: string, backend?: RecursiveWatcherBackend) {
const forkArgs = [
`--${SUMI_WATCHER_PROCESS_SOCK_KEY}=${JSON.stringify({
path: ipcHandlerPath,
})}`,
`--${WATCHER_INIT_DATA_KEY}=${JSON.stringify({
logDir: this.appConfig.logDir,
logLevel: this.appConfig.logLevel,
backend,
clientId,
})}`,
];
Expand All @@ -136,14 +141,14 @@ export class WatcherProcessManagerImpl implements IWatcherProcessManager {
return this.watcherProcess.pid;
}

async createProcess(clientId: string) {
async createProcess(clientId: string, backend?: RecursiveWatcherBackend) {
this.logger.log('create watcher process for client: ', clientId);
this.logger.log('appconfig watcherHost: ', this.watcherHost);

const ipcHandlerPath = await this.getIPCHandlerPath('watcher_process');
await this.createWatcherServer(clientId, ipcHandlerPath);

const pid = await this.createWatcherProcess(clientId, ipcHandlerPath);
const pid = await this.createWatcherProcess(clientId, ipcHandlerPath, backend);

return pid;
}
Expand Down

0 comments on commit fac07f6

Please sign in to comment.