Skip to content

Commit 35661b1

Browse files
committed
Add verbose log toggle
1 parent 7af7b57 commit 35661b1

File tree

5 files changed

+112
-78
lines changed

5 files changed

+112
-78
lines changed

Core/Sources/CodeiumService/CodeiumLanguageServer.swift

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import JSONRPC
33
import LanguageClient
44
import LanguageServerProtocol
55
import Logger
6+
import Preferences
67

78
protocol CodeiumLSP {
89
func sendRequest<E: CodeiumRequestType>(_ endpoint: E) async throws -> E.Response
@@ -135,17 +136,23 @@ extension CodeiumLanguageServer: CodeiumLSP {
135136
let response = try JSONDecoder().decode(E.Response.self, from: data)
136137
return response
137138
} catch {
138-
dump(error)
139-
Logger.codeium.error(error.localizedDescription)
139+
if UserDefaults.shared.value(for: \.codeiumVerboseLog) {
140+
dump(error)
141+
Logger.codeium.error(error.localizedDescription)
142+
}
140143
throw error
141144
}
142145
} else {
143146
do {
144147
let error = try JSONDecoder().decode(CodeiumResponseError.self, from: data)
145-
Logger.codeium.error(error.message)
148+
if UserDefaults.shared.value(for: \.codeiumVerboseLog) {
149+
Logger.codeium.error(error.message)
150+
}
146151
throw CancellationError()
147152
} catch {
148-
Logger.codeium.error(error.localizedDescription)
153+
if UserDefaults.shared.value(for: \.codeiumVerboseLog) {
154+
Logger.codeium.error(error.localizedDescription)
155+
}
149156
throw error
150157
}
151158
}
@@ -204,9 +211,9 @@ final class IOTransport {
204211
return
205212
}
206213

207-
#if DEBUG
208-
self.forwardDataToHandler(data)
209-
#endif
214+
if UserDefaults.shared.value(for: \.codeiumVerboseLog) {
215+
self.forwardDataToHandler(data)
216+
}
210217
}
211218

212219
stderrPipe.fileHandleForReading.readabilityHandler = { [unowned self] handle in
@@ -216,9 +223,9 @@ final class IOTransport {
216223
return
217224
}
218225

219-
#if DEBUG
220-
self.forwardErrorDataToHandler(data)
221-
#endif
226+
if UserDefaults.shared.value(for: \.codeiumVerboseLog) {
227+
self.forwardErrorDataToHandler(data)
228+
}
222229
}
223230
}
224231

Core/Sources/GitHubCopilotService/GitHubCopilotService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public class GitHubCopilotBaseService {
124124
}()
125125
}
126126
let localServer = CopilotLocalProcessServer(executionParameters: executionParams)
127-
localServer.logMessages = false
127+
localServer.logMessages = UserDefaults.shared.value(for: \.gitHubCopilotVerboseLog)
128128
localServer.notificationHandler = { _, respond in
129129
respond(.timeout)
130130
}

Core/Sources/HostApp/AccountSettings/CodeiumView.swift

Lines changed: 75 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ struct CodeiumView: View {
99
@Published var isSignedIn: Bool
1010
@Published var installationStatus: CodeiumInstallationManager.InstallationStatus
1111
@Published var installationStep: CodeiumInstallationManager.InstallationStep?
12+
@AppStorage(\.codeiumVerboseLog) var codeiumVerboseLog
1213

1314
init() {
1415
isSignedIn = codeiumAuthService.isSignedIn
@@ -123,78 +124,86 @@ struct CodeiumView: View {
123124

124125
var body: some View {
125126
VStack(alignment: .leading) {
126-
switch viewModel.installationStatus {
127-
case .notInstalled:
128-
HStack {
129-
Text("Language Server Version: Not Installed")
130-
installButton
131-
}
132-
case let .installed(version):
133-
HStack {
134-
Text("Language Server Version: \(version)")
135-
uninstallButton
136-
}
137-
case let .outdated(current: current, latest: latest):
138-
HStack {
139-
Text("Language Server Version: \(current) (Update Available: \(latest))")
140-
uninstallButton
141-
updateButton
127+
VStack(alignment: .leading) {
128+
switch viewModel.installationStatus {
129+
case .notInstalled:
130+
HStack {
131+
Text("Language Server Version: Not Installed")
132+
installButton
133+
}
134+
case let .installed(version):
135+
HStack {
136+
Text("Language Server Version: \(version)")
137+
uninstallButton
138+
}
139+
case let .outdated(current: current, latest: latest):
140+
HStack {
141+
Text("Language Server Version: \(current) (Update Available: \(latest))")
142+
uninstallButton
143+
updateButton
144+
}
145+
case let .unsupported(current: current, latest: latest):
146+
HStack {
147+
Text("Language Server Version: \(current) (Supported Version: \(latest))")
148+
uninstallButton
149+
updateButton
150+
}
142151
}
143-
case let .unsupported(current: current, latest: latest):
144-
HStack {
145-
Text("Language Server Version: \(current) (Supported Version: \(latest))")
146-
uninstallButton
147-
updateButton
152+
153+
if viewModel.isSignedIn {
154+
Text("Status: Signed In")
155+
156+
Button(action: {
157+
viewModel.isSignedIn = false
158+
}) {
159+
Text("Sign Out")
160+
}
161+
162+
Text(
163+
"The key is stored in the keychain. The helper app may request permission to access the key, please click \"Always Allow\" to grant this access."
164+
)
165+
.lineLimit(5)
166+
.fixedSize(horizontal: false, vertical: true)
167+
.foregroundColor(.secondary)
168+
} else {
169+
Text("Status: Not Signed In")
170+
171+
Button(action: {
172+
isSignInPanelPresented = true
173+
}) {
174+
Text("Sign In")
175+
}
148176
}
149177
}
150-
151-
if viewModel.isSignedIn {
152-
Text("Status: Signed In")
153-
154-
Button(action: {
155-
viewModel.isSignedIn = false
156-
}) {
157-
Text("Sign Out")
158-
}
159-
160-
Text(
161-
"The key is stored in the keychain. The helper app may request permission to access the key, please click \"Always Allow\" to grant this access."
162-
)
163-
.lineLimit(5)
164-
.fixedSize(horizontal: false, vertical: true)
165-
.foregroundColor(.secondary)
166-
} else {
167-
Text("Status: Not Signed In")
168-
169-
Button(action: {
170-
isSignInPanelPresented = true
171-
}) {
172-
Text("Sign In")
173-
}
178+
.padding(8)
179+
.frame(maxWidth: .infinity, alignment: .leading)
180+
.overlay {
181+
RoundedRectangle(cornerRadius: 8)
182+
.stroke(Color(nsColor: .separatorColor), style: .init(lineWidth: 1))
174183
}
175-
}
176-
.padding(8)
177-
.frame(maxWidth: .infinity, alignment: .leading)
178-
.overlay {
179-
RoundedRectangle(cornerRadius: 8)
180-
.stroke(Color(nsColor: .separatorColor), style: .init(lineWidth: 1))
181-
}
182-
.sheet(isPresented: $isSignInPanelPresented) {
183-
CodeiumSignInView(viewModel: viewModel, isPresented: $isSignInPanelPresented)
184-
}
185-
.onChange(of: viewModel.installationStep) { newValue in
186-
if let step = newValue {
187-
switch step {
188-
case .downloading:
189-
toast(Text("Downloading.."), .info)
190-
case .uninstalling:
191-
toast(Text("Uninstalling old version.."), .info)
192-
case .decompressing:
193-
toast(Text("Decompressing.."), .info)
194-
case .done:
195-
toast(Text("Done!"), .info)
184+
.sheet(isPresented: $isSignInPanelPresented) {
185+
CodeiumSignInView(viewModel: viewModel, isPresented: $isSignInPanelPresented)
186+
}
187+
.onChange(of: viewModel.installationStep) { newValue in
188+
if let step = newValue {
189+
switch step {
190+
case .downloading:
191+
toast(Text("Downloading.."), .info)
192+
case .uninstalling:
193+
toast(Text("Uninstalling old version.."), .info)
194+
case .decompressing:
195+
toast(Text("Decompressing.."), .info)
196+
case .done:
197+
toast(Text("Done!"), .info)
198+
}
196199
}
197200
}
201+
202+
Divider()
203+
204+
Form {
205+
Toggle("Verbose Log", isOn: $viewModel.codeiumVerboseLog)
206+
}
198207
}
199208
}
200209
}

Core/Sources/HostApp/AccountSettings/CopilotView.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ struct CopilotView: View {
1212
@AppStorage(\.nodePath) var nodePath: String
1313
@AppStorage(\.runNodeWith) var runNodeWith
1414
@AppStorage("username") var username: String = ""
15+
@AppStorage(\.gitHubCopilotVerboseLog) var gitHubCopilotVerboseLog
1516

1617
init() {}
1718
}
@@ -101,6 +102,12 @@ struct CopilotView: View {
101102
RoundedRectangle(cornerRadius: 8)
102103
.stroke(Color(nsColor: .separatorColor), style: .init(lineWidth: 1))
103104
}
105+
106+
Divider()
107+
108+
Form {
109+
Toggle("Verbose Log", isOn: $settings.gitHubCopilotVerboseLog)
110+
}
104111
}
105112
Spacer()
106113
}.onAppear {

Core/Sources/Preferences/Keys.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public extension UserDefaultPreferenceKeys {
221221
var chatGPTTemperature: ChatGPTTemperature { .init() }
222222
}
223223

224-
// MARK: - GitHubCopilot Account Settings
224+
// MARK: - GitHub Copilot Settings
225225

226226
public extension UserDefaultPreferenceKeys {
227227
struct GitHubCopilotVerboseLog: UserDefaultPreferenceKey {
@@ -250,6 +250,17 @@ public extension UserDefaultPreferenceKeys {
250250
var runNodeWith: RunNodeWithKey { .init() }
251251
}
252252

253+
// MARK: - Codeium Settings
254+
255+
public extension UserDefaultPreferenceKeys {
256+
struct CodeiumVerboseLog: UserDefaultPreferenceKey {
257+
public let defaultValue = false
258+
public let key = "CodeiumVerboseLog"
259+
}
260+
261+
var codeiumVerboseLog: CodeiumVerboseLog { .init() }
262+
}
263+
253264
// MARK: - UI
254265

255266
public extension UserDefaultPreferenceKeys {

0 commit comments

Comments
 (0)