Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/services/files/electron-browser/watcherClient.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { DisposableStore } from '../../../../base/common/lifecycle.js';
7
import { getDelayedChannel, ProxyChannel } from '../../../../base/parts/ipc/common/ipc.js';
8
import { IFileChange } from '../../../../platform/files/common/files.js';
9
import { AbstractUniversalWatcherClient, ILogMessage, IRecursiveWatcher } from '../../../../platform/files/common/watcher.js';
10
import { IUtilityProcessWorkerWorkbenchService } from '../../utilityProcess/electron-browser/utilityProcessWorkerWorkbenchService.js';
11
12
export class UniversalWatcherClient extends AbstractUniversalWatcherClient {
13
14
constructor(
15
onFileChanges: (changes: IFileChange[]) => void,
16
onLogMessage: (msg: ILogMessage) => void,
17
verboseLogging: boolean,
18
private readonly utilityProcessWorkerWorkbenchService: IUtilityProcessWorkerWorkbenchService
19
) {
20
super(onFileChanges, onLogMessage, verboseLogging);
21
22
this.init();
23
}
24
25
protected override createWatcher(disposables: DisposableStore): IRecursiveWatcher {
26
const watcher = ProxyChannel.toService<IRecursiveWatcher>(getDelayedChannel((async () => {
27
28
// Acquire universal watcher via utility process worker
29
//
30
// We explicitly do not add the worker as a disposable
31
// because we need to call `stop` on disposal to prevent
32
// a crash on shutdown (see below).
33
//
34
// The utility process worker services ensures to terminate
35
// the process automatically when the window closes or reloads.
36
const { client, onDidTerminate } = disposables.add(await this.utilityProcessWorkerWorkbenchService.createWorker({
37
moduleId: 'vs/platform/files/node/watcher/watcherMain',
38
type: 'fileWatcher',
39
name: 'file-watcher'
40
}));
41
42
// React on unexpected termination of the watcher process
43
// by listening to the `onDidTerminate` event. We do not
44
// consider an exit code of `0` as abnormal termination.
45
46
onDidTerminate.then(({ reason }) => {
47
if (reason?.code === 0) {
48
this.trace(`terminated by itself with code ${reason.code}, signal: ${reason.signal}`);
49
} else {
50
this.onError(`terminated by itself unexpectedly with code ${reason?.code}, signal: ${reason?.signal} (ETERM)`);
51
}
52
});
53
54
return client.getChannel('watcher');
55
})()));
56
57
return watcher;
58
}
59
}
60
61