Skip to content

Commit 5851fe3

Browse files
authored
watcher - some cleanup (microsoft#210723)
1 parent 69dbf1e commit 5851fe3

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,14 @@ export interface IRecursiveWatcherWithSubscribe extends IRecursiveWatcher {
135135

136136
/**
137137
* Subscribe to file events for the given path. The callback is called
138-
* whenever a file event occurs for the path. I fthe watcher failed,
138+
* whenever a file event occurs for the path. If the watcher failed,
139139
* the error parameter is set to `true`.
140140
*
141141
* @returns an `IDisposable` to stop listening to events or `undefined`
142142
* if no events can be watched for the path given the current set of
143143
* recursive watch requests.
144144
*/
145-
subscribe(path: string, callback: (error: boolean, change?: IFileChange) => void): IDisposable | undefined;
145+
subscribe(path: string, callback: (error: true | null, change?: IFileChange) => void): IDisposable | undefined;
146146
}
147147

148148
export interface IRecursiveWatcherOptions {

src/vs/platform/files/node/watcher/nodejs/nodejsWatcherLib.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,12 @@ export class NodeJSFileWatcherLibrary extends Disposable {
147147

148148
private doWatchWithExistingWatcher(realPath: string, isDirectory: boolean, disposables: DisposableStore): boolean {
149149
if (isDirectory) {
150-
return false; // only supported for files where we have the full path known upfront
150+
// TODO@bpasero recursive watcher re-use is currently not enabled
151+
// for when folders are watched. this is because the dispatching
152+
// in the recursive watcher for non-recurive requests is optimized
153+
// for file changes where we really only match on the exact path
154+
// and not child paths.
155+
return false;
151156
}
152157

153158
const resource = URI.file(this.request.path);

src/vs/platform/files/node/watcher/parcel/parcelWatcher.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ export class ParcelWatcher extends BaseWatcher implements IRecursiveWatcherWithS
782782
return true;
783783
}
784784

785-
subscribe(path: string, callback: (error: boolean, change?: IFileChange) => void): IDisposable | undefined {
785+
subscribe(path: string, callback: (error: true | null, change?: IFileChange) => void): IDisposable | undefined {
786786
for (const watcher of this.watchers) {
787787
if (watcher.failed) {
788788
continue; // watcher has already failed
@@ -810,7 +810,7 @@ export class ParcelWatcher extends BaseWatcher implements IRecursiveWatcherWithS
810810
callback(true /* error */);
811811
}));
812812
disposables.add(Event.once(watcher.onDidFail)(() => callback(true /* error */)));
813-
disposables.add(watcher.subscribe(path, change => callback(false, change)));
813+
disposables.add(watcher.subscribe(path, change => callback(null, change)));
814814

815815
return disposables;
816816
}

src/vs/platform/files/node/watcher/watcherStats.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,31 @@ export function computeStats(
3838
lines.push(`- I/O Handles Impact: total: ${recursiveRequestsStatus.polling + nonRecursiveRequestsStatus.polling + recursiveWatcherStatus.active + nonRecursiveWatcherStatus.active}`);
3939

4040
lines.push(`\n[Recursive Requests (${allRecursiveRequests.length}, suspended: ${recursiveRequestsStatus.suspended}, polling: ${recursiveRequestsStatus.polling})]:`);
41+
const recursiveRequestLines: string[] = [];
4142
for (const request of [nonSuspendedRecursiveRequests, suspendedPollingRecursiveRequests, suspendedNonPollingRecursiveRequests].flat()) {
42-
fillRequestStats(lines, request, recursiveWatcher);
43+
fillRequestStats(recursiveRequestLines, request, recursiveWatcher);
4344
}
45+
lines.push(...alignTextColumns(recursiveRequestLines));
4446

45-
fillRecursiveWatcherStats(lines, recursiveWatcher);
47+
const recursiveWatcheLines: string[] = [];
48+
fillRecursiveWatcherStats(recursiveWatcheLines, recursiveWatcher);
49+
lines.push(...alignTextColumns(recursiveWatcheLines));
4650

4751
lines.push(`\n[Non-Recursive Requests (${allNonRecursiveRequests.length}, suspended: ${nonRecursiveRequestsStatus.suspended}, polling: ${nonRecursiveRequestsStatus.polling})]:`);
52+
const nonRecursiveRequestLines: string[] = [];
4853
for (const request of [nonSuspendedNonRecursiveRequests, suspendedPollingNonRecursiveRequests, suspendedNonPollingNonRecursiveRequests].flat()) {
49-
fillRequestStats(lines, request, nonRecursiveWatcher);
54+
fillRequestStats(nonRecursiveRequestLines, request, nonRecursiveWatcher);
5055
}
56+
lines.push(...alignTextColumns(nonRecursiveRequestLines));
5157

52-
fillNonRecursiveWatcherStats(lines, nonRecursiveWatcher);
58+
const nonRecursiveWatcheLines: string[] = [];
59+
fillNonRecursiveWatcherStats(nonRecursiveWatcheLines, nonRecursiveWatcher);
60+
lines.push(...alignTextColumns(nonRecursiveWatcheLines));
5361

62+
return `\n\n[File Watcher] request stats:\n\n${lines.join('\n')}\n\n`;
63+
}
64+
65+
function alignTextColumns(lines: string[]) {
5466
let maxLength = 0;
5567
for (const line of lines) {
5668
maxLength = Math.max(maxLength, line.split('\t')[0].length);
@@ -65,7 +77,7 @@ export function computeStats(
6577
}
6678
}
6779

68-
return `\n\n[File Watcher] request stats:\n\n${lines.join('\n')}\n\n`;
80+
return lines;
6981
}
7082

7183
function computeRequestStatus(requests: IUniversalWatchRequest[], watcher: ParcelWatcher | NodeJSWatcher): { suspended: number; polling: number } {

0 commit comments

Comments
 (0)