Merge pull request #16080 from atom/fb-hw-directory-watcher

Allow directory providers to implement a custom onDidChangeFiles
This commit is contained in:
Ash Wilson
2017-11-02 18:30:59 -07:00
committed by GitHub
2 changed files with 38 additions and 2 deletions

View File

@@ -338,13 +338,21 @@ class Project extends Model {
}
this.rootDirectories.push(directory)
this.watcherPromisesByPath[directory.getPath()] = watchPath(directory.getPath(), {}, events => {
const didChangeCallback = events => {
// Stop event delivery immediately on removal of a rootDirectory, even if its watcher
// promise has yet to resolve at the time of removal
if (this.rootDirectories.includes(directory)) {
this.emitter.emit('did-change-files', events)
}
})
}
// We'll use the directory's custom onDidChangeFiles callback, if available.
// CustomDirectory::onDidChangeFiles should match the signature of
// Project::onDidChangeFiles below (although it may resolve asynchronously)
this.watcherPromisesByPath[directory.getPath()] =
directory.onDidChangeFiles != null
? Promise.resolve(directory.onDidChangeFiles(didChangeCallback))
: watchPath(directory.getPath(), {}, didChangeCallback)
for (let watchedPath in this.watcherPromisesByPath) {
if (!this.rootDirectories.find(dir => dir.getPath() === watchedPath)) {