Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impl/debug chat commands #203

Merged
merged 6 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Main.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,9 @@
{
"caption": "Copilot: Send Any Request",
"command": "copilot_send_any_request"
},
{
"caption": "Copilot: Debug Chat Commands",
"command": "copilot_conversation_debug"
}
]
38 changes: 20 additions & 18 deletions plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
CopilotConversationChatShimCommand,
CopilotConversationCloseCommand,
CopilotConversationCopyCodeCommand,
CopilotConversationDebugCommand,
CopilotConversationDestroyCommand,
CopilotConversationDestroyShimCommand,
CopilotConversationInsertCodeCommand,
Expand Down Expand Up @@ -50,35 +51,36 @@
"CopilotAcceptPanelCompletionCommand",
"CopilotAcceptPanelCompletionShimCommand",
"CopilotAskCompletionsCommand",
"CopilotCheckStatusCommand",
"CopilotCheckFileStatusCommand",
"CopilotCheckStatusCommand",
"CopilotClosePanelCompletionCommand",
"CopilotConversationAgentsCommand",
"CopilotConversationChatCommand",
"CopilotConversationChatShimCommand",
"CopilotConversationCloseCommand",
"CopilotConversationCopyCodeCommand",
"CopilotConversationDebugCommand",
"CopilotConversationDestroyCommand",
"CopilotConversationDestroyShimCommand",
"CopilotConversationInsertCodeCommand",
"CopilotConversationInsertCodeShimCommand",
"CopilotConversationRatingCommand",
"CopilotConversationRatingShimCommand",
"CopilotConversationTemplatesCommand",
"CopilotConversationToggleReferencesBlockCommand",
"CopilotConversationTurnDeleteCommand",
"CopilotConversationTurnDeleteShimCommand",
"CopilotGetPanelCompletionsCommand",
"CopilotGetVersionCommand",
"CopilotGetPromptCommand",
"CopilotGetVersionCommand",
"CopilotNextCompletionCommand",
"CopilotPreviousCompletionCommand",
"CopilotRejectCompletionCommand",
"CopilotSendAnyRequestCommand",
"CopilotSignInCommand",
"CopilotSignInWithGithubTokenCommand",
"CopilotSignOutCommand",
"CopilotConversationToggleReferencesBlockCommand",
"CopilotToggleConversationChatCommand",
"CopilotConversationChatShimCommand",
"CopilotConversationChatCommand",
"CopilotConversationCloseCommand",
"CopilotConversationDestroyShimCommand",
"CopilotConversationDestroyCommand",
"CopilotConversationAgentsCommand",
"CopilotConversationTemplatesCommand",
"CopilotConversationTurnDeleteCommand",
"CopilotConversationTurnDeleteShimCommand",
"CopilotConversationRatingShimCommand",
"CopilotConversationRatingCommand",
"CopilotConversationCopyCodeCommand",
"CopilotConversationInsertCodeShimCommand",
"CopilotConversationInsertCodeCommand",
"CopilotSendAnyRequestCommand",
# ST: helper commands
"CopilotPrepareAndEditSettingsCommand",
# ST: event listeners
Expand Down
21 changes: 20 additions & 1 deletion plugin/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from collections.abc import Callable
from functools import partial, wraps
from pathlib import Path
from typing import Any, Literal, cast
from typing import Any, Literal, Sequence, cast

import sublime
import sublime_plugin
Expand Down Expand Up @@ -49,6 +49,7 @@
preprocess_message_for_html,
)
from .types import (
CopilotConversationDebugTemplates,
CopilotPayloadConversationCreate,
CopilotPayloadConversationPreconditions,
CopilotPayloadConversationTemplate,
Expand Down Expand Up @@ -866,6 +867,24 @@ def _on_result_sign_out(self, payload: CopilotPayloadSignOut) -> None:
GithubInfo.clear_avatar()


class CopilotConversationDebugCommand(CopilotTextCommand):
@_provide_plugin_session()
def run(self, plugin: CopilotPlugin, session: Session, _: sublime.Edit) -> None:
if not (window := self.view.window()):
return

templates = tuple(CopilotConversationDebugTemplates)
window.show_quick_panel(
[[template.name, template.value] for template in templates],
lambda index: self._on_selected(index, templates),
)

def _on_selected(self, index: int, templates: Sequence[CopilotConversationDebugTemplates]) -> None:
if index == -1:
return
self.view.run_command("copilot_conversation_chat", {"message": f"{templates[index].value}"})


class CopilotSendAnyRequestCommand(CopilotTextCommand):
@_provide_plugin_session()
def run(self, plugin: CopilotPlugin, session: Session, _: sublime.Edit, request_type: str, payload: str) -> None:
Expand Down
28 changes: 21 additions & 7 deletions plugin/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,7 @@ class CopilotPayloadPanelCompletionSolutionCount(TypedDict, total=True):
# --------------------- #


class CopilotConversationTemplates(StrEnum):
FIX = "/fix"
TESTS = "/tests"
DOC = "/doc"
EXPLAIN = "/explain"
SIMPLIFY = "/simplify"

class CopilotStrEnum(StrEnum):
@classmethod
def has_value(cls, value: str) -> bool:
try:
Expand All @@ -178,6 +172,26 @@ def has_value(cls, value: str) -> bool:
return False


class CopilotConversationTemplates(CopilotStrEnum):
FIX = "/fix"
TESTS = "/tests"
DOC = "/doc"
EXPLAIN = "/explain"
SIMPLIFY = "/simplify"


class CopilotConversationDebugTemplates(CopilotStrEnum):
FAIL = "/debug.fail"
FILTER = "/debug.filter"
DUMP = "/debug.dump"
TREE = "/debug.tree"
ECHO = "/debug.echo"
PROMPT = "/debug.prompt"
SKILLS = "/debug.skills"
VULNERABILITY = "/debug.vulnerability"
MARKDOWN = "/debug.markdown"


class CopilotPayloadConversationEntry(TypedDict, total=True):
kind: str
conversationId: str
Expand Down