|
| 1 | +import { Event, EventEmitter, Uri, workspace } from "vscode"; |
| 2 | +import { anyEvent, filterEvent, IDisposable, isDescendant } from "../util"; |
| 3 | + |
| 4 | +export class RepositoryFilesWatcher implements IDisposable { |
| 5 | + private disposables: IDisposable[] = []; |
| 6 | + |
| 7 | + public onDidChange: Event<Uri>; |
| 8 | + public onDidCreate: Event<Uri>; |
| 9 | + public onDidDelete: Event<Uri>; |
| 10 | + public onDidAny: Event<Uri>; |
| 11 | + |
| 12 | + public onDidWorkspaceChange: Event<Uri>; |
| 13 | + public onDidWorkspaceCreate: Event<Uri>; |
| 14 | + public onDidWorkspaceDelete: Event<Uri>; |
| 15 | + public onDidWorkspaceAny: Event<Uri>; |
| 16 | + |
| 17 | + public onDidSvnChange: Event<Uri>; |
| 18 | + public onDidSvnCreate: Event<Uri>; |
| 19 | + public onDidSvnDelete: Event<Uri>; |
| 20 | + public onDidSvnAny: Event<Uri>; |
| 21 | + |
| 22 | + constructor(readonly root: string) { |
| 23 | + const fsWatcher = workspace.createFileSystemWatcher("**"); |
| 24 | + this.disposables.push(fsWatcher); |
| 25 | + |
| 26 | + const ignoreTmp = (uri: Uri) => !/[\\\/]\.svn[\\\/]tmp/.test(uri.path); |
| 27 | + |
| 28 | + const ignoreNonRelevants = (uri: Uri) => |
| 29 | + ignoreTmp(uri) && !isDescendant(this.root, uri.fsPath); |
| 30 | + |
| 31 | + this.onDidChange = filterEvent(fsWatcher.onDidChange, ignoreNonRelevants); |
| 32 | + this.onDidCreate = filterEvent(fsWatcher.onDidCreate, ignoreNonRelevants); |
| 33 | + this.onDidDelete = filterEvent(fsWatcher.onDidDelete, ignoreNonRelevants); |
| 34 | + |
| 35 | + this.onDidAny = anyEvent( |
| 36 | + this.onDidChange, |
| 37 | + this.onDidCreate, |
| 38 | + this.onDidDelete |
| 39 | + ); |
| 40 | + |
| 41 | + const svnPattern = /[\\\/]\.svn[\\\/]/; |
| 42 | + |
| 43 | + const ignoreSvn = (uri: Uri) => !svnPattern.test(uri.path); |
| 44 | + |
| 45 | + this.onDidWorkspaceChange = filterEvent(this.onDidChange, ignoreSvn); |
| 46 | + this.onDidWorkspaceCreate = filterEvent(this.onDidCreate, ignoreSvn); |
| 47 | + this.onDidWorkspaceDelete = filterEvent(this.onDidDelete, ignoreSvn); |
| 48 | + |
| 49 | + this.onDidWorkspaceAny = anyEvent( |
| 50 | + this.onDidWorkspaceChange, |
| 51 | + this.onDidWorkspaceCreate, |
| 52 | + this.onDidWorkspaceDelete |
| 53 | + ); |
| 54 | + const ignoreWorkspace = (uri: Uri) => svnPattern.test(uri.path); |
| 55 | + |
| 56 | + this.onDidSvnChange = filterEvent(this.onDidChange, ignoreWorkspace); |
| 57 | + this.onDidSvnCreate = filterEvent(this.onDidCreate, ignoreWorkspace); |
| 58 | + this.onDidSvnDelete = filterEvent(this.onDidDelete, ignoreWorkspace); |
| 59 | + |
| 60 | + this.onDidSvnAny = anyEvent( |
| 61 | + this.onDidSvnChange, |
| 62 | + this.onDidSvnCreate, |
| 63 | + this.onDidSvnDelete |
| 64 | + ); |
| 65 | + } |
| 66 | + |
| 67 | + public dispose(): void { |
| 68 | + this.disposables.forEach(d => d.dispose()); |
| 69 | + } |
| 70 | +} |
0 commit comments