@opensumi/ide-file-service 3.7.1-next-1739428766.0 → 3.7.1-next-1739439717.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/lib/browser/file-service-client.js +4 -4
  2. package/lib/browser/file-service-client.js.map +1 -1
  3. package/lib/browser/file-service-provider-client.d.ts +2 -2
  4. package/lib/browser/file-service-provider-client.d.ts.map +1 -1
  5. package/lib/browser/file-service-provider-client.js +2 -2
  6. package/lib/browser/file-service-provider-client.js.map +1 -1
  7. package/lib/common/files.d.ts +2 -2
  8. package/lib/common/files.d.ts.map +1 -1
  9. package/lib/common/watcher.d.ts +2 -3
  10. package/lib/common/watcher.d.ts.map +1 -1
  11. package/lib/common/watcher.js.map +1 -1
  12. package/lib/node/disk-file-system.provider.d.ts +2 -3
  13. package/lib/node/disk-file-system.provider.d.ts.map +1 -1
  14. package/lib/node/disk-file-system.provider.js +2 -3
  15. package/lib/node/disk-file-system.provider.js.map +1 -1
  16. package/lib/node/hosted/recursive/file-service-watcher.d.ts +13 -14
  17. package/lib/node/hosted/recursive/file-service-watcher.d.ts.map +1 -1
  18. package/lib/node/hosted/recursive/file-service-watcher.js +97 -158
  19. package/lib/node/hosted/recursive/file-service-watcher.js.map +1 -1
  20. package/lib/node/hosted/un-recursive/file-service-watcher.d.ts +11 -5
  21. package/lib/node/hosted/un-recursive/file-service-watcher.d.ts.map +1 -1
  22. package/lib/node/hosted/un-recursive/file-service-watcher.js +31 -15
  23. package/lib/node/hosted/un-recursive/file-service-watcher.js.map +1 -1
  24. package/lib/node/hosted/watcher.host.service.d.ts +2 -7
  25. package/lib/node/hosted/watcher.host.service.d.ts.map +1 -1
  26. package/lib/node/hosted/watcher.host.service.js +28 -60
  27. package/lib/node/hosted/watcher.host.service.js.map +1 -1
  28. package/lib/node/hosted/watcher.process.js +1 -1
  29. package/lib/node/hosted/watcher.process.js.map +1 -1
  30. package/lib/node/watcher-process-manager.d.ts +2 -3
  31. package/lib/node/watcher-process-manager.d.ts.map +1 -1
  32. package/lib/node/watcher-process-manager.js +3 -4
  33. package/lib/node/watcher-process-manager.js.map +1 -1
  34. package/package.json +9 -9
  35. package/src/browser/file-service-client.ts +4 -4
  36. package/src/browser/file-service-provider-client.ts +2 -3
  37. package/src/common/files.ts +2 -2
  38. package/src/common/watcher.ts +3 -10
  39. package/src/node/disk-file-system.provider.ts +3 -8
  40. package/src/node/hosted/recursive/file-service-watcher.ts +108 -190
  41. package/src/node/hosted/un-recursive/file-service-watcher.ts +46 -22
  42. package/src/node/hosted/watcher.host.service.ts +33 -100
  43. package/src/node/hosted/watcher.process.ts +1 -1
  44. package/src/node/watcher-process-manager.ts +5 -13
@@ -1,45 +1,20 @@
1
1
  import { SumiConnectionMultiplexer } from '@opensumi/ide-connection';
2
- import {
3
- DidFilesChangedParams,
4
- Disposable,
5
- DisposableCollection,
6
- FileUri,
7
- IDisposable,
8
- RecursiveWatcherBackend,
9
- } from '@opensumi/ide-core-common';
2
+ import { DidFilesChangedParams } from '@opensumi/ide-core-common';
10
3
  import { defaultFilesWatcherExcludes, flattenExcludes } from '@opensumi/ide-core-common/lib/preferences/file-watch';
11
4
  import { URI, Uri, UriComponents } from '@opensumi/ide-utils/lib/uri';
12
5
 
13
6
  import { IWatcherHostService, WatcherProcessManagerProxy, WatcherServiceProxy } from '../../common/watcher';
14
7
  import { IWatcher } from '../disk-file-system.provider';
15
8
 
16
- import { RecursiveFileSystemWatcher } from './recursive/file-service-watcher';
9
+ import { FileSystemWatcherServer } from './recursive/file-service-watcher';
17
10
  import { UnRecursiveFileSystemWatcher } from './un-recursive/file-service-watcher';
18
11
  import { WatcherProcessLogger } from './watch-process-log';
19
12
 
20
- const watcherPlaceHolder = {
21
- disposable: {
22
- dispose: () => {},
23
- },
24
- handlers: [],
25
- };
26
-
27
13
  export class WatcherHostServiceImpl implements IWatcherHostService {
28
- private static WATCHER_SEQUENCE = 1;
29
-
30
- private WATCHER_HANDLERS = new Map<
31
- number,
32
- {
33
- path: string;
34
- handlers: any;
35
- disposable: IDisposable;
36
- }
37
- >();
38
-
39
14
  /**
40
15
  * recursive file system watcher
41
16
  */
42
- private recursiveFileSystemWatcher?: RecursiveFileSystemWatcher;
17
+ private recursiveFileSystemWatcher?: FileSystemWatcherServer;
43
18
 
44
19
  /**
45
20
  * unrecursive file system watcher
@@ -52,11 +27,7 @@ export class WatcherHostServiceImpl implements IWatcherHostService {
52
27
 
53
28
  private watchedDirs: Set<string> = new Set();
54
29
 
55
- constructor(
56
- private rpcProtocol: SumiConnectionMultiplexer,
57
- private logger: WatcherProcessLogger,
58
- private backend: RecursiveWatcherBackend,
59
- ) {
30
+ constructor(private rpcProtocol: SumiConnectionMultiplexer, private logger: WatcherProcessLogger) {
60
31
  this.rpcProtocol.set(WatcherServiceProxy, this);
61
32
  this.defaultExcludes = flattenExcludes(defaultFilesWatcherExcludes);
62
33
  this.initWatcherServer(this.defaultExcludes);
@@ -77,19 +48,18 @@ export class WatcherHostServiceImpl implements IWatcherHostService {
77
48
 
78
49
  // rewatch
79
50
  for (const [_uri, { options, disposable }] of this.watcherCollection) {
51
+ this.doWatch(Uri.parse(_uri), options);
80
52
  this.logger.log('rewatch file changes: ', _uri, ' recursive: ', options?.recursive);
81
53
  disposable.dispose();
82
- this.watcherCollection.delete(_uri);
83
- this.doWatch(Uri.parse(_uri), options);
84
54
  }
85
55
  }
86
56
 
87
- this.recursiveFileSystemWatcher = new RecursiveFileSystemWatcher(excludes, this.logger, this.backend);
57
+ this.recursiveFileSystemWatcher = new FileSystemWatcherServer(excludes, this.logger);
88
58
  this.unrecursiveFileSystemWatcher = new UnRecursiveFileSystemWatcher(this.logger);
89
59
 
90
60
  const watcherClient = {
91
61
  onDidFilesChanged: (events: DidFilesChangedParams) => {
92
- this.logger.log('onDidFilesChanged: ', events);
62
+ this.logger.log('watcher server onDidFilesChanged: ', events);
93
63
  const proxy = this.rpcProtocol.getProxy(WatcherProcessManagerProxy);
94
64
  proxy.$onDidFilesChanged(events);
95
65
  },
@@ -99,84 +69,47 @@ export class WatcherHostServiceImpl implements IWatcherHostService {
99
69
  this.unrecursiveFileSystemWatcher.setClient(watcherClient);
100
70
  }
101
71
 
102
- checkIsAlreadyWatched(watcherPath: string): number | undefined {
103
- for (const [watcherId, watcher] of this.WATCHER_HANDLERS) {
104
- if (watcherPath === watcher.path) {
105
- return watcherId;
106
- }
107
- }
108
- }
109
-
110
- private async doWatch(
111
- uri: Uri,
112
- options?: { excludes?: string[]; recursive?: boolean; pollingWatch?: boolean },
113
- ): Promise<number> {
72
+ private getWatcherServer(recursive?: boolean) {
73
+ const useRecursiveServer = recursive;
74
+ let watcherServer: FileSystemWatcherServer | UnRecursiveFileSystemWatcher;
114
75
  this.initWatcherServer();
115
- const basePath = FileUri.fsPath(uri.toString());
116
- let watcherId = this.checkIsAlreadyWatched(basePath);
117
76
 
118
- if (watcherId) {
119
- this.logger.log(uri.toString(), 'is already watched');
120
- return watcherId;
77
+ if (useRecursiveServer) {
78
+ watcherServer = this.recursiveFileSystemWatcher!;
79
+ } else {
80
+ watcherServer = this.unrecursiveFileSystemWatcher!;
121
81
  }
122
82
 
123
- watcherId = WatcherHostServiceImpl.WATCHER_SEQUENCE++;
83
+ return watcherServer;
84
+ }
124
85
 
125
- this.WATCHER_HANDLERS.set(watcherId, {
126
- ...watcherPlaceHolder,
127
- path: basePath,
128
- });
86
+ private async doWatch(uri: Uri, options?: { excludes?: string[]; recursive?: boolean }): Promise<number> {
87
+ const watcherServer = this.getWatcherServer(options?.recursive);
88
+ if (!watcherServer) {
89
+ return -1;
90
+ }
129
91
 
130
92
  this.logger.log('watch file changes: ', uri.toString(), ' recursive: ', options?.recursive);
131
93
 
132
94
  const mergedExcludes = new Set([...(options?.excludes ?? []), ...this.defaultExcludes]);
95
+ const id = await watcherServer.watchFileChanges(uri.toString(), {
96
+ excludes: Array.from(mergedExcludes),
97
+ });
133
98
 
134
- const disposables = new DisposableCollection();
135
-
136
- await this.unrecursiveFileSystemWatcher!.watchFileChanges(uri.toString());
99
+ this.watchedDirs.add(uri.toString());
137
100
 
138
- disposables.push(
139
- Disposable.create(async () => {
140
- this.unrecursiveFileSystemWatcher!.unwatchFileChanges(uri.toString());
141
- this.logger.log('dispose unrecursive watcher: ', uri.toString());
101
+ const disposable = {
102
+ dispose: () => {
103
+ watcherServer.unwatchFileChanges(id);
142
104
  this.watchedDirs.delete(uri.toString());
143
- this.WATCHER_HANDLERS.delete(watcherId);
144
- }),
145
- );
146
-
147
- if (options?.recursive) {
148
- this.logger.log('use recursive watcher for: ', uri.toString());
149
- try {
150
- await this.recursiveFileSystemWatcher!.watchFileChanges(uri.toString(), {
151
- excludes: Array.from(mergedExcludes),
152
- pollingWatch: options?.pollingWatch,
153
- });
154
-
155
- disposables.push(
156
- Disposable.create(async () => {
157
- this.logger.log('dispose recursive watcher: ', uri.toString());
158
- this.recursiveFileSystemWatcher!.unwatchFileChanges(uri.toString());
159
- this.watchedDirs.delete(uri.toString());
160
- this.WATCHER_HANDLERS.delete(watcherId);
161
- }),
162
- );
163
- } catch (error) {
164
- // watch error or timeout
165
- this.logger.error('watch error: ', error);
166
- }
167
- }
168
-
169
- this.watcherCollection.set(uri.toString(), { id: watcherId, options, disposable: disposables });
170
-
171
- this.watchedDirs.add(uri.toString());
105
+ },
106
+ };
172
107
 
173
- return watcherId;
108
+ this.watcherCollection.set(uri.toString(), { id, options, disposable });
109
+ return id;
174
110
  }
175
111
 
176
- async $watch(
177
- uri: UriComponents,
178
- options?: { excludes?: string[]; recursive?: boolean; pollingWatch?: boolean },
179
- ): Promise<number> {
112
+ async $watch(uri: UriComponents, options?: { excludes?: string[]; recursive?: boolean }): Promise<number> {
180
113
  const _uri = URI.revive(uri);
181
114
  return this.doWatch(_uri, options);
182
115
  }
@@ -37,7 +37,7 @@ async function initWatcherProcess() {
37
37
  });
38
38
 
39
39
  const logger = new WatcherProcessLogger(watcherInjector, initData.logDir, initData.logLevel);
40
- const watcherHostService = new WatcherHostServiceImpl(watcherProtocol, logger, initData.backend);
40
+ const watcherHostService = new WatcherHostServiceImpl(watcherProtocol, logger);
41
41
  watcherHostService.initWatcherServer();
42
42
  }
43
43
 
@@ -7,11 +7,7 @@ import { IRPCProtocol } from '@opensumi/ide-connection';
7
7
  import { NetSocketConnection } from '@opensumi/ide-connection/lib/common/connection/drivers/socket';
8
8
  import { SumiConnectionMultiplexer } from '@opensumi/ide-connection/lib/common/rpc/multiplexer';
9
9
  import { ILogServiceManager, SupportLogNamespace } from '@opensumi/ide-core-common/lib/log';
10
- import {
11
- DidFilesChangedParams,
12
- FileSystemWatcherClient,
13
- RecursiveWatcherBackend,
14
- } from '@opensumi/ide-core-common/lib/types/file-watch';
10
+ import { DidFilesChangedParams, FileSystemWatcherClient } from '@opensumi/ide-core-common/lib/types/file-watch';
15
11
  import { normalizedIpcHandlerPathAsync } from '@opensumi/ide-core-common/lib/utils/ipc';
16
12
  import { AppConfig, Deferred, ILogService, UriComponents } from '@opensumi/ide-core-node';
17
13
  import { process as processUtil } from '@opensumi/ide-utils';
@@ -114,7 +110,7 @@ export class WatcherProcessManagerImpl implements IWatcherProcessManager {
114
110
  );
115
111
  }
116
112
 
117
- private async createWatcherProcess(clientId: string, ipcHandlerPath: string, backend?: RecursiveWatcherBackend) {
113
+ private async createWatcherProcess(clientId: string, ipcHandlerPath: string) {
118
114
  const forkArgs = [
119
115
  `--${SUMI_WATCHER_PROCESS_SOCK_KEY}=${JSON.stringify({
120
116
  path: ipcHandlerPath,
@@ -122,7 +118,6 @@ export class WatcherProcessManagerImpl implements IWatcherProcessManager {
122
118
  `--${WATCHER_INIT_DATA_KEY}=${JSON.stringify({
123
119
  logDir: this.appConfig.logDir,
124
120
  logLevel: this.appConfig.logLevel,
125
- backend,
126
121
  clientId,
127
122
  })}`,
128
123
  ];
@@ -141,14 +136,14 @@ export class WatcherProcessManagerImpl implements IWatcherProcessManager {
141
136
  return this.watcherProcess.pid;
142
137
  }
143
138
 
144
- async createProcess(clientId: string, backend?: RecursiveWatcherBackend) {
139
+ async createProcess(clientId: string) {
145
140
  this.logger.log('create watcher process for client: ', clientId);
146
141
  this.logger.log('appconfig watcherHost: ', this.watcherHost);
147
142
 
148
143
  const ipcHandlerPath = await this.getIPCHandlerPath('watcher_process');
149
144
  await this.createWatcherServer(clientId, ipcHandlerPath);
150
145
 
151
- const pid = await this.createWatcherProcess(clientId, ipcHandlerPath, backend);
146
+ const pid = await this.createWatcherProcess(clientId, ipcHandlerPath);
152
147
 
153
148
  return pid;
154
149
  }
@@ -163,10 +158,7 @@ export class WatcherProcessManagerImpl implements IWatcherProcessManager {
163
158
  }
164
159
  }
165
160
 
166
- async watch(
167
- uri: UriComponents,
168
- options?: { excludes?: string[]; recursive?: boolean; pollingWatch?: boolean },
169
- ): Promise<number> {
161
+ async watch(uri: UriComponents, options?: { excludes?: string[]; recursive?: boolean }): Promise<number> {
170
162
  this.logger.log('Wait for watcher process ready...');
171
163
  await this._whenReadyDeferred.promise;
172
164
  this.logger.log('start watch: ', uri);