func()

in ibazel/ibazel.go [503:534]


func (i *IBazel) watchFiles(query string, watcher common.Watcher) {
	toWatch, err := i.queryForSourceFiles(query)
	if err != nil {
		// If the query fails, just keep watching the same files as before
		return
	}

	filesWatched := map[string]struct{}{}
	uniqueDirectories := map[string]struct{}{}

	for _, file := range toWatch {
		if _, err := os.Stat(file); !os.IsNotExist(err) {
			filesWatched[file] = struct{}{}
		}

		parentDirectory, _ := filepath.Split(file)
		// Add a watch to the file's parent directory, we might already have this dir in our set but thats OK
		uniqueDirectories[parentDirectory] = struct{}{}
	}

	watchList := keys(uniqueDirectories)
	err = watcher.UpdateAll(watchList)
	if err != nil {
		log.Errorf("Error(s) updating watch list:\n %v", err)
	}

	if len(filesWatched) == 0 {
		log.Errorf("Didn't find any files to watch from query %s", query)
	}

	i.filesWatched[watcher] = filesWatched
}