'use strict' ; import * as vscode from 'vscode' ; import { LOG } from './logger' ; export class UriWatcher { private static _instanceCnt = 0 ; private log = LOG ( 'UriWatcher' + ( ++ UriWatcher . _instanceCnt ) ) ; private _watcher : vscode . FileSystemWatcher ; constructor ( globPattern , uris , run ) { this . _watcher = vscode . workspace . createFileSystemWatcher ( globPattern , false , false , false ) ; let watching = uris . map ( uri => uri . fsPath ) ; this . log . info ( 'Watching ' + globPattern + ': ' + watching . join ( ', ' ) ) ; let maybeUpdate = ( affectedPath ) => { let path = affectedPath . fsPath ; if ( watching . indexOf ( path ) >= 0 ) { this . log . debug ( 'Firing due to event ' + path ) ; run ( ) ; } else { } } ; this . _watcher . onDidChange ( maybeUpdate ) ; this . _watcher . onDidCreate ( maybeUpdate ) ; this . _watcher . onDidDelete ( maybeUpdate ) ; } public dispose ( ) { this . _watcher . dispose ( ) ; this . log . info ( 'Stopped.' ) ; } }