@@ -6,6 +6,7 @@ import GitHubCopilotService
66import LanguageServerProtocol
77import Logger
88import OpenAIService
9+ import PromptToCodeBasic
910import SuggestionBasic
1011import SuggestionInjector
1112import SuggestionWidget
@@ -364,11 +365,18 @@ extension WindowBaseCommandHandler {
364365
365366 let codeLanguage = languageIdentifierFromFileURL ( fileURL)
366367
367- let ( code, selection) = {
368- guard var selection = editor. selections. last,
369- selection. start != selection. end
370- else { return ( " " , . cursor( editor. cursorPosition) ) }
371-
368+ let snippets = editor. selections. map { selection in
369+ guard selection. start != selection. end else {
370+ return PromptToCodeSnippet (
371+ startLineIndex: selection. start. line,
372+ originalCode: " " ,
373+ modifiedCode: " " ,
374+ description: " " ,
375+ error: " " ,
376+ attachedRange: . init( start: selection. start, end: selection. end)
377+ )
378+ }
379+ var selection = selection
372380 let isMultipleLine = selection. start. line != selection. end. line
373381 let isSpaceOnlyBeforeStartPositionOnTheSameLine = {
374382 guard selection. start. line >= 0 , selection. start. line < editor. lines. count else {
@@ -391,14 +399,16 @@ extension WindowBaseCommandHandler {
391399 // indentation.
392400 selection. start = . init( line: selection. start. line, character: 0 )
393401 }
394- return (
395- editor. selectedCode ( in: selection) ,
396- . init(
397- start: . init( line: selection. start. line, character: selection. start. character) ,
398- end: . init( line: selection. end. line, character: selection. end. character)
399- )
402+ let selectedCode = editor. selectedCode ( in: selection)
403+ return PromptToCodeSnippet (
404+ startLineIndex: selection. start. line,
405+ originalCode: selectedCode,
406+ modifiedCode: selectedCode,
407+ description: " " ,
408+ error: " " ,
409+ attachedRange: . init( start: selection. start, end: selection. end)
400410 )
401- } ( ) as ( String , CursorRange )
411+ }
402412
403413 let store = await Service . shared. guiController. store
404414
@@ -416,7 +426,7 @@ extension WindowBaseCommandHandler {
416426 nil
417427 }
418428
419- _ = await Task { @ MainActor in
429+ _ = await MainActor . run {
420430 store. send ( . promptToCodeGroup( . activateOrCreatePromptToCode( . init(
421431 promptToCodeState: Shared ( . init(
422432 source: . init(
@@ -426,17 +436,17 @@ extension WindowBaseCommandHandler {
426436 content: editor. content,
427437 lines: editor. lines
428438 ) ,
429- originalCode: code,
430- attachedRange: selection,
439+ snippets: IdentifiedArray ( snippets) ,
431440 instruction: newPrompt ?? " " ,
432- extraSystemPrompt: newExtraSystemPrompt ?? " "
441+ extraSystemPrompt: newExtraSystemPrompt ?? " " ,
442+ isAttachedToTarget: false
433443 ) ) ,
434444 indentSize: filespace. codeMetadata. indentSize ?? 4 ,
435445 usesTabsForIndentation: filespace. codeMetadata. usesTabsForIndentation ?? false ,
436446 commandName: name,
437447 isContinuous: isContinuous
438448 ) ) ) )
439- } . result
449+ }
440450 }
441451
442452 func executeSingleRoundDialog(
0 commit comments