refactor: Pass placeholder to _generic_chat_command instead of special-casing context

This commit is contained in:
Paul Gauthier (aider) 2025-03-22 18:36:10 -07:00
parent be87ff0193
commit b2444b43a6

View file

@ -1148,9 +1148,9 @@ class Commands:
def cmd_context(self, args): def cmd_context(self, args):
"""Enter context mode to see surrounding code context. If no prompt provided, switches to context mode.""" # noqa """Enter context mode to see surrounding code context. If no prompt provided, switches to context mode.""" # noqa
return self._generic_chat_command(args, "context") return self._generic_chat_command(args, "context", placeholder=args.strip() or None)
def _generic_chat_command(self, args, edit_format): def _generic_chat_command(self, args, edit_format, placeholder=None):
if not args.strip(): if not args.strip():
# Switch to the corresponding chat mode if no args provided # Switch to the corresponding chat mode if no args provided
return self.cmd_chat_mode(edit_format) return self.cmd_chat_mode(edit_format)
@ -1167,22 +1167,14 @@ class Commands:
user_msg = args user_msg = args
coder.run(user_msg) coder.run(user_msg)
# When using context command, set the placeholder to the args # Use the provided placeholder if any
if edit_format == "context" and args.strip(): raise SwitchCoder(
raise SwitchCoder( edit_format=self.coder.edit_format,
edit_format=self.coder.edit_format, summarize_from_coder=False,
summarize_from_coder=False, from_coder=coder,
from_coder=coder, show_announcements=False,
show_announcements=False, placeholder=placeholder,
placeholder=args, )
)
else:
raise SwitchCoder(
edit_format=self.coder.edit_format,
summarize_from_coder=False,
from_coder=coder,
show_announcements=False,
)
def get_help_md(self): def get_help_md(self):
"Show help about all commands in markdown" "Show help about all commands in markdown"