Skip to content

Commit

Permalink
get prompt implementation. Rough and needs cleaned
Browse files Browse the repository at this point in the history
  • Loading branch information
TerminalFi committed Aug 16, 2024
1 parent f96ad61 commit c766a79
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 30 deletions.
4 changes: 4 additions & 0 deletions Main.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
"message": "/doc"
}
},
{
"caption": "Copilot: Get Prompt",
"command": "copilot_get_prompt",
},
{
"caption": "Copilot: Fix This",
"command": "copilot_conversation_chat",
Expand Down
2 changes: 2 additions & 0 deletions plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
CopilotConversationTurnDeleteCommand,
CopilotConversationTurnDeleteShimCommand,
CopilotGetPanelCompletionsCommand,
CopilotGetPromptCommand,
CopilotGetVersionCommand,
CopilotNextCompletionCommand,
CopilotPrepareAndEditSettingsCommand,
Expand Down Expand Up @@ -53,6 +54,7 @@
"CopilotClosePanelCompletionCommand",
"CopilotGetPanelCompletionsCommand",
"CopilotGetVersionCommand",
"CopilotGetPromptCommand",
"CopilotNextCompletionCommand",
"CopilotPreviousCompletionCommand",
"CopilotRejectCompletionCommand",
Expand Down
18 changes: 18 additions & 0 deletions plugin/commands.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import json
import os
import uuid
from abc import ABC
Expand Down Expand Up @@ -29,6 +30,7 @@
REQ_CONVERSATION_TURN_DELETE,
REQ_FILE_CHECK_STATUS,
REQ_GET_PANEL_COMPLETIONS,
REQ_GET_PROMPT,
REQ_GET_VERSION,
REQ_NOTIFY_ACCEPTED,
REQ_NOTIFY_REJECTED,
Expand Down Expand Up @@ -568,6 +570,22 @@ def _on_result_conversation_agents(self, payload: list[CopilotRequestConversatio
window.show_quick_panel([[item["slug"], item["description"]] for item in payload], lambda _: None)


class CopilotGetPromptCommand(CopilotTextCommand):
@_provide_plugin_session()
def run(self, plugin: CopilotPlugin, session: Session, _: sublime.Edit) -> None:
doc = prepare_completion_request_doc(self.view)
session.send_request(Request(REQ_GET_PROMPT, {"doc": doc}), self._on_result_get_prompt)

def _on_result_get_prompt(self, payload) -> None:
window = self.view.window()
if not window:
return
prompt_view = window.create_output_panel("prompt_view", unlisted=True)
prompt_view.assign_syntax("scope:source.json")
prompt_view.run_command("append", {"characters": json.dumps(payload, indent=4)})
window.run_command("show_panel", {"panel": "output.prompt_view"})


class CopilotConversationTemplatesCommand(CopilotTextCommand):
@_provide_plugin_session()
def run(self, plugin: CopilotPlugin, session: Session, _: sublime.Edit) -> None:
Expand Down
61 changes: 31 additions & 30 deletions plugin/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,47 @@
# Copilot requests #
# ---------------- #

REQ_CHECK_STATUS = "checkStatus" # done
REQ_FILE_CHECK_STATUS = "checkFileStatus" # done
REQ_GET_COMPLETIONS = "getCompletions" # done
REQ_GET_COMPLETIONS_CYCLING = "getCompletionsCycling" # done
REQ_GET_PANEL_COMPLETIONS = "getPanelCompletions" # done
REQ_GET_VERSION = "getVersion" # done
REQ_NOTIFY_ACCEPTED = "notifyAccepted" # done
REQ_NOTIFY_REJECTED = "notifyRejected" # done
REQ_CHECK_STATUS = "checkStatus"
REQ_FILE_CHECK_STATUS = "checkFileStatus"
REQ_GET_COMPLETIONS = "getCompletions"
REQ_GET_COMPLETIONS_CYCLING = "getCompletionsCycling"
REQ_GET_PROMPT = "getPrompt"
REQ_GET_PANEL_COMPLETIONS = "getPanelCompletions"
REQ_GET_VERSION = "getVersion"
REQ_NOTIFY_ACCEPTED = "notifyAccepted"
REQ_NOTIFY_REJECTED = "notifyRejected"
REQ_NOTIFY_SHOWN = "notifyShown"
REQ_RECORD_TELEMETRY_CONSENT = "recordTelemetryConsent"
REQ_SET_EDITOR_INFO = "setEditorInfo" # done
REQ_SIGN_IN_CONFIRM = "signInConfirm" # done
REQ_SIGN_IN_INITIATE = "signInInitiate" # done
REQ_SIGN_IN_WITH_GITHUB_TOKEN = "signInWithGithubToken" # done
REQ_SIGN_OUT = "signOut" # done
REQ_SET_EDITOR_INFO = "setEditorInfo"
REQ_SIGN_IN_CONFIRM = "signInConfirm"
REQ_SIGN_IN_INITIATE = "signInInitiate"
REQ_SIGN_IN_WITH_GITHUB_TOKEN = "signInWithGithubToken"
REQ_SIGN_OUT = "signOut"

# --------------------- #
# Copilot Chat requests #
# --------------------- #

REQ_CONVERSATION_AGENTS = "conversation/agents" # done
REQ_CONVERSATION_CONTEXT = "conversation/context" # done
REQ_CONVERSATION_COPY_CODE = "conversation/copyCode" # done
REQ_CONVERSATION_CREATE = "conversation/create" # done
REQ_CONVERSATION_DESTROY = "conversation/destroy" # done
REQ_CONVERSATION_INSERT_CODE = "conversation/insertCode" # done
REQ_CONVERSATION_PERSISTANCE = "conversation/persistance" # done
REQ_CONVERSATION_PRECONDITIONS = "conversation/preconditions" # done
REQ_CONVERSATION_RATING = "conversation/rating" # done
REQ_CONVERSATION_TEMPLATES = "conversation/templates" # done
REQ_CONVERSATION_TURN = "conversation/turn" # done
REQ_CONVERSATION_TURN_DELETE = "conversation/turnDelete" # done
REQ_CONVERSATION_AGENTS = "conversation/agents"
REQ_CONVERSATION_CONTEXT = "conversation/context"
REQ_CONVERSATION_COPY_CODE = "conversation/copyCode"
REQ_CONVERSATION_CREATE = "conversation/create"
REQ_CONVERSATION_DESTROY = "conversation/destroy"
REQ_CONVERSATION_INSERT_CODE = "conversation/insertCode"
REQ_CONVERSATION_PERSISTANCE = "conversation/persistance"
REQ_CONVERSATION_PRECONDITIONS = "conversation/preconditions"
REQ_CONVERSATION_RATING = "conversation/rating"
REQ_CONVERSATION_TEMPLATES = "conversation/templates"
REQ_CONVERSATION_TURN = "conversation/turn"
REQ_CONVERSATION_TURN_DELETE = "conversation/turnDelete"

# --------------------- #
# Copilot notifications #
# --------------------- #

NTFY_FEATURE_FLAGS_NOTIFICATION = "featureFlagsNotification" # done
NTFY_LOG_MESSAGE = "LogMessage" # done
NTFY_PANEL_SOLUTION = "PanelSolution" # done
NTFY_PANEL_SOLUTION_DONE = "PanelSolutionsDone" # done
NTFY_FEATURE_FLAGS_NOTIFICATION = "featureFlagsNotification"
NTFY_LOG_MESSAGE = "LogMessage"
NTFY_PANEL_SOLUTION = "PanelSolution"
NTFY_PANEL_SOLUTION_DONE = "PanelSolutionsDone"
NTFY_PROGRESS = "$/progress"
NTFY_STATUS_NOTIFICATION = "statusNotification" # done
NTFY_STATUS_NOTIFICATION = "statusNotification"

0 comments on commit c766a79

Please sign in to comment.