Skip to content

Commit d96e234

Browse files
committed
Support ignoring trailing new lines
1 parent 7c3e584 commit d96e234

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

Core/Sources/GitHubCopilotService/GitHubCopilotService.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public class GitHubCopilotBaseService {
165165

166166
self.server = server
167167
localProcessServer = localServer
168-
168+
169169
Task {
170170
try await server.sendRequest(GitHubCopilotRequest.SetEditorInfo())
171171
}
@@ -312,6 +312,18 @@ public final class GitHubCopilotSuggestionService: GitHubCopilotBaseService,
312312
}
313313
return true
314314
}
315+
.map {
316+
if UserDefaults.shared.value(for: \.gitHubCopilotIgnoreTrailingNewLines) {
317+
var updated = $0
318+
var text = updated.text[...]
319+
while text.hasSuffix("\n") {
320+
text = text.dropLast(1)
321+
}
322+
updated.text = String(text)
323+
return updated
324+
}
325+
return $0
326+
}
315327
try Task.checkCancellation()
316328
return completions
317329
}

Core/Sources/HostApp/AccountSettings/CopilotView.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ struct CopilotView: View {
1818
@AppStorage(\.gitHubCopilotProxyUsername) var gitHubCopilotProxyUsername
1919
@AppStorage(\.gitHubCopilotProxyPassword) var gitHubCopilotProxyPassword
2020
@AppStorage(\.gitHubCopilotUseStrictSSL) var gitHubCopilotUseStrictSSL
21-
21+
@AppStorage(\.gitHubCopilotIgnoreTrailingNewLines)
22+
var gitHubCopilotIgnoreTrailingNewLines
2223
init() {}
2324
}
2425

@@ -229,13 +230,20 @@ struct CopilotView: View {
229230
Divider()
230231

231232
Form {
233+
Toggle(
234+
"Ignore Trailing New Lines",
235+
isOn: $settings.gitHubCopilotIgnoreTrailingNewLines
236+
)
232237
Toggle("Verbose Log", isOn: $settings.gitHubCopilotVerboseLog)
233238
}
234239

235240
Divider()
236241

237242
Form {
238-
TextField(text: $settings.gitHubCopilotProxyHost, prompt: Text("xxx.xxx.xxx.xxx, leave it blank to disable proxy.")) {
243+
TextField(
244+
text: $settings.gitHubCopilotProxyHost,
245+
prompt: Text("xxx.xxx.xxx.xxx, leave it blank to disable proxy.")
246+
) {
239247
Text("Proxy Host")
240248
}
241249
TextField(text: $settings.gitHubCopilotProxyPort, prompt: Text("80")) {

Tool/Sources/Preferences/Keys.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ public extension UserDefaultPreferenceKeys {
160160
var runNodeWith: PreferenceKey<NodeRunner> {
161161
.init(defaultValue: .env, key: "RunNodeWith")
162162
}
163+
164+
var gitHubCopilotIgnoreTrailingNewLines: PreferenceKey<Bool> {
165+
.init(defaultValue: false, key: "GitHubCopilotIgnoreTrailingNewLines")
166+
}
163167
}
164168

165169
// MARK: - Codeium Settings

0 commit comments

Comments
 (0)