Skip to content

Commit 33f4d78

Browse files
committed
Update prompt to code
1 parent ebaebb3 commit 33f4d78

File tree

6 files changed

+27
-26
lines changed

6 files changed

+27
-26
lines changed

Core/Sources/Service/GUI/PromptToCodeProvider+Service.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,9 @@ extension PromptToCodeProvider {
7272
onContinuousToggleClick = {
7373
service.isContinuous.toggle()
7474
}
75-
75+
7676
onToggleAttachOrDetachToCode = {
77-
if service.selectionRange != nil {
78-
service.selectionRange = nil
79-
} else {
80-
// reset to selected or focused range.
81-
}
77+
service.toggleAttachOrDetachToCode()
8278
}
8379
}
8480

Core/Sources/Service/GUI/WidgetDataSource.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class WidgetDataSource {
2222
}
2323
}
2424

25-
private(set) var promptToCodes = [URL: PromptToCode]()
25+
private(set) var promptToCode: PromptToCode?
2626

2727
init() {}
2828

@@ -57,7 +57,7 @@ final class WidgetDataSource {
5757
service: service,
5858
name: name,
5959
onClosePromptToCode: { [weak self] in
60-
self?.removePromptToCode(for: url)
60+
self?.removePromptToCode()
6161
let presenter = PresentInWindowSuggestionPresenter()
6262
presenter.closePromptToCode(fileURL: url)
6363
if let app = ActiveApplicationMonitor.shared.previousApp, app.isXcode {
@@ -72,16 +72,16 @@ final class WidgetDataSource {
7272
}
7373

7474
let newPromptToCode = build()
75-
promptToCodes[url] = newPromptToCode
75+
promptToCode = newPromptToCode
7676
return newPromptToCode.promptToCodeService
7777
}
7878

79-
func removePromptToCode(for url: URL) {
80-
promptToCodes[url] = nil
79+
func removePromptToCode() {
80+
promptToCode = nil
8181
}
8282

8383
func cleanup(for url: URL) {
84-
removePromptToCode(for: url)
84+
// removePromptToCode(for: url)
8585
}
8686
}
8787

@@ -140,7 +140,7 @@ extension WidgetDataSource: SuggestionWidgetDataSource {
140140
}
141141

142142
func promptToCodeForFile(at url: URL) async -> PromptToCodeProvider? {
143-
return promptToCodes[url]?.provider
143+
return promptToCode?.provider
144144
}
145145
}
146146

Core/Sources/Service/SuggestionCommandHandler/WindowBaseCommandHandler.swift

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,6 @@ struct WindowBaseCommandHandler: SuggestionCommandHandler {
136136
defer { presenter.markAsProcessing(false) }
137137
let fileURL = try await Environment.fetchCurrentFileURL()
138138

139-
let dataSource = Service.shared.guiController.widgetDataSource
140-
141-
if await dataSource.promptToCodes[fileURL]?.promptToCodeService != nil {
142-
await dataSource.removePromptToCode(for: fileURL)
143-
presenter.closePromptToCode(fileURL: fileURL)
144-
return
145-
}
146-
147139
let (workspace, _) = try await Service.shared.workspacePool
148140
.fetchOrCreateWorkspaceAndFilespace(fileURL: fileURL)
149141
workspace.rejectSuggestion(forFileAt: fileURL, editor: editor)
@@ -164,8 +156,6 @@ struct WindowBaseCommandHandler: SuggestionCommandHandler {
164156
var cursorPosition = editor.cursorPosition
165157
var extraInfo = SuggestionInjector.ExtraInfo()
166158

167-
let dataSource = Service.shared.guiController.widgetDataSource
168-
169159
if let acceptedSuggestion = workspace.acceptSuggestion(
170160
forFileAt: fileURL,
171161
editor: editor
@@ -202,7 +192,7 @@ struct WindowBaseCommandHandler: SuggestionCommandHandler {
202192

203193
let dataSource = Service.shared.guiController.widgetDataSource
204194

205-
if let service = await dataSource.promptToCodes[fileURL]?.promptToCodeService {
195+
if let service = await dataSource.promptToCode?.promptToCodeService {
206196
let rangeStart = service.selectionRange?.start ?? editor.cursorPosition
207197

208198
let suggestion = CodeSuggestion(
@@ -230,7 +220,7 @@ struct WindowBaseCommandHandler: SuggestionCommandHandler {
230220
)
231221
presenter.presentPromptToCode(fileURL: fileURL)
232222
} else {
233-
await dataSource.removePromptToCode(for: fileURL)
223+
await dataSource.removePromptToCode()
234224
presenter.closePromptToCode(fileURL: fileURL)
235225
}
236226

Core/Sources/Service/XPCService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public class XPCService: NSObject, XPCServiceProtocol {
108108
withReply reply: @escaping (Data?, Error?) -> Void
109109
) {
110110
replyWithUpdatedContent(editorContent: editorContent, withReply: reply) { handler, editor in
111-
try await handler.acceptSuggestion(editor: editor)
111+
try await handler.acceptPromptToCode(editor: editor)
112112
}
113113
}
114114

Core/Tests/ActiveDocumentChatContextCollectorTests/SwiftFocusedCodeFinderTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Foundation
22
import SuggestionModel
33
import XCTest
4+
import FocusedCodeFinder
45

56
@testable import ActiveDocumentChatContextCollector
67

Tool/Sources/FocusedCodeFinder/FocusedCodeFinder.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ public struct CodeContext: Equatable {
2828
public static var empty: CodeContext {
2929
.init(scope: .file, contextRange: .zero, focusedRange: .zero, focusedCode: "", imports: [])
3030
}
31+
32+
public init(
33+
scope: Scope,
34+
contextRange: CursorRange,
35+
focusedRange: CursorRange,
36+
focusedCode: String,
37+
imports: [String]
38+
) {
39+
self.scope = scope
40+
self.contextRange = contextRange
41+
self.focusedRange = focusedRange
42+
self.focusedCode = focusedCode
43+
self.imports = imports
44+
}
3145
}
3246

3347
public protocol FocusedCodeFinder {

0 commit comments

Comments
 (0)