Skip to content

Commit a17c130

Browse files
committed
destroy edit command
1 parent e4520f7 commit a17c130

File tree

4 files changed

+356
-410
lines changed

4 files changed

+356
-410
lines changed

plugin/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
CopilotConversationTurnDeleteCommand,
2929
CopilotConversationTurnDeleteShimCommand,
3030
CopilotEditConversationCreateCommand,
31+
CopilotEditConversationDestroyShimCommand,
32+
CopilotEditConversationDestroyCommand,
3133
CopilotGetPanelCompletionsCommand,
3234
CopilotGetPromptCommand,
3335
CopilotGetVersionCommand,
@@ -60,6 +62,8 @@
6062
"CopilotCheckStatusCommand",
6163
"CopilotCodeReviewCommand",
6264
"CopilotEditConversationCreateCommand",
65+
"CopilotEditConversationDestroyShimCommand",
66+
"CopilotEditConversationDestroyCommand",
6367
"CopilotClosePanelCompletionCommand",
6468
"CopilotConversationAgentsCommand",
6569
"CopilotConversationChatCommand",

plugin/client.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
REQ_GET_VERSION,
3434
REQ_SET_EDITOR_INFO,
3535
REQ_CONTEXT_REGISTER_PROVIDERS,
36-
COPILOT_ACCEPT_SUGGESTION_KINDS,
37-
COPILOT_OUTPUT_PANEL_PREFIX,
3836
REQ_CONVERSATION_AGENTS,
3937
REQ_CONVERSATION_PRECONDITIONS,
4038
REQ_CONVERSATION_TEMPLATES,
@@ -62,6 +60,7 @@
6260
AccountStatus,
6361
CopilotPayloadCompletions,
6462
CopilotPayloadConversationContext,
63+
CopilotPayloadConversationEntry,
6564
CopilotPayloadFeatureFlagsNotification,
6665
CopilotPayloadGetVersion,
6766
CopilotPayloadLogMessage,
@@ -70,10 +69,6 @@
7069
CopilotPayloadStatusNotification,
7170
NetworkProxy,
7271
T_Callable,
73-
CopilotPayloadNotifyShown,
74-
CopilotPayloadSetEditorInfo,
75-
T_AccountStatus,
76-
T_CompletionItem,
7772
)
7873
from .ui import ViewCompletionManager, ViewPanelCompletionManager, WindowConversationManager, WindowEditConversationManager
7974
from .utils import (
@@ -461,7 +456,7 @@ def _create_conversation_entry(
461456
reply: str,
462457
turn_id: str | None = None,
463458
kind: str = "report"
464-
) -> dict[str, Any]:
459+
) -> CopilotPayloadConversationEntry:
465460
"""Helper method to create a standardized conversation entry."""
466461
return {
467462
"kind": kind,
@@ -635,7 +630,7 @@ def _on_get_completions(
635630
vcm.show(completions, 0, get_session_setting(session, "completion_style"))
636631

637632
@notification_handler(REQ_NOTIFY_SHOWN)
638-
def _handle_notify_shown_notification(self, payload: CopilotPayloadNotifyShown) -> None:
633+
def _handle_notify_shown_notification(self, payload: Any) -> None:
639634
pass
640635

641636
@notification_handler(REQ_COPILOT_MODELS)

plugin/commands.py

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
REQ_EDIT_CONVERSATION_CREATE,
6161
REQ_EDIT_CONVERSATION_TURN,
6262
REQ_EDIT_CONVERSATION_TURN_DELETE,
63+
REQ_EDIT_CONVERSATION_DESTROY,
6364
REQ_CONVERSATION_REGISTER_TOOLS,
6465
)
6566
from .decorators import must_be_active_view
@@ -1447,6 +1448,15 @@ def _on_result_edit_conversation_turn_delete(
14471448
view.run_command("copilot_refresh_edit_conversation_panel", {"conversation_id": conversation_id})
14481449
break
14491450

1451+
class CopilotEditConversationDestroyShimCommand(CopilotWindowCommand):
1452+
def run(self, conversation_id: str) -> None:
1453+
wecm = WindowEditConversationManager(self.window)
1454+
if not (view := find_view_by_id(wecm.source_view_id)):
1455+
status_message("Failed to find source view.")
1456+
return
1457+
# Focus the view so that the command runs
1458+
self.window.focus_view(view)
1459+
view.run_command("copilot_edit_conversation_destroy", {"conversation_id": conversation_id})
14501460

14511461
class CopilotEditConversationDestroyCommand(CopilotTextCommand):
14521462
"""Command to destroy an edit conversation."""
@@ -1459,32 +1469,42 @@ def run(
14591469
_: sublime.Edit,
14601470
conversation_id: str
14611471
) -> None:
1472+
if not (
1473+
(window := self.view.window())
1474+
and (wecm := WindowEditConversationManager(window))
1475+
and wecm.conversation_id == conversation_id
1476+
):
1477+
status_message("Failed to find window or edit conversation.")
1478+
return
1479+
14621480
session.send_request(
14631481
Request(
14641482
REQ_EDIT_CONVERSATION_DESTROY,
14651483
{
1466-
"conversationId": conversation_id
1484+
"editConversationId": conversation_id,
1485+
"options": {},
14671486
}
14681487
),
1469-
lambda response: self._on_result_edit_conversation_destroy(conversation_id, response)
1488+
self._on_result_edit_conversation_destroy,
14701489
)
14711490

1472-
def _on_result_edit_conversation_destroy(
1473-
self,
1474-
conversation_id: str,
1475-
payload: Any
1476-
) -> None:
1491+
def _on_result_edit_conversation_destroy(self, payload: str) -> None:
14771492
if not (window := self.view.window()):
1493+
status_message("Failed to find window")
1494+
return
1495+
if payload != "OK":
1496+
status_message("Failed to destroy edit conversation.")
14781497
return
14791498

1480-
# Close and clean up the panel
1481-
panel_name = f"{COPILOT_OUTPUT_PANEL_PREFIX}_edit_{conversation_id[:8]}"
1482-
for view in window.views():
1483-
if view.settings().get('output.name') == panel_name:
1484-
view.close()
1485-
break
1499+
status_message("Destroyed edit conversation.")
1500+
wecm = WindowEditConversationManager(window)
1501+
wecm.close()
1502+
wecm.reset()
14861503

1487-
status_message("Edit conversation destroyed", icon="✅")
1504+
def is_enabled(self, event: dict[Any, Any] | None = None, point: int | None = None) -> bool: # type: ignore
1505+
if not (window := self.view.window()):
1506+
return False
1507+
return bool(WindowEditConversationManager(window).conversation_id)
14881508

14891509

14901510
class CopilotRefreshEditConversationPanelCommand(sublime_plugin.TextCommand):

0 commit comments

Comments
 (0)