Skip to content

Commit

Permalink
file watcher 💄
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Sep 23, 2021
1 parent 2d6b50d commit 319a55c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
8 changes: 3 additions & 5 deletions src/vs/platform/files/node/diskFileSystemProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ export class DiskFileSystemProvider extends Disposable implements
enableLegacyWatcher = product.quality === 'stable' && isLinux;
}

// Single Folder Watcher (stable only)
// Legacy Watcher
if (enableLegacyWatcher && this.recursiveFoldersToWatch.length === 1) {
if (isWindows) {
watcherImpl = WindowsWatcherService;
Expand All @@ -629,7 +629,7 @@ export class DiskFileSystemProvider extends Disposable implements
}
}

// NSFW: Multi Folder Watcher or insiders
// Standard Watcher
else {
watcherImpl = NsfwWatcherService;
}
Expand All @@ -652,9 +652,7 @@ export class DiskFileSystemProvider extends Disposable implements

if (!this.recursiveWatcherLogLevelListener) {
this.recursiveWatcherLogLevelListener = this.logService.onDidChangeLogLevel(() => {
if (this.recursiveWatcher) {
this.recursiveWatcher.setVerboseLogging(this.logService.getLevel() === LogLevel.Trace);
}
this.recursiveWatcher?.setVerboseLogging(this.logService.getLevel() === LogLevel.Trace);
});
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/vs/platform/files/node/watcher/nodejs/watcherService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { IDiskFileChange, ILogMessage, normalizeFileChanges } from 'vs/platform/
export class FileWatcher extends Disposable {
private isDisposed: boolean | undefined;

private fileChangesDelayer: ThrottledDelayer<void> = this._register(new ThrottledDelayer<void>(CHANGE_BUFFER_DELAY * 2 /* sync on delay from underlying library */));
private readonly fileChangesDelayer: ThrottledDelayer<void> = this._register(new ThrottledDelayer<void>(CHANGE_BUFFER_DELAY * 2 /* sync on delay from underlying library */));
private fileChangesBuffer: IDiskFileChange[] = [];

constructor(
Expand Down Expand Up @@ -100,8 +100,8 @@ export class FileWatcher extends Disposable {

// Logging
if (this.verboseLogging) {
for (const e of normalizedFileChanges) {
this.onVerbose(`>> normalized ${e.type === FileChangeType.ADDED ? '[ADDED]' : e.type === FileChangeType.DELETED ? '[DELETED]' : '[CHANGED]'} ${e.path}`);
for (const event of normalizedFileChanges) {
this.onVerbose(`>> normalized ${event.type === FileChangeType.ADDED ? '[ADDED]' : event.type === FileChangeType.DELETED ? '[DELETED]' : '[CHANGED]'} ${event.path}`);
}
}

Expand Down
11 changes: 9 additions & 2 deletions src/vs/platform/files/node/watcher/nsfw/nsfwWatcherService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ export class NsfwWatcherService extends Disposable implements IWatcherService {
constructor() {
super();

this.registerListeners();
}

private registerListeners(): void {

// Error handling on process
process.on('uncaughtException', (error: Error | string) => this.onError(error));
process.on('unhandledRejection', (error: Error | string) => this.onError(error));
}

async watch(requests: IWatchRequest[]): Promise<void> {
Expand Down Expand Up @@ -307,8 +314,8 @@ export class NsfwWatcherService extends Disposable implements IWatcherService {
return Array.from(requestTrie).map(([, request]) => request);
}

private isPathIgnored(absolutePath: string, ignored: ParsedPattern[] | undefined): boolean {
return Array.isArray(ignored) && ignored.some(ignore => ignore(absolutePath));
private isPathIgnored(absolutePath: string, ignored: ParsedPattern[]): boolean {
return ignored.some(ignore => ignore(absolutePath));
}

async setVerboseLogging(enabled: boolean): Promise<void> {
Expand Down
11 changes: 6 additions & 5 deletions src/vs/platform/files/node/watcher/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ export function normalizeFileChanges(changes: IDiskFileChange[]): IDiskFileChang
}

class EventNormalizer {
private normalized: IDiskFileChange[] = [];
private mapPathToChange: Map<string, IDiskFileChange> = new Map();

private readonly normalized: IDiskFileChange[] = [];
private readonly mapPathToChange = new Map<string, IDiskFileChange>();

processEvent(event: IDiskFileChange): void {
const existingEvent = this.mapPathToChange.get(event.path);
Expand Down Expand Up @@ -88,7 +89,7 @@ class EventNormalizer {
}

normalize(): IDiskFileChange[] {
const addedChangeEvents: IDiskFileChange[] = [];
const addOrChangeEvents: IDiskFileChange[] = [];
const deletedPaths: string[] = [];

// This algorithm will remove all DELETE events up to the root folder
Expand All @@ -100,7 +101,7 @@ class EventNormalizer {
// 3.) for each DELETE, check if there is a deleted parent and ignore the event in that case
return this.normalized.filter(e => {
if (e.type !== FileChangeType.DELETED) {
addedChangeEvents.push(e);
addOrChangeEvents.push(e);

return false; // remove ADD / CHANGE
}
Expand All @@ -117,6 +118,6 @@ class EventNormalizer {
deletedPaths.push(e.path);

return true;
}).concat(addedChangeEvents);
}).concat(addOrChangeEvents);
}
}
4 changes: 0 additions & 4 deletions src/vs/workbench/contrib/files/browser/workspaceWatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { IConfigurationService, IConfigurationChangeEvent } from 'vs/platform/co
import { IFilesConfiguration, IFileService } from 'vs/platform/files/common/files';
import { IWorkspaceContextService, IWorkspaceFolder, IWorkspaceFoldersChangeEvent } from 'vs/platform/workspace/common/workspace';
import { ResourceMap } from 'vs/base/common/map';
import { onUnexpectedError } from 'vs/base/common/errors';
import { INotificationService, Severity, NeverShowAgainScope } from 'vs/platform/notification/common/notification';
import { localize } from 'vs/nls';
import { FileService } from 'vs/platform/files/common/fileService';
Expand Down Expand Up @@ -72,9 +71,6 @@ export class WorkspaceWatcher extends Disposable {
private onError(error: Error): void {
const msg = error.toString();

// Forward to unexpected error handler
onUnexpectedError(msg);

// Detect if we run into ENOSPC issues
if (msg.indexOf('ENOSPC') >= 0) {
this.notificationService.prompt(
Expand Down

0 comments on commit 319a55c

Please sign in to comment.