forked from intitni/CopilotForXcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSuggestionSettingsView.swift
More file actions
155 lines (136 loc) · 5.52 KB
/
SuggestionSettingsView.swift
File metadata and controls
155 lines (136 loc) · 5.52 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
import Preferences
import SwiftUI
#if canImport(ProHostApp)
import ProHostApp
#endif
struct SuggestionSettingsView: View {
final class Settings: ObservableObject {
@AppStorage(\.realtimeSuggestionToggle)
var realtimeSuggestionToggle
@AppStorage(\.realtimeSuggestionDebounce)
var realtimeSuggestionDebounce
@AppStorage(\.suggestionPresentationMode)
var suggestionPresentationMode
@AppStorage(\.disableSuggestionFeatureGlobally)
var disableSuggestionFeatureGlobally
@AppStorage(\.suggestionFeatureEnabledProjectList)
var suggestionFeatureEnabledProjectList
@AppStorage(\.hideCommonPrecedingSpacesInSuggestion)
var hideCommonPrecedingSpacesInSuggestion
@AppStorage(\.suggestionCodeFontSize)
var suggestionCodeFontSize
@AppStorage(\.suggestionFeatureProvider)
var suggestionFeatureProvider
@AppStorage(\.suggestionDisplayCompactMode)
var suggestionDisplayCompactMode
@AppStorage(\.acceptSuggestionWithTab)
var acceptSuggestionWithTab
init() {}
}
@StateObject var settings = Settings()
@State var isSuggestionFeatureEnabledListPickerOpen = false
@State var isSuggestionFeatureDisabledLanguageListViewOpen = false
var body: some View {
Form {
Group {
Picker(selection: $settings.suggestionPresentationMode) {
ForEach(PresentationMode.allCases, id: \.rawValue) {
switch $0 {
case .nearbyTextCursor:
Text("Nearby Text Cursor").tag($0)
case .floatingWidget:
Text("Floating Widget").tag($0)
}
}
} label: {
Text("Presentation")
}
Picker(selection: $settings.suggestionFeatureProvider) {
ForEach(SuggestionFeatureProvider.allCases, id: \.rawValue) {
switch $0 {
case .gitHubCopilot:
Text("GitHub Copilot").tag($0)
case .codeium:
Text("Codeium").tag($0)
}
}
} label: {
Text("Feature Provider")
}
Toggle(isOn: $settings.realtimeSuggestionToggle) {
Text("Real-time Suggestion")
}
#if canImport(ProHostApp)
WithFeatureEnabled(\.tabToAcceptSuggestion) {
Toggle(isOn: $settings.acceptSuggestionWithTab) {
Text("Accept Suggestion with Tab")
}
}
#endif
HStack {
Toggle(isOn: $settings.disableSuggestionFeatureGlobally) {
Text("Disable Suggestion Feature Globally")
}
Button("Exception List") {
isSuggestionFeatureEnabledListPickerOpen = true
}
}.sheet(isPresented: $isSuggestionFeatureEnabledListPickerOpen) {
SuggestionFeatureEnabledProjectListView(
isOpen: $isSuggestionFeatureEnabledListPickerOpen
)
}
HStack {
Button("Disabled Language List") {
isSuggestionFeatureDisabledLanguageListViewOpen = true
}
}.sheet(isPresented: $isSuggestionFeatureDisabledLanguageListViewOpen) {
SuggestionFeatureDisabledLanguageListView(
isOpen: $isSuggestionFeatureDisabledLanguageListViewOpen
)
}
HStack {
Slider(value: $settings.realtimeSuggestionDebounce, in: 0...2, step: 0.1) {
Text("Real-time Suggestion Debounce")
}
Text(
"\(settings.realtimeSuggestionDebounce.formatted(.number.precision(.fractionLength(2))))s"
)
.font(.body)
.monospacedDigit()
.padding(.vertical, 2)
.padding(.horizontal, 6)
.background(
RoundedRectangle(cornerRadius: 4, style: .continuous)
.fill(Color.primary.opacity(0.1))
)
}
Divider()
}
Group {
Toggle(isOn: $settings.suggestionDisplayCompactMode) {
Text("Hide Buttons")
}
Toggle(isOn: $settings.hideCommonPrecedingSpacesInSuggestion) {
Text("Hide Common Preceding Spaces")
}
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")
}
Divider()
}
}
}
}
struct SuggestionSettingsView_Previews: PreviewProvider {
static var previews: some View {
SuggestionSettingsView()
}
}