mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-30 17:24:59 +00:00
auto-complete filenames
This commit is contained in:
parent
40d764e9f8
commit
5ba084edec
2 changed files with 31 additions and 9 deletions
|
@ -237,8 +237,12 @@ class Coder:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def run_loop(self):
|
def run_loop(self):
|
||||||
rel_fnames = self.get_inchat_relative_files()
|
inp = self.io.get_input(
|
||||||
inp = self.io.get_input(self.root, rel_fnames, self.commands)
|
self.root,
|
||||||
|
self.get_inchat_relative_files(),
|
||||||
|
self.get_addable_relative_files(),
|
||||||
|
self.commands,
|
||||||
|
)
|
||||||
|
|
||||||
self.num_control_c = 0
|
self.num_control_c = 0
|
||||||
|
|
||||||
|
@ -340,9 +344,7 @@ class Coder:
|
||||||
quotes = "".join(['"', "'", "`"])
|
quotes = "".join(['"', "'", "`"])
|
||||||
words = set(word.strip(quotes) for word in words)
|
words = set(word.strip(quotes) for word in words)
|
||||||
|
|
||||||
addable_rel_fnames = set(self.get_all_relative_files()) - set(
|
addable_rel_fnames = self.get_addable_relative_files()
|
||||||
self.get_inchat_relative_files()
|
|
||||||
)
|
|
||||||
|
|
||||||
mentioned_rel_fnames = set()
|
mentioned_rel_fnames = set()
|
||||||
fname_to_rel_fnames = {}
|
fname_to_rel_fnames = {}
|
||||||
|
@ -639,6 +641,9 @@ class Coder:
|
||||||
return 0
|
return 0
|
||||||
return max(Path(path).stat().st_mtime for path in files)
|
return max(Path(path).stat().st_mtime for path in files)
|
||||||
|
|
||||||
|
def get_addable_relative_files(self):
|
||||||
|
return set(self.get_all_relative_files()) - set(self.get_inchat_relative_files())
|
||||||
|
|
||||||
def apply_updates(self, content, inp):
|
def apply_updates(self, content, inp):
|
||||||
try:
|
try:
|
||||||
edited = self.update_files(content, inp)
|
edited = self.update_files(content, inp)
|
||||||
|
|
25
aider/io.py
25
aider/io.py
|
@ -14,11 +14,18 @@ from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
class FileContentCompleter(Completer):
|
class FileContentCompleter(Completer):
|
||||||
def __init__(self, root, rel_fnames, commands):
|
def __init__(self, root, rel_fnames, addable_rel_fnames, commands):
|
||||||
self.commands = commands
|
self.commands = commands
|
||||||
|
self.addable_rel_fnames = addable_rel_fnames
|
||||||
|
self.rel_fnames = rel_fnames
|
||||||
|
|
||||||
self.words = set()
|
self.words = set()
|
||||||
|
for rel_fname in addable_rel_fnames:
|
||||||
|
self.words.add(rel_fname)
|
||||||
|
|
||||||
for rel_fname in rel_fnames:
|
for rel_fname in rel_fnames:
|
||||||
|
self.words.add(rel_fname)
|
||||||
|
|
||||||
fname = os.path.join(root, rel_fname)
|
fname = os.path.join(root, rel_fname)
|
||||||
with open(fname, "r") as f:
|
with open(fname, "r") as f:
|
||||||
content = f.read()
|
content = f.read()
|
||||||
|
@ -52,7 +59,15 @@ class FileContentCompleter(Completer):
|
||||||
|
|
||||||
|
|
||||||
class InputOutput:
|
class InputOutput:
|
||||||
def __init__(self, pretty=True, yes=False, input_history_file=None, chat_history_file=None, input=None, output=None):
|
def __init__(
|
||||||
|
self,
|
||||||
|
pretty=True,
|
||||||
|
yes=False,
|
||||||
|
input_history_file=None,
|
||||||
|
chat_history_file=None,
|
||||||
|
input=None,
|
||||||
|
output=None,
|
||||||
|
):
|
||||||
self.input = input
|
self.input = input
|
||||||
self.output = output
|
self.output = output
|
||||||
self.pretty = pretty
|
self.pretty = pretty
|
||||||
|
@ -71,7 +86,7 @@ class InputOutput:
|
||||||
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
self.append_chat_history(f"\n# aider chat started at {current_time}\n\n")
|
self.append_chat_history(f"\n# aider chat started at {current_time}\n\n")
|
||||||
|
|
||||||
def get_input(self, root, rel_fnames, commands):
|
def get_input(self, root, rel_fnames, addable_rel_fnames, commands):
|
||||||
if self.pretty:
|
if self.pretty:
|
||||||
self.console.rule()
|
self.console.rule()
|
||||||
else:
|
else:
|
||||||
|
@ -89,7 +104,9 @@ class InputOutput:
|
||||||
style = Style.from_dict({"": "green"})
|
style = Style.from_dict({"": "green"})
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
completer_instance = FileContentCompleter(root, rel_fnames, commands)
|
completer_instance = FileContentCompleter(
|
||||||
|
root, rel_fnames, addable_rel_fnames, commands
|
||||||
|
)
|
||||||
if multiline_input:
|
if multiline_input:
|
||||||
show = ". "
|
show = ". "
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue