Skip to content

Commit 7a4ce3d

Browse files
committed
Adjust prompt to code panel UI
1 parent 0ee5824 commit 7a4ce3d

File tree

7 files changed

+203
-70
lines changed

7 files changed

+203
-70
lines changed

Core/Sources/Service/SuggestionCommandHandler/WindowBaseCommandHandler.swift

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import GitHubCopilotService
66
import LanguageServerProtocol
77
import Logger
88
import OpenAIService
9+
import PromptToCodeBasic
910
import SuggestionBasic
1011
import SuggestionInjector
1112
import 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(

Core/Sources/SuggestionWidget/FeatureReducers/PromptToCodePanel.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public struct PromptToCodePanel {
8080
case modifyCodeCancelled
8181
case cancelButtonTapped
8282
case acceptButtonTapped
83+
case acceptAndContinueButtonTapped
8384
case appendNewLineToPromptButtonTapped
8485
case snippetPanel(IdentifiedActionOf<PromptToCodeSnippetPanel>)
8586
}
@@ -222,14 +223,15 @@ public struct PromptToCodePanel {
222223
return .cancel(id: CancellationKey.modifyCode(state.id))
223224

224225
case .acceptButtonTapped:
225-
let isContinuous = state.isContinuous
226226
return .run { _ in
227227
await commandHandler.acceptPromptToCode()
228-
if !isContinuous {
229-
activatePreviousActiveXcode()
230-
} else {
231-
activateThisApp()
232-
}
228+
activatePreviousActiveXcode()
229+
}
230+
231+
case .acceptAndContinueButtonTapped:
232+
return .run { _ in
233+
await commandHandler.acceptPromptToCode()
234+
activateThisApp()
233235
}
234236

235237
case .appendNewLineToPromptButtonTapped:

0 commit comments

Comments
 (0)