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)
6566from .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
14511461class 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
14901510class CopilotRefreshEditConversationPanelCommand (sublime_plugin .TextCommand ):
0 commit comments