feat: add input interruption on file changes in FileWatcher

This commit is contained in:
Paul Gauthier 2024-11-27 16:29:24 -08:00 committed by Paul Gauthier (aider)
parent ac7900ecd7
commit 496b92536f

View file

@ -9,7 +9,7 @@ from watchfiles import watch
from aider.dump import dump # noqa from aider.dump import dump # noqa
VERBOSE = False VERBOSE = True
def is_source_file(path: Path) -> bool: def is_source_file(path: Path) -> bool:
@ -65,10 +65,11 @@ def load_gitignores(gitignore_paths: list[Path]) -> Optional[PathSpec]:
class FileWatcher: class FileWatcher:
"""Watches source files for changes and AI comments""" """Watches source files for changes and AI comments"""
def __init__(self, directory: str, encoding="utf-8", gitignores: list[str] = None): def __init__(self, coder, encoding="utf-8", gitignores=None):
self.directory = directory self.coder = coder
self.directory = coder.root
self.encoding = encoding self.encoding = encoding
self.root = Path(directory) self.root = Path(self.directory)
self.root_abs = self.root.absolute() self.root_abs = self.root.absolute()
self.stop_event = None self.stop_event = None
self.watcher_thread = None self.watcher_thread = None
@ -139,6 +140,7 @@ class FileWatcher:
dump(result) dump(result)
if result: if result:
self.changed_files = result self.changed_files = result
self.io.interrupt_input()
return return
except Exception as e: except Exception as e:
if VERBOSE: if VERBOSE: