Skip to content

Commit e29d3cc

Browse files
committed
WSL1: Use parcel watcher for polling watch mode (fix microsoft#135691)
1 parent 6c0929c commit e29d3cc

File tree

5 files changed

+222
-78
lines changed

5 files changed

+222
-78
lines changed

src/vs/platform/files/common/diskFileSystemProvider.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ import { IFileChange, IWatchOptions } from 'vs/platform/files/common/files';
1414
import { IDiskFileChange, ILogMessage, IWatchRequest, toFileChanges, WatcherService } from 'vs/platform/files/common/watcher';
1515
import { ILogService, LogLevel } from 'vs/platform/log/common/log';
1616

17-
export interface IWatcherOptions {
18-
pollingInterval?: number;
19-
usePolling: boolean | string[];
20-
}
21-
2217
export abstract class AbstractDiskFileSystemProvider extends Disposable {
2318

2419
constructor(
@@ -93,7 +88,11 @@ export abstract class AbstractDiskFileSystemProvider extends Disposable {
9388
}
9489

9590
// Ask to watch the provided folders
96-
return this.recursiveWatcher.watch(this.recursiveFoldersToWatch);
91+
return this.doWatch(this.recursiveWatcher, this.recursiveFoldersToWatch);
92+
}
93+
94+
protected doWatch(watcher: WatcherService, requests: IWatchRequest[]): Promise<void> {
95+
return watcher.watch(requests);
9796
}
9897

9998
protected abstract createRecursiveWatcher(

src/vs/platform/files/common/watcher.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ export interface IWatchRequest {
6868
* A set of glob patterns or paths to exclude from watching.
6969
*/
7070
excludes: string[];
71+
72+
/**
73+
* @deprecated TODO@bpasero TODO@aeschli remove me once WSL1
74+
* support ends.
75+
*/
76+
pollingInterval?: number;
7177
}
7278

7379
export interface IDiskFileChange {

src/vs/platform/files/node/diskFileSystemProvider.ts

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { FileWatcher as NodeJSWatcherService } from 'vs/platform/files/node/watc
2424
import { FileWatcher as NsfwWatcherService } from 'vs/platform/files/node/watcher/nsfw/watcherService';
2525
import { FileWatcher as ParcelWatcherService } from 'vs/platform/files/node/watcher/parcel/watcherService';
2626
import { FileWatcher as UnixWatcherService } from 'vs/platform/files/node/watcher/unix/watcherService';
27-
import { IDiskFileChange, ILogMessage, WatcherService } from 'vs/platform/files/common/watcher';
27+
import { IDiskFileChange, ILogMessage, IWatchRequest, WatcherService } from 'vs/platform/files/common/watcher';
2828
import { ILogService } from 'vs/platform/log/common/log';
2929
import product from 'vs/platform/product/common/product';
3030
import { AbstractDiskFileSystemProvider } from 'vs/platform/files/common/diskFileSystemProvider';
@@ -43,8 +43,24 @@ import { toErrorMessage } from 'vs/base/common/errorMessage';
4343
})();
4444

4545
export interface IWatcherOptions {
46-
pollingInterval?: number;
46+
47+
/**
48+
* If `true`, will enable polling for all watchers, otherwise
49+
* will enable it for paths included in the string array.
50+
*
51+
* @deprecated TODO@bpasero TODO@aeschli remove me once WSL1
52+
* support ends.
53+
*/
4754
usePolling: boolean | string[];
55+
56+
/**
57+
* If polling is enabled (via `usePolling`), defines the duration
58+
* in which the watcher will poll for changes.
59+
*
60+
* @deprecated TODO@bpasero TODO@aeschli remove me once WSL1
61+
* support ends.
62+
*/
63+
pollingInterval?: number;
4864
}
4965

5066
export interface IDiskFileSystemProviderOptions {
@@ -552,17 +568,10 @@ export class DiskFileSystemProvider extends AbstractDiskFileSystemProvider imple
552568
): WatcherService
553569
};
554570

555-
let watcherOptions: IWatcherOptions | undefined = undefined;
556-
557-
// requires a polling watcher
571+
let enableLegacyWatcher = false;
558572
if (this.options?.watcher?.usePolling) {
559-
watcherImpl = UnixWatcherService;
560-
watcherOptions = this.options?.watcher;
561-
}
562-
563-
// can use efficient watcher
564-
else {
565-
let enableLegacyWatcher = false;
573+
enableLegacyWatcher = false; // can use Parcel watcher for when polling is required
574+
} else {
566575
if (this.options?.legacyWatcher === 'on' || this.options?.legacyWatcher === 'off') {
567576
enableLegacyWatcher = this.options.legacyWatcher === 'on'; // setting always wins
568577
} else {
@@ -572,26 +581,43 @@ export class DiskFileSystemProvider extends AbstractDiskFileSystemProvider imple
572581
enableLegacyWatcher = folders === 1;
573582
}
574583
}
584+
}
575585

576-
if (enableLegacyWatcher) {
577-
if (isLinux) {
578-
watcherImpl = UnixWatcherService;
579-
} else {
580-
watcherImpl = NsfwWatcherService;
581-
}
586+
if (enableLegacyWatcher) {
587+
if (isLinux) {
588+
watcherImpl = UnixWatcherService;
582589
} else {
583-
watcherImpl = ParcelWatcherService;
590+
watcherImpl = NsfwWatcherService;
584591
}
592+
} else {
593+
watcherImpl = ParcelWatcherService;
585594
}
586595

587596
return new watcherImpl(
588597
changes => onChange(changes),
589598
msg => onLogMessage(msg),
590599
verboseLogging,
591-
watcherOptions
600+
this.options?.watcher
592601
);
593602
}
594603

604+
protected override doWatch(watcher: WatcherService, requests: IWatchRequest[]): Promise<void> {
605+
const usePolling = this.options?.watcher?.usePolling;
606+
if (usePolling === true) {
607+
for (const request of requests) {
608+
request.pollingInterval = this.options?.watcher?.pollingInterval ?? 5000;
609+
}
610+
} else if (Array.isArray(usePolling)) {
611+
for (const request of requests) {
612+
if (usePolling.includes(request.path)) {
613+
request.pollingInterval = this.options?.watcher?.pollingInterval ?? 5000;
614+
}
615+
}
616+
}
617+
618+
return super.doWatch(watcher, requests);
619+
}
620+
595621
protected createNonRecursiveWatcher(
596622
path: string,
597623
onChange: (changes: IDiskFileChange[]) => void,

0 commit comments

Comments
 (0)