@@ -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 (
0 commit comments