From 575b25542f99f56546ffb2d712686c36104a63c8 Mon Sep 17 00:00:00 2001 From: Jack Cherng Date: Tue, 13 Aug 2024 10:59:42 +0800 Subject: [PATCH] fix: `/explain` (and others) doesn't work (#197) --- plugin/helpers.py | 5 ++--- plugin/types.py | 8 ++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/plugin/helpers.py b/plugin/helpers.py index 840f52b..2adcfeb 100644 --- a/plugin/helpers.py +++ b/plugin/helpers.py @@ -20,6 +20,7 @@ from .log import log_error from .settings import get_plugin_setting_dotted from .types import ( + CopilotConversationTemplates, CopilotDocType, CopilotPayloadCompletion, CopilotPayloadPanelSolution, @@ -284,10 +285,8 @@ def preprocess_chat_message( templates = templates or [] user_template = first_true(templates, pred=lambda t: f"/{t['id']}" == message) - is_template = False - if user_template: - is_template = True + if is_template := bool(user_template or CopilotConversationTemplates.has_value(message)): message += "\n\n{{ user_prompt }}\n\n{{ code }}" region = view.sel()[0] diff --git a/plugin/types.py b/plugin/types.py index 5ba6ddc..566c744 100644 --- a/plugin/types.py +++ b/plugin/types.py @@ -163,6 +163,14 @@ class CopilotConversationTemplates(StrEnum): EXPLAIN = "/explain" SIMPLIFY = "/simplify" + @classmethod + def has_value(cls, value: str) -> bool: + try: + cls(value) + return True + except ValueError: + return False + class CopilotPayloadConversationEntry(TypedDict, total=True): kind: str