mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-03 19:24:59 +00:00
roughed in faster completions
This commit is contained in:
parent
d403f37469
commit
60e838df9f
2 changed files with 50 additions and 42 deletions
|
@ -5,7 +5,6 @@ import sys
|
|||
from pathlib import Path
|
||||
|
||||
import git
|
||||
from prompt_toolkit.completion import Completion
|
||||
|
||||
from aider import models, prompts, voice
|
||||
from aider.litellm import litellm
|
||||
|
@ -41,11 +40,9 @@ class Commands:
|
|||
models.sanity_check_models(self.io, model)
|
||||
raise SwitchModel(model)
|
||||
|
||||
def completions_model(self, partial):
|
||||
models = litellm.model_cost.keys()
|
||||
for model in models:
|
||||
if partial.lower() in model.lower():
|
||||
yield Completion(model, start_position=-len(partial))
|
||||
def completions_model(self):
|
||||
models = [] # litellm.model_cost.keys()
|
||||
return models
|
||||
|
||||
def cmd_models(self, args):
|
||||
"Search the list of available models"
|
||||
|
@ -82,21 +79,23 @@ class Commands:
|
|||
def is_command(self, inp):
|
||||
return inp[0] in "/!"
|
||||
|
||||
def get_commands(self):
|
||||
commands = []
|
||||
def get_commands(self, with_completions=False):
|
||||
commands = dict()
|
||||
for attr in dir(self):
|
||||
if attr.startswith("cmd_"):
|
||||
commands.append("/" + attr[4:])
|
||||
if not attr.startswith("cmd_"):
|
||||
continue
|
||||
|
||||
cmd = attr[4:]
|
||||
completions = getattr(self, f"completions_{cmd}", None)
|
||||
if completions and with_completions:
|
||||
completions = sorted(completions())
|
||||
else:
|
||||
completions = []
|
||||
|
||||
commands["/" + cmd] = completions
|
||||
|
||||
return commands
|
||||
|
||||
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:
|
||||
for completion in cmd_completions_method(partial):
|
||||
yield completion
|
||||
|
||||
def do_run(self, cmd_name, args):
|
||||
cmd_method_name = f"cmd_{cmd_name}"
|
||||
cmd_method = getattr(self, cmd_method_name, None)
|
||||
|
@ -113,7 +112,7 @@ class Commands:
|
|||
first_word = words[0]
|
||||
rest_inp = inp[len(words[0]) :]
|
||||
|
||||
all_commands = self.get_commands()
|
||||
all_commands = self.get_commands().keys()
|
||||
matching_commands = [cmd for cmd in all_commands if cmd.startswith(first_word)]
|
||||
return matching_commands, first_word, rest_inp
|
||||
|
||||
|
@ -377,12 +376,10 @@ class Commands:
|
|||
fname = f'"{fname}"'
|
||||
return fname
|
||||
|
||||
def completions_add(self, partial):
|
||||
def completions_add(self):
|
||||
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(self.quote_fname(fname), start_position=-len(partial))
|
||||
return files
|
||||
|
||||
def glob_filtered_to_repo(self, pattern):
|
||||
try:
|
||||
|
@ -483,12 +480,9 @@ class Commands:
|
|||
reply = prompts.added_files.format(fnames=", ".join(added_fnames))
|
||||
return reply
|
||||
|
||||
def completions_drop(self, partial):
|
||||
def completions_drop(self):
|
||||
files = self.coder.get_inchat_relative_files()
|
||||
|
||||
for fname in files:
|
||||
if partial.lower() in fname.lower():
|
||||
yield Completion(self.quote_fname(fname), start_position=-len(partial))
|
||||
return files
|
||||
|
||||
def cmd_drop(self, args=""):
|
||||
"Remove files from the chat session to free up context space"
|
||||
|
@ -624,7 +618,7 @@ class Commands:
|
|||
|
||||
def cmd_help(self, args):
|
||||
"Show help about all commands"
|
||||
commands = sorted(self.get_commands())
|
||||
commands = sorted(self.get_commands().keys())
|
||||
for cmd in commands:
|
||||
cmd_method_name = f"cmd_{cmd[1:]}"
|
||||
cmd_method = getattr(self, cmd_method_name, None)
|
||||
|
@ -638,7 +632,7 @@ class Commands:
|
|||
"Show help about all commands in markdown"
|
||||
|
||||
res = ""
|
||||
commands = sorted(self.get_commands())
|
||||
commands = sorted(self.get_commands().keys())
|
||||
for cmd in commands:
|
||||
cmd_method_name = f"cmd_{cmd[1:]}"
|
||||
cmd_method = getattr(self, cmd_method_name, None)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue