import { AbstractWatcher , AutoWire , Logger , WorkspaceFolder } from "@vmware/vrdt-common" ; import { DidChangeWatchedFilesParams , Disposable , FileEvent } from "vscode-languageserver" ; import { URI } from "vscode-uri" ; import { ConnectionLocator } from "./ConnectionLocator" ; import { Environment } from "./Environment" ; export interface FileChangeEvent extends FileEvent { workspaceFolder : WorkspaceFolder | undefined ; } export interface FileChangeEventParams { changes : FileChangeEvent [ ] ; } export type FileChangeListener = ( event : FileChangeEventParams ) => void ; @ AutoWire export class WorkspaceFilesWatcher extends AbstractWatcher < FileChangeEventParams > { protected readonly logger = Logger . get ( "WorkspaceFilesWatcher" ) ; constructor ( connectionLocator , private environment ) { super ( ) ; connectionLocator . connection . onDidChangeWatchedFiles ( this . watchedFilesChanged . bind ( this ) ) ; } onDidChangeWatchedFiles ( listener ) { return this . registerListener ( listener ) ; } private watchedFilesChanged ( event ) { this . logger . info ( "Watched workspace files were changed." ) ; const newEvent = { changes : event . changes . map ( this . convertEvent . bind ( this ) ) } ; this . logger . debug ( "Full list of changes (created = type 1, changed = type 2, deleted = type 3): " , newEvent ) ; this . notifyListeners ( newEvent ) ; } private convertEvent ( event ) { return { type : event . type , uri : event . uri , workspaceFolder : this . environment . getWorkspaceFolderOf ( URI . parse ( event . uri ) . fsPath ) } ; } }