Skip to content

Commit

Permalink
feat: support copilot-1.39.0 (#201)
Browse files Browse the repository at this point in the history
Co-authored-by: Jack Cherng <jfcherng@gmail.com>
  • Loading branch information
TerminalFi and jfcherng authored Aug 27, 2024
1 parent 0e0ae63 commit 0555826
Show file tree
Hide file tree
Showing 17 changed files with 280 additions and 91 deletions.
10 changes: 5 additions & 5 deletions LSP-copilot.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
"hook_to_auto_complete_command": false,
"local_checks": false,
"proxy": "",
"telemetry": false,
// The (Jinja2) template of the status bar text which is inside the parentheses `(...)`.
// See https://jinja.palletsprojects.com/templates/
"status_text": "{% if is_copilot_ignored %}{{ is_copilot_ignored }}{% elif is_waiting %}{{ is_waiting }}{% elif server_version %}v{{ server_version }}{% endif %}",
"prompts": [
{
"id": "review",
Expand All @@ -37,7 +33,11 @@
"At last provide a summary of the overall code quality and any general suggestions for improvement.",
]
}
]
],
// The (Jinja2) template of the status bar text which is inside the parentheses `(...)`.
// See https://jinja.palletsprojects.com/templates/
"status_text": "{% if is_copilot_ignored %}{{ is_copilot_ignored }}{% elif is_waiting %}{{ is_waiting }}{% elif server_version %}v{{ server_version }}{% endif %}",
"telemetry": false,
},
// ST4 configuration
"selector": "source | text | embedding"
Expand Down
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
14 changes: 7 additions & 7 deletions language-server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion language-server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"private": true,
"dependencies": {
"copilot-node-server": "^1.38.0"
"copilot-node-server": "^1.39.0"
}
}
4 changes: 4 additions & 0 deletions plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
CopilotConversationRatingCommand,
CopilotConversationRatingShimCommand,
CopilotConversationTemplatesCommand,
CopilotConversationToggleReferencesBlockCommand,
CopilotConversationTurnDeleteCommand,
CopilotConversationTurnDeleteShimCommand,
CopilotGetPanelCompletionsCommand,
CopilotGetPromptCommand,
CopilotGetVersionCommand,
CopilotNextCompletionCommand,
CopilotPrepareAndEditSettingsCommand,
Expand Down Expand Up @@ -53,12 +55,14 @@
"CopilotClosePanelCompletionCommand",
"CopilotGetPanelCompletionsCommand",
"CopilotGetVersionCommand",
"CopilotGetPromptCommand",
"CopilotNextCompletionCommand",
"CopilotPreviousCompletionCommand",
"CopilotRejectCompletionCommand",
"CopilotSignInCommand",
"CopilotSignInWithGithubTokenCommand",
"CopilotSignOutCommand",
"CopilotConversationToggleReferencesBlockCommand",
"CopilotToggleConversationChatCommand",
"CopilotConversationChatShimCommand",
"CopilotConversationChatCommand",
Expand Down
40 changes: 32 additions & 8 deletions plugin/assets/chat_panel.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ html {
--copilot-accept-foreground: var(--foreground);
--copilot-accept-background: var(--background);
--copilot-accept-border: var(--greenish);

--copilot-references-foreground: var(--foreground);
--copilot-references-background: var(--background);
--copilot-references-border: color(var(--foreground) alpha(0.25));
}

.wrapper {
Expand All @@ -20,19 +24,19 @@ html {
color: color(var(--foreground) a(0.25));
}

.wrapper .navbar {
text-align: left;
margin-top: 1rem;
margin-bottom: 2rem;
}

.wrapper .navbar .suggested-title {
display: inline-block;
font-size: 1.2em;
margin-bottom: 1rem;
padding-bottom: 1rem;
}

.wrapper .navbar {
text-align: left;
margin-top: 1rem;
margin-bottom: 1rem;
}

.wrapper .header {
display: block;
margin-bottom: 1rem;
Expand Down Expand Up @@ -114,11 +118,31 @@ html {
.wrapper .icon {
width: 1.25em;
height: 1.25em;
color: var(--foreground)
color: var(--foreground);
}

.wrapper .icon.delete-icon {
width: 1em;
height: 1em;
color: var(--foreground)
color: var(--foreground);
}

.wrapper div.reference {
margin-top: 1rem;
}

.wrapper div.references {
margin-top: 1rem;
border-radius: 3px;
border-style: solid;
border-width: 1px;
border-color: var(--copilot-references-border);
}

.wrapper div .reference_link {
border-radius: 0px;
border-style: none;
border-width: 0px;
font-size: 0.8em;
color: var(--copilot-references-foreground);
}
Binary file added plugin/assets/collapse.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plugin/assets/expand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 40 additions & 4 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 All @@ -17,6 +18,7 @@

from .client import CopilotPlugin
from .constants import (
COPILOT_OUTPUT_PANEL_PREFIX,
PACKAGE_NAME,
REQ_CHECK_STATUS,
REQ_CONVERSATION_AGENTS,
Expand All @@ -29,6 +31,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 @@ -68,6 +71,7 @@
find_window_by_id,
get_session_setting,
message_dialog,
mutable_view,
ok_cancel_dialog,
status_message,
)
Expand Down Expand Up @@ -274,8 +278,10 @@ def _on_result_conversation_preconditions(
"conversationId": wcm.conversation_id,
"reply": msg.split()[0] if is_template else preprocess_message_for_html(msg),
"turnId": str(uuid.uuid4()),
"references": [],
"annotations": [],
"hideText": False,
"warnings": [],
})
session.send_request(
Request(
Expand Down Expand Up @@ -323,17 +329,20 @@ def _on_prompt(self, plugin: CopilotPlugin, session: Session, msg: str):
return
user_prompts: list[CopilotUserDefinedPromptTemplates] = session.config.settings.get("prompts") or []
is_template, msg = preprocess_chat_message(view, msg, user_prompts)
views = [sv.view for sv in session.session_views_async() if sv.view.id() != view.id()]
if not (request := prepare_conversation_turn_request(wcm.conversation_id, wcm.window.id(), msg, view, views)):
return

wcm.append_conversation_entry({
"kind": plugin.get_account_status().user or "user",
"conversationId": wcm.conversation_id,
"reply": msg.split()[0] if is_template else preprocess_message_for_html(msg),
"turnId": str(uuid.uuid4()),
"references": request["references"],
"annotations": [],
"hideText": False,
"warnings": [],
})
if not (request := prepare_conversation_turn_request(wcm.conversation_id, wcm.window.id(), msg, view)):
return

session.send_request(
Request(REQ_CONVERSATION_TURN, request),
lambda _: wcm.prompt(callback=lambda x: self._on_prompt(plugin, session, x)),
Expand Down Expand Up @@ -436,6 +445,16 @@ def is_enabled(self, event: dict[Any, Any] | None = None, point: int | None = No
return bool(WindowConversationManager(window).conversation_id)


class CopilotConversationToggleReferencesBlockCommand(CopilotWindowCommand):
def run(self, window_id: int, conversation_id: str, turn_id: str) -> None:
wcm = WindowConversationManager(self.window)
if conversation_id != wcm.conversation_id:
return

wcm.toggle_references_block(turn_id)
wcm.update()


class CopilotConversationTurnDeleteShimCommand(CopilotWindowCommand):
def run(self, window_id: int, conversation_id: str, turn_id: str) -> None:
wcm = WindowConversationManager(self.window)
Expand Down Expand Up @@ -568,6 +587,24 @@ 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
view = window.create_output_panel(f"{COPILOT_OUTPUT_PANEL_PREFIX}.prompt_view", unlisted=True)

with mutable_view(view) as view:
view.assign_syntax("scope:source.json")
view.run_command("append", {"characters": json.dumps(payload, indent=4)})
window.run_command("show_panel", {"panel": f"output.{COPILOT_OUTPUT_PANEL_PREFIX}.prompt_view"})


class CopilotConversationTemplatesCommand(CopilotTextCommand):
@_provide_plugin_session()
def run(self, plugin: CopilotPlugin, session: Session, _: sublime.Edit) -> None:
Expand Down Expand Up @@ -612,7 +649,6 @@ def run(self, plugin: CopilotPlugin, session: Session, edit: sublime.Edit) -> No
return

vcm.hide()

if not (completion := vcm.current_completion):
return

Expand Down
62 changes: 32 additions & 30 deletions plugin/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# Setting Prefixes #
# ---------------- #

COPILOT_OUTPUT_PANEL_PREFIX = "copilot"
COPILOT_VIEW_SETTINGS_PREFIX = "copilot.completion"
COPILOT_WINDOW_SETTINGS_PREFIX = "copilot"
COPILOT_WINDOW_CONVERSATION_SETTINGS_PREFIX = "copilot.conversation"
Expand All @@ -16,46 +17,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"
Loading

0 comments on commit 0555826

Please sign in to comment.