src/vs/platform/files/common/fileService.ts/FileService/watch
class FileService:	watch(resource: URI, options: IWatchOptions = { recursive: false, excludes: [] }): IDisposable {
		const disposables = new DisposableStore();

		// Forward watch request to provider and
		// wire in disposables.
		{
			let watchDisposed = false;
			let disposeWatch = () => { watchDisposed = true; };
			disposables.add(toDisposable(() => disposeWatch()));

			// Watch and wire in disposable which is async but
			// check if we got disposed meanwhile and forward
			this.doWatch(resource, options).then(disposable => {
				if (watchDisposed) {
					dispose(disposable);
				} else {
					disposeWatch = () => dispose(disposable);
				}
			}, error => this.logService.error(error));
		}

		// Remember as watched resource and unregister
		// properly on disposal.
		//
		// Note: we only do this for non-recursive watchers
		// until we have a better `createWatcher` based API
		// (https://github.com/microsoft/vscode/issues/126809)
		//
		if (!options.recursive) {

			// Increment counter for resource
			this.watchedResources.set(resource, (this.watchedResources.get(resource) ?? 0) + 1);

			// Decrement counter for resource on dispose
			// and remove from map when last one is gone
			disposables.add(toDisposable(() => {
				const watchedResourceCounter = this.watchedResources.get(resource);
				if (typeof watchedResourceCounter === 'number') {
					if (watchedResourceCounter <= 1) {
						this.watchedResources.delete(resource);
					} else {
						this.watchedResources.set(resource, watchedResourceCounter - 1);
					}
				}
			}));
		}

		return disposables;
	}