refactor: simplify file watcher filter function implementation

This commit is contained in:
Paul Gauthier (aider) 2024-12-01 08:09:13 -08:00
parent aa6d9779d3
commit e8ccc030c0

View file

@ -76,17 +76,12 @@ class FileWatcher:
self.changed_files = set()
self.gitignores = gitignores
#ai stop making this so indirect; just `def filter_func()` and use self.gitignores in it!
gitignore_paths = [Path(g) for g in self.gitignores] if self.gitignores else []
gitignore_spec = load_gitignores(gitignore_paths)
self.filter_func = self.create_filter_func(gitignore_spec, None)
self.gitignore_spec = load_gitignores([Path(g) for g in self.gitignores] if self.gitignores else [])
coder.io.file_watcher = self
def create_filter_func(self, gitignore_spec, ignore_func):
"""Creates a filter function for the file watcher"""
def filter_func(change_type, path):
def filter_func(self, change_type, path):
"""Filter function for the file watcher"""
path_obj = Path(path)
path_abs = path_obj.absolute()
@ -97,9 +92,7 @@ class FileWatcher:
if self.verbose:
dump(rel_path)
if gitignore_spec and gitignore_spec.match_file(str(rel_path)):
return False
if ignore_func and ignore_func(rel_path):
if self.gitignore_spec and self.gitignore_spec.match_file(str(rel_path)):
return False
if not is_source_file(path_obj):
@ -118,8 +111,6 @@ class FileWatcher:
dump(err)
return False
return filter_func
def start(self):
"""Start watching for file changes"""
self.stop_event = threading.Event()