From b2444b43a6dea64184d5f680c1da07f14327faf6 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Sat, 22 Mar 2025 18:36:10 -0700 Subject: [PATCH] refactor: Pass placeholder to `_generic_chat_command` instead of special-casing context --- aider/commands.py | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/aider/commands.py b/aider/commands.py index fe0d7f8b4..420a36b4a 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -1148,9 +1148,9 @@ class Commands: def cmd_context(self, args): """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(): # Switch to the corresponding chat mode if no args provided return self.cmd_chat_mode(edit_format) @@ -1167,22 +1167,14 @@ class Commands: user_msg = args coder.run(user_msg) - # When using context command, set the placeholder to the args - if edit_format == "context" and args.strip(): - raise SwitchCoder( - edit_format=self.coder.edit_format, - summarize_from_coder=False, - from_coder=coder, - show_announcements=False, - placeholder=args, - ) - else: - raise SwitchCoder( - edit_format=self.coder.edit_format, - summarize_from_coder=False, - from_coder=coder, - show_announcements=False, - ) + # Use the provided placeholder if any + raise SwitchCoder( + edit_format=self.coder.edit_format, + summarize_from_coder=False, + from_coder=coder, + show_announcements=False, + placeholder=placeholder, + ) def get_help_md(self): "Show help about all commands in markdown"