Skip to content

Commit

Permalink
Adding a command that can be used to send any command with a payload (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
TerminalFi authored Aug 16, 2024
1 parent ef6bca1 commit de5b16c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Main.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,8 @@
"default": "/* User extra CSS rules: Chat Panel */\n/* CSS rules: https://www.sublimetext.com/docs/minihtml.html#css */\n",
},
},
{
"caption": "Copilot: Send Any Request",
"command": "copilot_send_any_request"
}
]
2 changes: 2 additions & 0 deletions plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
CopilotPrepareAndEditSettingsCommand,
CopilotPreviousCompletionCommand,
CopilotRejectCompletionCommand,
CopilotSendAnyRequestCommand,
CopilotSignInCommand,
CopilotSignInWithGithubTokenCommand,
CopilotSignOutCommand,
Expand Down Expand Up @@ -73,6 +74,7 @@
"CopilotConversationCopyCodeCommand",
"CopilotConversationInsertCodeShimCommand",
"CopilotConversationInsertCodeCommand",
"CopilotSendAnyRequestCommand",
# ST: helper commands
"CopilotPrepareAndEditSettingsCommand",
# ST: event listeners
Expand Down
39 changes: 39 additions & 0 deletions plugin/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -816,3 +816,42 @@ def _on_result_sign_out(self, payload: CopilotPayloadSignOut) -> None:
message_dialog("Sign out OK. Bye!")

GithubInfo.clear_avatar()


class CopilotSendAnyRequestCommand(CopilotTextCommand):
@_provide_plugin_session()
def run(self, plugin: CopilotPlugin, session: Session, _: sublime.Edit, request_type: str, payload: str) -> None:
try:
decode_payload = sublime.decode_value(payload)
except ValueError as e:
message_dialog(f"Failed to parse payload: {e}", is_error_=True)
decode_payload = {}
session.send_request(Request(request_type, decode_payload), self._on_results_any_request)

def _on_results_any_request(self, payload: Any) -> None:
print(payload)

def input(self, args: dict[str, Any]) -> sublime_plugin.CommandInputHandler | None:
return CopilotSendAnyRequestCommandTextInputHandler()


class CopilotSendAnyRequestCommandTextInputHandler(sublime_plugin.TextInputHandler):
def placeholder(self) -> str:
return "Enter type of request. Example: conversation/turn"

def name(self) -> str:
return "request_type"

def next_input(self, args: dict[str, Any]) -> sublime_plugin.CommandInputHandler | None:
return CopilotSendAnyRequestPayloadInputHandler(args)


class CopilotSendAnyRequestPayloadInputHandler(sublime_plugin.TextInputHandler):
def __init__(self, args: dict[str, Any]) -> None:
self.args = args

def placeholder(self) -> str:
return 'Enter payload JSON. Example: {"conversationId": "12345"}'

def name(self) -> str:
return "payload"
16 changes: 14 additions & 2 deletions plugin/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,13 @@ class CopilotPayloadSignInWithGithubToken(TypedDict, total=True):


class CopilotPayloadSignInConfirm(TypedDict, total=True):
status: Literal["AlreadySignedIn", "MaybeOk", "NotAuthorized", "NotSignedIn", "OK"]
status: Literal[
"AlreadySignedIn",
"MaybeOk",
"NotAuthorized",
"NotSignedIn",
"OK",
]
user: str


Expand Down Expand Up @@ -239,7 +245,13 @@ class CopilotPayloadConversationContext(TypedDict, total=True):
"""E.g., `"e3b0d5e3-0c3b-4292-a5ea-15d6003e7c45"`."""
turnId: str
"""E.g., `"09ac7601-6c28-4617-b3e4-13f5ff8502b7"`."""
skillId: Literal["current-editor", "project-labels", "recent-files"] # not the complet list yet
skillId: Literal[
"current-editor",
"project-labels",
"recent-files",
"references",
"problems-in-active-document",
] # not the complet list yet


class CopilotUserDefinedPromptTemplates(TypedDict, total=True):
Expand Down

0 comments on commit de5b16c

Please sign in to comment.