Path: blob/main/src/vs/workbench/services/files/electron-browser/watcherClient.ts
3296 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import { DisposableStore } from '../../../../base/common/lifecycle.js';6import { getDelayedChannel, ProxyChannel } from '../../../../base/parts/ipc/common/ipc.js';7import { IFileChange } from '../../../../platform/files/common/files.js';8import { AbstractUniversalWatcherClient, ILogMessage, IRecursiveWatcher } from '../../../../platform/files/common/watcher.js';9import { IUtilityProcessWorkerWorkbenchService } from '../../utilityProcess/electron-browser/utilityProcessWorkerWorkbenchService.js';1011export class UniversalWatcherClient extends AbstractUniversalWatcherClient {1213constructor(14onFileChanges: (changes: IFileChange[]) => void,15onLogMessage: (msg: ILogMessage) => void,16verboseLogging: boolean,17private readonly utilityProcessWorkerWorkbenchService: IUtilityProcessWorkerWorkbenchService18) {19super(onFileChanges, onLogMessage, verboseLogging);2021this.init();22}2324protected override createWatcher(disposables: DisposableStore): IRecursiveWatcher {25const watcher = ProxyChannel.toService<IRecursiveWatcher>(getDelayedChannel((async () => {2627// Acquire universal watcher via utility process worker28//29// We explicitly do not add the worker as a disposable30// because we need to call `stop` on disposal to prevent31// a crash on shutdown (see below).32//33// The utility process worker services ensures to terminate34// the process automatically when the window closes or reloads.35const { client, onDidTerminate } = disposables.add(await this.utilityProcessWorkerWorkbenchService.createWorker({36moduleId: 'vs/platform/files/node/watcher/watcherMain',37type: 'fileWatcher',38name: 'file-watcher'39}));4041// React on unexpected termination of the watcher process42// by listening to the `onDidTerminate` event. We do not43// consider an exit code of `0` as abnormal termination.4445onDidTerminate.then(({ reason }) => {46if (reason?.code === 0) {47this.trace(`terminated by itself with code ${reason.code}, signal: ${reason.signal}`);48} else {49this.onError(`terminated by itself unexpectedly with code ${reason?.code}, signal: ${reason?.signal} (ETERM)`);50}51});5253return client.getChannel('watcher');54})()));5556return watcher;57}58}596061