Skip to content

Commit d91f277

Browse files
committed
Add settings for prompt to code provider
1 parent 75d7c7f commit d91f277

File tree

4 files changed

+40
-1
lines changed

4 files changed

+40
-1
lines changed

Copilot for Xcode/SettingsView.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ struct SettingsView: View {
2222
var disableSuggestionFeatureGlobally: Bool
2323
@AppStorage(\.suggestionFeatureEnabledProjectList)
2424
var suggestionFeatureEnabledProjectList: [String]
25+
@AppStorage(\.promptToCodeFeatureProvider)
26+
var promptToCodeFeatureProvider: PromptToCodeFeatureProvider
2527
init() {}
2628
}
2729

@@ -134,6 +136,19 @@ struct SettingsView: View {
134136
Text("Use accessibility API to accept suggestion in widget")
135137
}
136138
.toggleStyle(.switch)
139+
140+
Picker(selection: $settings.promptToCodeFeatureProvider) {
141+
ForEach(PromptToCodeFeatureProvider.allCases, id: \.rawValue) {
142+
switch $0 {
143+
case .openAI:
144+
Text("OpenAI").tag($0)
145+
case .githubCopilot:
146+
Text("GitHub Copilot (Less Accurate)").tag($0)
147+
}
148+
}
149+
} label: {
150+
Text("Prompt to code with")
151+
}
137152
}
138153
}.buttonStyle(.copilot)
139154
}

Core/Sources/Preferences/Keys.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@ public struct UserDefaultPreferenceKeys {
151151
public var suggestionFeatureEnabledProjectList: SuggestionFeatureEnabledProjectList {
152152
.init()
153153
}
154+
155+
public struct PromptToCodeFeatureProviderKey: UserDefaultPreferenceKey {
156+
public let defaultValue: PromptToCodeFeatureProvider = .openAI
157+
public let key = "PromptToCodeFeatureProvider"
158+
}
159+
160+
public var promptToCodeFeatureProvider: PromptToCodeFeatureProviderKey {
161+
.init()
162+
}
154163

155164
public var disableLazyVStack: FeatureFlags.DisableLazyVStack { .init() }
156165
public var preCacheOnFileOpen: FeatureFlags.PreCacheOnFileOpen { .init() }
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Foundation
2+
3+
public enum PromptToCodeFeatureProvider: Int, CaseIterable {
4+
case openAI
5+
case githubCopilot
6+
}

Core/Sources/PromptToCodeService/PromptToCodeService.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,16 @@ import OpenAIService
66
public final class PromptToCodeService: ObservableObject {
77
var designatedPromptToCodeAPI: PromptToCodeAPI?
88
var promptToCodeAPI: PromptToCodeAPI {
9-
designatedPromptToCodeAPI ?? OpenAIPromptToCodeAPI()
9+
if let designatedPromptToCodeAPI {
10+
return designatedPromptToCodeAPI
11+
}
12+
13+
switch UserDefaults.shared.value(for: \.promptToCodeFeatureProvider) {
14+
case .openAI:
15+
return OpenAIPromptToCodeAPI()
16+
case .githubCopilot:
17+
return CopilotPromptToCodeAPI()
18+
}
1019
}
1120

1221
var runningAPI: PromptToCodeAPI?

0 commit comments

Comments
 (0)