mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-04 19:55:00 +00:00
refactor: simplify file change handling and interrupt logic
This commit is contained in:
parent
aac0c0f037
commit
9b4df54432
1 changed files with 10 additions and 28 deletions
38
aider/io.py
38
aider/io.py
|
@ -201,6 +201,7 @@ class InputOutput:
|
||||||
file_watcher=None,
|
file_watcher=None,
|
||||||
):
|
):
|
||||||
self.placeholder = None
|
self.placeholder = None
|
||||||
|
self.interrupted = False
|
||||||
self.never_prompts = set()
|
self.never_prompts = set()
|
||||||
self.editingmode = editingmode
|
self.editingmode = editingmode
|
||||||
no_color = os.environ.get("NO_COLOR")
|
no_color = os.environ.get("NO_COLOR")
|
||||||
|
@ -318,6 +319,7 @@ class InputOutput:
|
||||||
self.tool_error(f"{filename}: {e}")
|
self.tool_error(f"{filename}: {e}")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# add a silent=False arg that suppresses error output ai!
|
||||||
def read_text(self, filename):
|
def read_text(self, filename):
|
||||||
if is_image_file(filename):
|
if is_image_file(filename):
|
||||||
return self.read_image(filename)
|
return self.read_image(filename)
|
||||||
|
@ -381,6 +383,7 @@ class InputOutput:
|
||||||
if self.prompt_session and self.prompt_session.app:
|
if self.prompt_session and self.prompt_session.app:
|
||||||
# Store any partial input before interrupting
|
# Store any partial input before interrupting
|
||||||
self.placeholder = self.prompt_session.app.current_buffer.text
|
self.placeholder = self.prompt_session.app.current_buffer.text
|
||||||
|
self.interrupted = True
|
||||||
self.prompt_session.app.exit()
|
self.prompt_session.app.exit()
|
||||||
|
|
||||||
def get_input(
|
def get_input(
|
||||||
|
@ -394,8 +397,6 @@ class InputOutput:
|
||||||
):
|
):
|
||||||
self.rule()
|
self.rule()
|
||||||
|
|
||||||
self.file_watcher.start()
|
|
||||||
|
|
||||||
rel_fnames = list(rel_fnames)
|
rel_fnames = list(rel_fnames)
|
||||||
show = ""
|
show = ""
|
||||||
if rel_fnames:
|
if rel_fnames:
|
||||||
|
@ -454,6 +455,10 @@ class InputOutput:
|
||||||
default = self.placeholder or ""
|
default = self.placeholder or ""
|
||||||
self.placeholder = None
|
self.placeholder = None
|
||||||
|
|
||||||
|
self.interrupted = False
|
||||||
|
if not multiline_input:
|
||||||
|
self.file_watcher.start()
|
||||||
|
|
||||||
line = self.prompt_session.prompt(
|
line = self.prompt_session.prompt(
|
||||||
show,
|
show,
|
||||||
default=default,
|
default=default,
|
||||||
|
@ -467,10 +472,9 @@ class InputOutput:
|
||||||
line = input(show)
|
line = input(show)
|
||||||
|
|
||||||
# Check if we were interrupted by a file change
|
# Check if we were interrupted by a file change
|
||||||
if changes := self.file_watcher.get_changes():
|
if self.interrupted:
|
||||||
res = process_file_changes(changes)
|
cmd = self.file_watcher.process_changes()
|
||||||
self.file_watcher.changed_files = None
|
return cmd
|
||||||
return res
|
|
||||||
|
|
||||||
except EOFError:
|
except EOFError:
|
||||||
return ""
|
return ""
|
||||||
|
@ -857,25 +861,3 @@ def get_rel_fname(fname, root):
|
||||||
return os.path.relpath(fname, root)
|
return os.path.relpath(fname, root)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return fname
|
return fname
|
||||||
|
|
||||||
|
|
||||||
def process_file_changes(changed):
|
|
||||||
"""Process file changes and handle special ! comments"""
|
|
||||||
|
|
||||||
has_bangs = any(
|
|
||||||
"!" in comment for comments in changed.values() if comments for comment in comments
|
|
||||||
)
|
|
||||||
|
|
||||||
if not has_bangs:
|
|
||||||
return "/add " + " ".join(changed.keys())
|
|
||||||
|
|
||||||
res = "\n".join(comment for comments in changed.values() if comments for comment in comments)
|
|
||||||
res = """The "ai" comments below can be found in the code above.
|
|
||||||
They contain your instructions.
|
|
||||||
Make the requested changes.
|
|
||||||
Also remove all these comments from the code.
|
|
||||||
|
|
||||||
""" + res
|
|
||||||
|
|
||||||
dump(res)
|
|
||||||
return res
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue