From 714456b9b996e969b77a66179e778abbf49ab896 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Tue, 7 Jun 2022 09:19:45 +0200 Subject: [PATCH] Watcher: allow to fully turn off a watcher for a workspace via `files.watcherExclude` (#150951) --- .../platform/files/node/watcher/parcel/parcelWatcher.ts | 9 +++++++-- .../files/test/node/parcelWatcher.integrationTest.ts | 8 ++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/vs/platform/files/node/watcher/parcel/parcelWatcher.ts b/src/vs/platform/files/node/watcher/parcel/parcelWatcher.ts index 4b9c801252b..21759ab776c 100644 --- a/src/vs/platform/files/node/watcher/parcel/parcelWatcher.ts +++ b/src/vs/platform/files/node/watcher/parcel/parcelWatcher.ts @@ -11,7 +11,7 @@ import { CancellationToken, CancellationTokenSource } from 'vs/base/common/cance import { toErrorMessage } from 'vs/base/common/errorMessage'; import { Emitter } from 'vs/base/common/event'; import { isEqualOrParent, randomPath } from 'vs/base/common/extpath'; -import { ParsedPattern, patternsEquals } from 'vs/base/common/glob'; +import { GLOBSTAR, ParsedPattern, patternsEquals } from 'vs/base/common/glob'; import { Disposable } from 'vs/base/common/lifecycle'; import { TernarySearchTree } from 'vs/base/common/map'; import { normalizeNFC } from 'vs/base/common/normalization'; @@ -663,12 +663,17 @@ export class ParcelWatcher extends Disposable implements IRecursiveWatcher { // Only consider requests for watching that are not // a child of an existing request path to prevent - // duplication. + // duplication. In addition, drop any request where + // everything is excluded (via `**` glob). // // However, allow explicit requests to watch folders // that are symbolic links because the Parcel watcher // does not allow to recursively watch symbolic links. for (const request of requests) { + if (request.excludes.includes(GLOBSTAR)) { + continue; // path is ignored entirely (via `**` glob exclude) + } + if (requestTrie.findSubstr(request.path)) { try { const realpath = realpathSync(request.path); diff --git a/src/vs/platform/files/test/node/parcelWatcher.integrationTest.ts b/src/vs/platform/files/test/node/parcelWatcher.integrationTest.ts index 0c12d6371e6..f65b70e4865 100644 --- a/src/vs/platform/files/test/node/parcelWatcher.integrationTest.ts +++ b/src/vs/platform/files/test/node/parcelWatcher.integrationTest.ts @@ -26,11 +26,11 @@ import { ltrim } from 'vs/base/common/strings'; class TestParcelWatcher extends ParcelWatcher { - testNormalizePaths(paths: string[]): string[] { + testNormalizePaths(paths: string[], excludes: string[] = []): string[] { // Work with strings as paths to simplify testing const requests: IRecursiveWatchRequest[] = paths.map(path => { - return { path, excludes: [], recursive: true }; + return { path, excludes, recursive: true }; }); return this.normalizeRequests(requests).map(request => request.path); @@ -555,6 +555,10 @@ import { ltrim } from 'vs/base/common/strings'; } }); + test('should ignore when everything excluded', () => { + assert.deepStrictEqual(watcher.testNormalizePaths(['/foo/bar', '/bar'], ['**', 'something']), []); + }); + test('excludes are converted to absolute paths', () => { // undefined / empty