forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPromptToCodeSettingsView.swift
More file actions
164 lines (138 loc) · 5.63 KB
/
PromptToCodeSettingsView.swift
File metadata and controls
164 lines (138 loc) · 5.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import Preferences
import SharedUIComponents
import SwiftUI
#if canImport(ProHostApp)
import ProHostApp
#endif
struct PromptToCodeSettingsView: View {
final class Settings: ObservableObject {
@AppStorage(\.hideCommonPrecedingSpacesInSuggestion)
var hideCommonPrecedingSpacesInSuggestion
@AppStorage(\.suggestionCodeFontSize)
var suggestionCodeFontSize
@AppStorage(\.promptToCodeGenerateDescription)
var promptToCodeGenerateDescription
@AppStorage(\.promptToCodeGenerateDescriptionInUserPreferredLanguage)
var promptToCodeGenerateDescriptionInUserPreferredLanguage
@AppStorage(\.promptToCodeChatModelId)
var promptToCodeChatModelId
@AppStorage(\.promptToCodeEmbeddingModelId)
var promptToCodeEmbeddingModelId
@AppStorage(\.chatModels) var chatModels
@AppStorage(\.embeddingModels) var embeddingModels
init() {}
}
@StateObject var settings = Settings()
var body: some View {
VStack(alignment: .center) {
Form {
Picker(
"Chat Model",
selection: $settings.promptToCodeChatModelId
) {
Text("Same as Chat Feature").tag("")
if !settings.chatModels
.contains(where: { $0.id == settings.promptToCodeChatModelId }),
!settings.promptToCodeChatModelId.isEmpty
{
Text(
(settings.chatModels.first?.name).map { "\($0) (Default)" }
?? "No Model Found"
)
.tag(settings.promptToCodeChatModelId)
}
ForEach(settings.chatModels, id: \.id) { chatModel in
Text(chatModel.name).tag(chatModel.id)
}
}
Picker(
"Embedding Model",
selection: $settings.promptToCodeEmbeddingModelId
) {
Text("Same as Chat Feature").tag("")
if !settings.embeddingModels
.contains(where: { $0.id == settings.promptToCodeEmbeddingModelId }),
!settings.promptToCodeEmbeddingModelId.isEmpty
{
Text(
(settings.embeddingModels.first?.name).map { "\($0) (Default)" }
?? "No Model Found"
)
.tag(settings.promptToCodeEmbeddingModelId)
}
ForEach(settings.embeddingModels, id: \.id) { embeddingModel in
Text(embeddingModel.name).tag(embeddingModel.id)
}
}
Toggle(isOn: $settings.promptToCodeGenerateDescription) {
Text("Generate Description")
}
Toggle(isOn: $settings.promptToCodeGenerateDescriptionInUserPreferredLanguage) {
Text("Generate Description in user preferred language")
}
}
SettingsDivider("Mirroring Settings of Suggestion Feature")
Form {
Toggle(isOn: $settings.hideCommonPrecedingSpacesInSuggestion) {
Text("Hide Common Preceding Spaces")
}.disabled(true)
HStack {
TextField(text: .init(get: {
"\(Int(settings.suggestionCodeFontSize))"
}, set: {
settings.suggestionCodeFontSize = Double(Int($0) ?? 0)
})) {
Text("Font size of suggestion code")
}
.textFieldStyle(.roundedBorder)
Text("pt")
}.disabled(true)
}
ScopeForm()
}
}
struct ScopeForm: View {
class Settings: ObservableObject {
@AppStorage(\.enableSenseScopeByDefaultInPromptToCode)
var enableSenseScopeByDefaultInPromptToCode: Bool
init() {}
}
@StateObject var settings = Settings()
var body: some View {
SettingsDivider("Scopes")
VStack {
#if canImport(ProHostApp)
SubSection(
title: Text("Sense Scope (Experimental)"),
description: IfFeatureEnabled(\.senseScopeInChat) {
Text("""
Enable the bot to access the relevant code \
of the editing document in the project, third party packages and the SDK.
""")
} else: {
VStack(alignment: .leading) {
Text("""
Enable the bot to read the relevant code \
of the editing document in the SDK, and
""")
WithFeatureEnabled(\.senseScopeInChat, alignment: .inlineLeading) {
Text("the project and third party packages.")
}
}
}
) {
Form {
Toggle(isOn: $settings.enableSenseScopeByDefaultInPromptToCode) {
Text("Enable by default")
}
}
}
#endif
}
}
}
}
#Preview {
PromptToCodeSettingsView()
.padding()
}