Skip to content

Commit 0555826

Browse files
TerminalFijfcherng
andauthored
feat: support copilot-1.39.0 (#201)
Co-authored-by: Jack Cherng <[email protected]>
1 parent 0e0ae63 commit 0555826

File tree

17 files changed

+280
-91
lines changed

17 files changed

+280
-91
lines changed

LSP-copilot.sublime-settings

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
"hook_to_auto_complete_command": false,
1818
"local_checks": false,
1919
"proxy": "",
20-
"telemetry": false,
21-
// The (Jinja2) template of the status bar text which is inside the parentheses `(...)`.
22-
// See https://jinja.palletsprojects.com/templates/
23-
"status_text": "{% if is_copilot_ignored %}{{ is_copilot_ignored }}{% elif is_waiting %}{{ is_waiting }}{% elif server_version %}v{{ server_version }}{% endif %}",
2420
"prompts": [
2521
{
2622
"id": "review",
@@ -37,7 +33,11 @@
3733
"At last provide a summary of the overall code quality and any general suggestions for improvement.",
3834
]
3935
}
40-
]
36+
],
37+
// The (Jinja2) template of the status bar text which is inside the parentheses `(...)`.
38+
// See https://jinja.palletsprojects.com/templates/
39+
"status_text": "{% if is_copilot_ignored %}{{ is_copilot_ignored }}{% elif is_waiting %}{{ is_waiting }}{% elif server_version %}v{{ server_version }}{% endif %}",
40+
"telemetry": false,
4141
},
4242
// ST4 configuration
4343
"selector": "source | text | embedding"

Main.sublime-commands

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
"message": "/doc"
2525
}
2626
},
27+
{
28+
"caption": "Copilot: Get Prompt",
29+
"command": "copilot_get_prompt",
30+
},
2731
{
2832
"caption": "Copilot: Fix This",
2933
"command": "copilot_conversation_chat",

language-server/package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

language-server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"private": true,
33
"dependencies": {
4-
"copilot-node-server": "^1.38.0"
4+
"copilot-node-server": "^1.39.0"
55
}
66
}

plugin/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121
CopilotConversationRatingCommand,
2222
CopilotConversationRatingShimCommand,
2323
CopilotConversationTemplatesCommand,
24+
CopilotConversationToggleReferencesBlockCommand,
2425
CopilotConversationTurnDeleteCommand,
2526
CopilotConversationTurnDeleteShimCommand,
2627
CopilotGetPanelCompletionsCommand,
28+
CopilotGetPromptCommand,
2729
CopilotGetVersionCommand,
2830
CopilotNextCompletionCommand,
2931
CopilotPrepareAndEditSettingsCommand,
@@ -53,12 +55,14 @@
5355
"CopilotClosePanelCompletionCommand",
5456
"CopilotGetPanelCompletionsCommand",
5557
"CopilotGetVersionCommand",
58+
"CopilotGetPromptCommand",
5659
"CopilotNextCompletionCommand",
5760
"CopilotPreviousCompletionCommand",
5861
"CopilotRejectCompletionCommand",
5962
"CopilotSignInCommand",
6063
"CopilotSignInWithGithubTokenCommand",
6164
"CopilotSignOutCommand",
65+
"CopilotConversationToggleReferencesBlockCommand",
6266
"CopilotToggleConversationChatCommand",
6367
"CopilotConversationChatShimCommand",
6468
"CopilotConversationChatCommand",

plugin/assets/chat_panel.css

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ html {
1010
--copilot-accept-foreground: var(--foreground);
1111
--copilot-accept-background: var(--background);
1212
--copilot-accept-border: var(--greenish);
13+
14+
--copilot-references-foreground: var(--foreground);
15+
--copilot-references-background: var(--background);
16+
--copilot-references-border: color(var(--foreground) alpha(0.25));
1317
}
1418

1519
.wrapper {
@@ -20,19 +24,19 @@ html {
2024
color: color(var(--foreground) a(0.25));
2125
}
2226

27+
.wrapper .navbar {
28+
text-align: left;
29+
margin-top: 1rem;
30+
margin-bottom: 2rem;
31+
}
32+
2333
.wrapper .navbar .suggested-title {
2434
display: inline-block;
2535
font-size: 1.2em;
2636
margin-bottom: 1rem;
2737
padding-bottom: 1rem;
2838
}
2939

30-
.wrapper .navbar {
31-
text-align: left;
32-
margin-top: 1rem;
33-
margin-bottom: 1rem;
34-
}
35-
3640
.wrapper .header {
3741
display: block;
3842
margin-bottom: 1rem;
@@ -114,11 +118,31 @@ html {
114118
.wrapper .icon {
115119
width: 1.25em;
116120
height: 1.25em;
117-
color: var(--foreground)
121+
color: var(--foreground);
118122
}
119123

120124
.wrapper .icon.delete-icon {
121125
width: 1em;
122126
height: 1em;
123-
color: var(--foreground)
127+
color: var(--foreground);
128+
}
129+
130+
.wrapper div.reference {
131+
margin-top: 1rem;
132+
}
133+
134+
.wrapper div.references {
135+
margin-top: 1rem;
136+
border-radius: 3px;
137+
border-style: solid;
138+
border-width: 1px;
139+
border-color: var(--copilot-references-border);
140+
}
141+
142+
.wrapper div .reference_link {
143+
border-radius: 0px;
144+
border-style: none;
145+
border-width: 0px;
146+
font-size: 0.8em;
147+
color: var(--copilot-references-foreground);
124148
}

plugin/assets/collapse.png

235 Bytes
Loading

plugin/assets/expand.png

192 Bytes
Loading

plugin/commands.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import json
34
import os
45
import uuid
56
from abc import ABC
@@ -17,6 +18,7 @@
1718

1819
from .client import CopilotPlugin
1920
from .constants import (
21+
COPILOT_OUTPUT_PANEL_PREFIX,
2022
PACKAGE_NAME,
2123
REQ_CHECK_STATUS,
2224
REQ_CONVERSATION_AGENTS,
@@ -29,6 +31,7 @@
2931
REQ_CONVERSATION_TURN_DELETE,
3032
REQ_FILE_CHECK_STATUS,
3133
REQ_GET_PANEL_COMPLETIONS,
34+
REQ_GET_PROMPT,
3235
REQ_GET_VERSION,
3336
REQ_NOTIFY_ACCEPTED,
3437
REQ_NOTIFY_REJECTED,
@@ -68,6 +71,7 @@
6871
find_window_by_id,
6972
get_session_setting,
7073
message_dialog,
74+
mutable_view,
7175
ok_cancel_dialog,
7276
status_message,
7377
)
@@ -274,8 +278,10 @@ def _on_result_conversation_preconditions(
274278
"conversationId": wcm.conversation_id,
275279
"reply": msg.split()[0] if is_template else preprocess_message_for_html(msg),
276280
"turnId": str(uuid.uuid4()),
281+
"references": [],
277282
"annotations": [],
278283
"hideText": False,
284+
"warnings": [],
279285
})
280286
session.send_request(
281287
Request(
@@ -323,17 +329,20 @@ def _on_prompt(self, plugin: CopilotPlugin, session: Session, msg: str):
323329
return
324330
user_prompts: list[CopilotUserDefinedPromptTemplates] = session.config.settings.get("prompts") or []
325331
is_template, msg = preprocess_chat_message(view, msg, user_prompts)
332+
views = [sv.view for sv in session.session_views_async() if sv.view.id() != view.id()]
333+
if not (request := prepare_conversation_turn_request(wcm.conversation_id, wcm.window.id(), msg, view, views)):
334+
return
335+
326336
wcm.append_conversation_entry({
327337
"kind": plugin.get_account_status().user or "user",
328338
"conversationId": wcm.conversation_id,
329339
"reply": msg.split()[0] if is_template else preprocess_message_for_html(msg),
330340
"turnId": str(uuid.uuid4()),
341+
"references": request["references"],
331342
"annotations": [],
332343
"hideText": False,
344+
"warnings": [],
333345
})
334-
if not (request := prepare_conversation_turn_request(wcm.conversation_id, wcm.window.id(), msg, view)):
335-
return
336-
337346
session.send_request(
338347
Request(REQ_CONVERSATION_TURN, request),
339348
lambda _: wcm.prompt(callback=lambda x: self._on_prompt(plugin, session, x)),
@@ -436,6 +445,16 @@ def is_enabled(self, event: dict[Any, Any] | None = None, point: int | None = No
436445
return bool(WindowConversationManager(window).conversation_id)
437446

438447

448+
class CopilotConversationToggleReferencesBlockCommand(CopilotWindowCommand):
449+
def run(self, window_id: int, conversation_id: str, turn_id: str) -> None:
450+
wcm = WindowConversationManager(self.window)
451+
if conversation_id != wcm.conversation_id:
452+
return
453+
454+
wcm.toggle_references_block(turn_id)
455+
wcm.update()
456+
457+
439458
class CopilotConversationTurnDeleteShimCommand(CopilotWindowCommand):
440459
def run(self, window_id: int, conversation_id: str, turn_id: str) -> None:
441460
wcm = WindowConversationManager(self.window)
@@ -568,6 +587,24 @@ def _on_result_conversation_agents(self, payload: list[CopilotRequestConversatio
568587
window.show_quick_panel([[item["slug"], item["description"]] for item in payload], lambda _: None)
569588

570589

590+
class CopilotGetPromptCommand(CopilotTextCommand):
591+
@_provide_plugin_session()
592+
def run(self, plugin: CopilotPlugin, session: Session, _: sublime.Edit) -> None:
593+
doc = prepare_completion_request_doc(self.view)
594+
session.send_request(Request(REQ_GET_PROMPT, {"doc": doc}), self._on_result_get_prompt)
595+
596+
def _on_result_get_prompt(self, payload) -> None:
597+
window = self.view.window()
598+
if not window:
599+
return
600+
view = window.create_output_panel(f"{COPILOT_OUTPUT_PANEL_PREFIX}.prompt_view", unlisted=True)
601+
602+
with mutable_view(view) as view:
603+
view.assign_syntax("scope:source.json")
604+
view.run_command("append", {"characters": json.dumps(payload, indent=4)})
605+
window.run_command("show_panel", {"panel": f"output.{COPILOT_OUTPUT_PANEL_PREFIX}.prompt_view"})
606+
607+
571608
class CopilotConversationTemplatesCommand(CopilotTextCommand):
572609
@_provide_plugin_session()
573610
def run(self, plugin: CopilotPlugin, session: Session, _: sublime.Edit) -> None:
@@ -612,7 +649,6 @@ def run(self, plugin: CopilotPlugin, session: Session, edit: sublime.Edit) -> No
612649
return
613650

614651
vcm.hide()
615-
616652
if not (completion := vcm.current_completion):
617653
return
618654

plugin/constants.py

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# Setting Prefixes #
99
# ---------------- #
1010

11+
COPILOT_OUTPUT_PANEL_PREFIX = "copilot"
1112
COPILOT_VIEW_SETTINGS_PREFIX = "copilot.completion"
1213
COPILOT_WINDOW_SETTINGS_PREFIX = "copilot"
1314
COPILOT_WINDOW_CONVERSATION_SETTINGS_PREFIX = "copilot.conversation"
@@ -16,46 +17,47 @@
1617
# Copilot requests #
1718
# ---------------- #
1819

19-
REQ_CHECK_STATUS = "checkStatus" # done
20-
REQ_FILE_CHECK_STATUS = "checkFileStatus" # done
21-
REQ_GET_COMPLETIONS = "getCompletions" # done
22-
REQ_GET_COMPLETIONS_CYCLING = "getCompletionsCycling" # done
23-
REQ_GET_PANEL_COMPLETIONS = "getPanelCompletions" # done
24-
REQ_GET_VERSION = "getVersion" # done
25-
REQ_NOTIFY_ACCEPTED = "notifyAccepted" # done
26-
REQ_NOTIFY_REJECTED = "notifyRejected" # done
20+
REQ_CHECK_STATUS = "checkStatus"
21+
REQ_FILE_CHECK_STATUS = "checkFileStatus"
22+
REQ_GET_COMPLETIONS = "getCompletions"
23+
REQ_GET_COMPLETIONS_CYCLING = "getCompletionsCycling"
24+
REQ_GET_PROMPT = "getPrompt"
25+
REQ_GET_PANEL_COMPLETIONS = "getPanelCompletions"
26+
REQ_GET_VERSION = "getVersion"
27+
REQ_NOTIFY_ACCEPTED = "notifyAccepted"
28+
REQ_NOTIFY_REJECTED = "notifyRejected"
2729
REQ_NOTIFY_SHOWN = "notifyShown"
2830
REQ_RECORD_TELEMETRY_CONSENT = "recordTelemetryConsent"
29-
REQ_SET_EDITOR_INFO = "setEditorInfo" # done
30-
REQ_SIGN_IN_CONFIRM = "signInConfirm" # done
31-
REQ_SIGN_IN_INITIATE = "signInInitiate" # done
32-
REQ_SIGN_IN_WITH_GITHUB_TOKEN = "signInWithGithubToken" # done
33-
REQ_SIGN_OUT = "signOut" # done
31+
REQ_SET_EDITOR_INFO = "setEditorInfo"
32+
REQ_SIGN_IN_CONFIRM = "signInConfirm"
33+
REQ_SIGN_IN_INITIATE = "signInInitiate"
34+
REQ_SIGN_IN_WITH_GITHUB_TOKEN = "signInWithGithubToken"
35+
REQ_SIGN_OUT = "signOut"
3436

3537
# --------------------- #
3638
# Copilot Chat requests #
3739
# --------------------- #
3840

39-
REQ_CONVERSATION_AGENTS = "conversation/agents" # done
40-
REQ_CONVERSATION_CONTEXT = "conversation/context" # done
41-
REQ_CONVERSATION_COPY_CODE = "conversation/copyCode" # done
42-
REQ_CONVERSATION_CREATE = "conversation/create" # done
43-
REQ_CONVERSATION_DESTROY = "conversation/destroy" # done
44-
REQ_CONVERSATION_INSERT_CODE = "conversation/insertCode" # done
45-
REQ_CONVERSATION_PERSISTANCE = "conversation/persistance" # done
46-
REQ_CONVERSATION_PRECONDITIONS = "conversation/preconditions" # done
47-
REQ_CONVERSATION_RATING = "conversation/rating" # done
48-
REQ_CONVERSATION_TEMPLATES = "conversation/templates" # done
49-
REQ_CONVERSATION_TURN = "conversation/turn" # done
50-
REQ_CONVERSATION_TURN_DELETE = "conversation/turnDelete" # done
41+
REQ_CONVERSATION_AGENTS = "conversation/agents"
42+
REQ_CONVERSATION_CONTEXT = "conversation/context"
43+
REQ_CONVERSATION_COPY_CODE = "conversation/copyCode"
44+
REQ_CONVERSATION_CREATE = "conversation/create"
45+
REQ_CONVERSATION_DESTROY = "conversation/destroy"
46+
REQ_CONVERSATION_INSERT_CODE = "conversation/insertCode"
47+
REQ_CONVERSATION_PERSISTANCE = "conversation/persistance"
48+
REQ_CONVERSATION_PRECONDITIONS = "conversation/preconditions"
49+
REQ_CONVERSATION_RATING = "conversation/rating"
50+
REQ_CONVERSATION_TEMPLATES = "conversation/templates"
51+
REQ_CONVERSATION_TURN = "conversation/turn"
52+
REQ_CONVERSATION_TURN_DELETE = "conversation/turnDelete"
5153

5254
# --------------------- #
5355
# Copilot notifications #
5456
# --------------------- #
5557

56-
NTFY_FEATURE_FLAGS_NOTIFICATION = "featureFlagsNotification" # done
57-
NTFY_LOG_MESSAGE = "LogMessage" # done
58-
NTFY_PANEL_SOLUTION = "PanelSolution" # done
59-
NTFY_PANEL_SOLUTION_DONE = "PanelSolutionsDone" # done
58+
NTFY_FEATURE_FLAGS_NOTIFICATION = "featureFlagsNotification"
59+
NTFY_LOG_MESSAGE = "LogMessage"
60+
NTFY_PANEL_SOLUTION = "PanelSolution"
61+
NTFY_PANEL_SOLUTION_DONE = "PanelSolutionsDone"
6062
NTFY_PROGRESS = "$/progress"
61-
NTFY_STATUS_NOTIFICATION = "statusNotification" # done
63+
NTFY_STATUS_NOTIFICATION = "statusNotification"

0 commit comments

Comments
 (0)