Skip to content

Commit 575b255

Browse files
authored
fix: /explain (and others) doesn't work (#197)
1 parent 31b5bc1 commit 575b255

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

plugin/helpers.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from .log import log_error
2121
from .settings import get_plugin_setting_dotted
2222
from .types import (
23+
CopilotConversationTemplates,
2324
CopilotDocType,
2425
CopilotPayloadCompletion,
2526
CopilotPayloadPanelSolution,
@@ -284,10 +285,8 @@ def preprocess_chat_message(
284285

285286
templates = templates or []
286287
user_template = first_true(templates, pred=lambda t: f"/{t['id']}" == message)
287-
is_template = False
288288

289-
if user_template:
290-
is_template = True
289+
if is_template := bool(user_template or CopilotConversationTemplates.has_value(message)):
291290
message += "\n\n{{ user_prompt }}\n\n{{ code }}"
292291

293292
region = view.sel()[0]

plugin/types.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,14 @@ class CopilotConversationTemplates(StrEnum):
163163
EXPLAIN = "/explain"
164164
SIMPLIFY = "/simplify"
165165

166+
@classmethod
167+
def has_value(cls, value: str) -> bool:
168+
try:
169+
cls(value)
170+
return True
171+
except ValueError:
172+
return False
173+
166174

167175
class CopilotPayloadConversationEntry(TypedDict, total=True):
168176
kind: str

0 commit comments

Comments
 (0)