mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-25 23:05:00 +00:00
improved completions for /add and /drop
This commit is contained in:
parent
923e42c176
commit
42ccd9c550
3 changed files with 24 additions and 11 deletions
|
@ -1,5 +1,6 @@
|
|||
import os
|
||||
from rich.text import Text
|
||||
from prompt_toolkit.completion import Completion
|
||||
|
||||
|
||||
class Commands:
|
||||
|
@ -35,11 +36,12 @@ class Commands:
|
|||
else:
|
||||
self.console.print(f"Error: Command {cmd_name} not found.")
|
||||
|
||||
def get_command_completions(self, cmd_name):
|
||||
def get_command_completions(self, cmd_name, partial):
|
||||
cmd_completions_method_name = f"completions_{cmd_name}"
|
||||
cmd_completions_method = getattr(self, cmd_completions_method_name, None)
|
||||
if cmd_completions_method:
|
||||
return set(cmd_completions_method())
|
||||
for completion in cmd_completions_method(partial):
|
||||
yield completion
|
||||
|
||||
def run(self, inp):
|
||||
words = inp.strip().split()
|
||||
|
@ -143,13 +145,19 @@ class Commands:
|
|||
else:
|
||||
self.console.print(f"[red]{matched_file} is already in the chat")
|
||||
|
||||
def completions_add(self):
|
||||
res = set(self.coder.get_all_relative_files())
|
||||
res = res - set(self.coder.get_inchat_relative_files())
|
||||
return res
|
||||
def completions_add(self, partial):
|
||||
files = set(self.coder.get_all_relative_files())
|
||||
files = files - set(self.coder.get_inchat_relative_files())
|
||||
for fname in files:
|
||||
if partial.lower() in fname.lower():
|
||||
yield Completion(fname, start_position=-len(partial))
|
||||
|
||||
def completions_drop(self):
|
||||
return self.coder.get_inchat_relative_files()
|
||||
def completions_drop(self, partial):
|
||||
files = self.coder.get_inchat_relative_files()
|
||||
|
||||
for fname in files:
|
||||
if partial.lower() in fname.lower():
|
||||
yield Completion(fname, start_position=-len(partial))
|
||||
|
||||
def cmd_drop(self, args):
|
||||
"Remove matching files from the chat"
|
||||
|
|
|
@ -35,7 +35,11 @@ class FileContentCompleter(Completer):
|
|||
if len(words) == 1 and not text[-1].isspace():
|
||||
candidates = self.commands.get_commands()
|
||||
else:
|
||||
candidates = self.commands.get_command_completions(words[0][1:])
|
||||
for completion in self.commands.get_command_completions(
|
||||
words[0][1:], words[-1]
|
||||
):
|
||||
yield completion
|
||||
return
|
||||
else:
|
||||
candidates = self.words
|
||||
|
||||
|
|
|
@ -21,8 +21,6 @@ class Foo:
|
|||
Take requests from the user for new features, improvements, bug fixes and other changes to the supplied code.
|
||||
If the user's request is ambiguous, ask questions to fully understand.
|
||||
|
||||
IF THE FILES DON'T CONTAIN THE RELEVANT CODE, SAY SO!
|
||||
|
||||
Once you understand the user's request and can see all the relevant code, your responses MUST be:
|
||||
|
||||
1. Briefly explain the needed changes.
|
||||
|
@ -47,6 +45,9 @@ some/dir/example.py
|
|||
"""Multiplies 2 numbers"""
|
||||
>>>>>>> UPDATED
|
||||
|
||||
If need to see the contents of a file from the git repo, ask the user!
|
||||
Don't edit a listed file without looking at the contents first!
|
||||
|
||||
You can make a new file by replying with an ORIGINAL/UPDATE that has an empty ORIGINAL block.
|
||||
|
||||
*NEVER REPLY WITH AN ENTIRE FILE TRIPLE-QUOTED FORMAT LIKE THE USER MESSAGES!*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue