Skip to content

Commit 061066b

Browse files
committed
Planned work messages
1 parent a17c130 commit 061066b

File tree

4 files changed

+138
-15
lines changed

4 files changed

+138
-15
lines changed

plugin/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,13 @@ def _handle_edit_description_response(self, wecm: WindowEditConversationManager,
487487
update["editDescription"],
488488
update.get("editTurnId")
489489
)
490+
# Use annotations to store metadata for template processing
491+
status = update.get("fileGenerationStatus")
492+
if status == EDIT_STATUS_PLAN_GENERATED:
493+
entry["annotations"] = ["edit-plan"]
494+
elif status == EDIT_STATUS_OVERALL_DESCRIPTION:
495+
entry["annotations"] = ["edit-description"]
496+
490497
wecm.append_conversation_entry(entry)
491498

492499
def _handle_code_generated_response(self, wecm: WindowEditConversationManager, update: dict[str, Any]) -> None:

plugin/commands.py

Lines changed: 74 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,7 @@ class CopilotEditConversationCreateCommand(CopilotTextCommand):
12301230
"""Command to create a new edit conversation with GitHub Copilot."""
12311231

12321232
@_provide_plugin_session()
1233-
def run(self, plugin: CopilotPlugin, session: Session, _: sublime.Edit) -> None:
1233+
def run(self, plugin: CopilotPlugin, session: Session, _: sublime.Edit, message: str = "") -> None:
12341234
if not (window := self.view.window()):
12351235
return
12361236

@@ -1239,24 +1239,68 @@ def run(self, plugin: CopilotPlugin, session: Session, _: sublime.Edit) -> None:
12391239
status_message("Cannot start edit conversation on an unsaved file", icon="❌")
12401240
return
12411241

1242-
# Get workspace folder if available
1243-
workspace_folder = None
1244-
if window.folders():
1245-
workspace_folder = window.folders()[0]
1242+
wecm = WindowEditConversationManager(window)
1243+
if wecm.conversation_id:
1244+
ui_entry = wecm.get_ui_entry()
1245+
ui_entry.open()
1246+
ui_entry.prompt_for_message(callback=lambda msg: self._on_edit_prompt(plugin, session, msg), initial_text=message)
1247+
return
1248+
1249+
# If no message provided, prompt for it first
1250+
if not message.strip():
1251+
wecm = WindowEditConversationManager(window)
1252+
wecm.source_view_id = self.view.id()
1253+
ui_entry = wecm.get_ui_entry()
1254+
ui_entry.open()
1255+
ui_entry.prompt_for_message(
1256+
callback=lambda msg: self._create_edit_conversation_with_message(plugin, session, msg),
1257+
initial_text=""
1258+
)
1259+
return
1260+
1261+
# Create conversation with the provided message
1262+
self._create_edit_conversation_with_message(plugin, session, message)
1263+
1264+
def _create_edit_conversation_with_message(self, plugin: CopilotPlugin, session: Session, message: str) -> None:
1265+
"""Create a new edit conversation with the specified message."""
1266+
if not (window := self.view.window()):
1267+
return
1268+
1269+
if not message.strip():
1270+
status_message("Please provide a message for the edit conversation", icon="❌")
1271+
return
1272+
1273+
file_uri = filename_to_uri(self.view.file_name() or "")
1274+
if not file_uri:
1275+
status_message("Cannot start edit conversation on an unsaved file", icon="❌")
1276+
return
12461277

12471278
# Prepare the document for the request
12481279
doc = prepare_conversation_edit_request(self.view)
12491280
if not doc:
12501281
status_message("Failed to prepare document for edit conversation", icon="❌")
12511282
return
12521283

1284+
# Add user message to conversation before sending request
12531285
wecm = WindowEditConversationManager(window)
1254-
if wecm.conversation_id:
1255-
print("opening pre-existing")
1256-
ui_entry = wecm.get_ui_entry()
1257-
ui_entry.open()
1258-
ui_entry.prompt_for_message(callback=lambda msg: self._on_edit_prompt(plugin, session, msg), initial_text="")
1259-
return
1286+
wecm.source_view_id = self.view.id()
1287+
is_template, msg = preprocess_chat_message(self.view, message, [])
1288+
# Add the user's message to the conversation
1289+
wecm.append_conversation_entry({
1290+
"kind": plugin.get_account_status().user or "user",
1291+
"conversationId": "", # Will be set when conversation is created
1292+
"reply": preprocess_message_for_html(msg),
1293+
"turnId": str(uuid.uuid4()),
1294+
"references": [],
1295+
"annotations": [],
1296+
"hideText": False,
1297+
"warnings": [],
1298+
})
1299+
1300+
# Update UI to show the user message
1301+
ui_entry = wecm.get_ui_entry()
1302+
ui_entry.update()
1303+
12601304
# Send request to create a new edit conversation
12611305
session.send_request(
12621306
Request(
@@ -1265,7 +1309,7 @@ def run(self, plugin: CopilotPlugin, session: Session, _: sublime.Edit) -> None:
12651309
"partialResultToken": f"copilot_pedit://{window.id()}",
12661310
"turns": [
12671311
{
1268-
"request": "Help me improve this code",
1312+
"request": msg,
12691313
"doc": doc
12701314
}
12711315
],
@@ -1301,9 +1345,12 @@ def _on_result_edit_conversation_create(
13011345
return
13021346

13031347
# The conversation ID will come from progress updates
1304-
# We'll handle it in the progress notification handler
1348+
# Set up the manager and UI for continuous conversation
13051349
wecm = WindowEditConversationManager(window)
13061350
wecm.source_view_id = self.view.id()
1351+
ui_entry = wecm.get_ui_entry()
1352+
ui_entry.open()
1353+
ui_entry.prompt_for_message(callback=lambda msg: self._on_edit_prompt(plugin, session, msg))
13071354

13081355

13091356
def _on_edit_prompt(self, plugin: CopilotPlugin, session: Session, msg: str):
@@ -1320,6 +1367,7 @@ def _on_edit_prompt(self, plugin: CopilotPlugin, session: Session, msg: str):
13201367
status_message("Source view no longer available", icon="❌")
13211368
return
13221369

1370+
is_template, msg = preprocess_chat_message(source_view, msg, [])
13231371
# Get workspace folder if available
13241372
workspace_folder = None
13251373
if window.folders():
@@ -1334,7 +1382,19 @@ def _on_edit_prompt(self, plugin: CopilotPlugin, session: Session, msg: str):
13341382
file_uri = filename_to_uri(source_view.file_name() or "")
13351383

13361384
# Add user message to conversation
1337-
ui_entry.add_user_message(msg)
1385+
wecm.append_conversation_entry({
1386+
"kind": plugin.get_account_status().user or "user",
1387+
"conversationId": wecm.conversation_id,
1388+
"reply": preprocess_message_for_html(msg),
1389+
"turnId": str(uuid.uuid4()),
1390+
"references": [],
1391+
"annotations": [],
1392+
"hideText": False,
1393+
"warnings": [],
1394+
})
1395+
1396+
# Update UI to show the user message
1397+
ui_entry.update()
13381398

13391399
# Send the turn request
13401400
session.send_request(

plugin/templates/edit_conversation.md.jinja

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,49 @@
11
<style>
22
{{ include_asset('chat_panel.css') }}
33
{{ include_asset('chat_panel.custom.css', use_cache=False) }}
4+
5+
/* Edit plan specific styling */
6+
.edit-plan {
7+
margin: 1rem 0;
8+
padding: 0.75rem;
9+
background-color: color(var(--background) blend(var(--foreground) 85%));
10+
border-left: 3px solid var(--bluish);
11+
border-radius: 3px;
12+
}
13+
14+
.edit-plan strong {
15+
color: var(--bluish);
16+
font-weight: bold;
17+
display: block;
18+
margin-bottom: 0.5rem;
19+
}
20+
21+
.edit-plan-content {
22+
color: color(var(--foreground) alpha(0.8));
23+
font-style: italic;
24+
line-height: 1.4;
25+
}
26+
27+
/* Edit description (overall-description-generated) styling */
28+
.edit-description {
29+
margin: 1rem 0;
30+
padding: 0.75rem;
31+
background-color: color(var(--background) blend(var(--foreground) 3%));
32+
border-left: 3px solid var(--greenish);
33+
border-radius: 3px;
34+
}
35+
36+
.edit-description strong {
37+
color: var(--greenish);
38+
font-weight: bold;
39+
display: block;
40+
margin-bottom: 0.5rem;
41+
}
42+
43+
.edit-description-content {
44+
color: color(var(--foreground) alpha(0.9));
45+
line-height: 1.4;
46+
}
447
</style>
548

649
<div class="navbar">
@@ -44,7 +87,19 @@
4487
{%- endif -%}
4588
</div>
4689

90+
{% if "edit-plan" in section.annotations %}
91+
<div class="edit-plan">
92+
<strong>Planned work</strong>
93+
<div class="edit-plan-content">{{ section.message | safe }}</div>
94+
</div>
95+
{% elif "edit-description" in section.annotations %}
96+
<div class="edit-description">
97+
<strong>Overview</strong>
98+
<div class="edit-description-content">{{ section.message | safe }}</div>
99+
</div>
100+
{% else %}
47101
{{ section.message | safe }}
102+
{% endif %}
48103

49104
---
50105

@@ -95,4 +150,4 @@
95150
<div class="waiting-message">
96151
<em>Waiting for Copilot response...</em>
97152
</div>
98-
{% endif %}
153+
{% endif %}

plugin/ui/chat.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ def completion_content(self) -> str:
545545
"kind": entry.get("kind", "unknown"),
546546
"message": entry.get("reply", ""),
547547
"turnId": entry.get("turnId", ""),
548+
"annotations": entry.get("annotations", []),
548549
"thumbs_up_url": sublime.command_url(
549550
"copilot_conversation_rating_shim",
550551
{"turn_id": entry.get("turnId", ""), "rating": 1}

0 commit comments

Comments
 (0)