@@ -234,8 +234,7 @@ struct WindowBaseCommandHandler: SuggestionCommandHandler {
234234 func chatWithSelection( editor: EditorContent ) async throws -> UpdatedContent ? {
235235 Task {
236236 do {
237- try await startChatWithSelection (
238- editor: editor,
237+ try await startChat (
239238 specifiedSystemPrompt: nil ,
240239 extraSystemPrompt: nil ,
241240 sendingMessageImmediately: nil ,
@@ -289,8 +288,7 @@ extension WindowBaseCommandHandler {
289288
290289 switch command. feature {
291290 case let . chatWithSelection( extraSystemPrompt, prompt) :
292- try await startChatWithSelection (
293- editor: editor,
291+ try await startChat (
294292 specifiedSystemPrompt: nil ,
295293 extraSystemPrompt: extraSystemPrompt,
296294 sendingMessageImmediately: prompt,
@@ -385,69 +383,6 @@ extension WindowBaseCommandHandler {
385383
386384 presenter. presentPromptToCode ( fileURL: fileURL)
387385 }
388-
389- private func startChatWithSelection(
390- editor: EditorContent ,
391- specifiedSystemPrompt: String ? ,
392- extraSystemPrompt: String ? ,
393- sendingMessageImmediately: String ? ,
394- name: String ?
395- ) async throws {
396- presenter. markAsProcessing ( true )
397- defer { presenter. markAsProcessing ( false ) }
398-
399- let fileURL = try await Environment . fetchCurrentFileURL ( )
400-
401- let code = {
402- guard let selection = editor. selections. last,
403- selection. start != selection. end else { return " " }
404- return editor. selectedCode ( in: selection)
405- } ( )
406-
407- let chat = WidgetDataSource . shared. createChatIfNeeded ( for: fileURL)
408-
409- chat. mutateSystemPrompt ( specifiedSystemPrompt)
410- chat. mutateExtraSystemPrompt ( extraSystemPrompt ?? " " )
411-
412- Task {
413- let customCommandPrefix = {
414- if let name { return " [ \( name) ] " }
415- return " "
416- } ( )
417-
418- if specifiedSystemPrompt != nil {
419- await chat. chatGPTService. mutateHistory { history in
420- history. append ( . init(
421- role: . assistant,
422- content: " " ,
423- summary: " \( customCommandPrefix) System prompt is updated. "
424- ) )
425- }
426- } else if !code. isEmpty, let selection = editor. selections. last {
427- await chat. chatGPTService. mutateHistory { history in
428- history. append ( . init(
429- role: . assistant,
430- content: " " ,
431- summary: " \( customCommandPrefix) Chatting about selected code in ` \( fileURL. lastPathComponent) ` from ` \( selection. start. line + 1 ) : \( selection. start. character + 1 ) ` to ` \( selection. end. line + 1 ) : \( selection. end. character) `. \n The code will persist in the conversation. "
432- ) )
433- }
434- } else if !customCommandPrefix. isEmpty {
435- await chat. chatGPTService. mutateHistory { history in
436- history. append ( . init(
437- role: . assistant,
438- content: " " ,
439- summary: " \( customCommandPrefix) System prompt is updated. "
440- ) )
441- }
442- }
443-
444- if let sendingMessageImmediately, !sendingMessageImmediately. isEmpty {
445- try await chat. send ( content: sendingMessageImmediately)
446- }
447- }
448-
449- presenter. presentChatRoom ( fileURL: fileURL)
450- }
451386
452387 private func startChat(
453388 specifiedSystemPrompt: String ? ,
@@ -459,7 +394,6 @@ extension WindowBaseCommandHandler {
459394 defer { presenter. markAsProcessing ( false ) }
460395
461396 let focusedElementURI = try await Environment . fetchFocusedElementURI ( )
462- let language = UserDefaults . shared. value ( for: \. chatGPTLanguage)
463397
464398 let chat = WidgetDataSource . shared. createChatIfNeeded ( for: focusedElementURI)
465399
@@ -472,15 +406,7 @@ extension WindowBaseCommandHandler {
472406 return " "
473407 } ( )
474408
475- if specifiedSystemPrompt != nil {
476- await chat. chatGPTService. mutateHistory { history in
477- history. append ( . init(
478- role: . assistant,
479- content: " " ,
480- summary: " \( customCommandPrefix) System prompt is updated. "
481- ) )
482- }
483- } else if !customCommandPrefix. isEmpty {
409+ if specifiedSystemPrompt != nil || extraSystemPrompt != nil {
484410 await chat. chatGPTService. mutateHistory { history in
485411 history. append ( . init(
486412 role: . assistant,
0 commit comments