Skip to content

Commit 94a480f

Browse files
committed
Fix FetchSuggestionTests
1 parent 587a05f commit 94a480f

File tree

5 files changed

+22
-13
lines changed

5 files changed

+22
-13
lines changed

Core/Sources/GitHubCopilotService/GitHubCopilotService.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public protocol GitHubCopilotSuggestionServiceType {
2323
tabSize: Int,
2424
indentSize: Int,
2525
usesTabsForIndentation: Bool,
26-
ignoreSpaceOnlySuggestions: Bool
26+
ignoreSpaceOnlySuggestions: Bool,
27+
ignoreTrailingNewLinesAndSpaces: Bool
2728
) async throws -> [CodeSuggestion]
2829
func notifyAccepted(_ completion: CodeSuggestion) async
2930
func notifyRejected(_ completions: [CodeSuggestion]) async
@@ -269,7 +270,8 @@ public final class GitHubCopilotSuggestionService: GitHubCopilotBaseService,
269270
tabSize: Int,
270271
indentSize: Int,
271272
usesTabsForIndentation: Bool,
272-
ignoreSpaceOnlySuggestions: Bool
273+
ignoreSpaceOnlySuggestions: Bool,
274+
ignoreTrailingNewLinesAndSpaces: Bool
273275
) async throws -> [CodeSuggestion] {
274276
let languageId = languageIdentifierFromFileURL(fileURL)
275277

@@ -313,7 +315,7 @@ public final class GitHubCopilotSuggestionService: GitHubCopilotBaseService,
313315
return true
314316
}
315317
.map {
316-
if UserDefaults.shared.value(for: \.gitHubCopilotIgnoreTrailingNewLines) {
318+
if ignoreTrailingNewLinesAndSpaces {
317319
var updated = $0
318320
var text = updated.text[...]
319321
while let last = text.last, last.isNewline || last.isWhitespace {

Core/Sources/PromptToCodeService/CopilotPromptToCodeAPI.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ final class CopilotPromptToCodeAPI: PromptToCodeAPI {
7070
tabSize: indentSize,
7171
indentSize: indentSize,
7272
usesTabsForIndentation: usesTabsForIndentation,
73-
ignoreSpaceOnlySuggestions: true
73+
ignoreSpaceOnlySuggestions: true,
74+
ignoreTrailingNewLinesAndSpaces: false
7475
)
7576
try Task.checkCancellation()
7677
guard let first = result.first else { throw CancellationError() }

Core/Sources/SuggestionService/GitHubCopilotSuggestionProvider.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ extension GitHubCopilotSuggestionProvider {
4242
tabSize: tabSize,
4343
indentSize: indentSize,
4444
usesTabsForIndentation: usesTabsForIndentation,
45-
ignoreSpaceOnlySuggestions: ignoreSpaceOnlySuggestions
45+
ignoreSpaceOnlySuggestions: ignoreSpaceOnlySuggestions,
46+
ignoreTrailingNewLinesAndSpaces: UserDefaults.shared
47+
.value(for: \.gitHubCopilotIgnoreTrailingNewLines)
4648
)
4749
}
4850

@@ -73,12 +75,12 @@ extension GitHubCopilotSuggestionProvider {
7375
try await (try? createGitHubCopilotServiceIfNeeded())?
7476
.notifySaveTextDocument(fileURL: fileURL)
7577
}
76-
78+
7779
func cancelRequest() async {
7880
await (try? createGitHubCopilotServiceIfNeeded())?
7981
.cancelRequest()
8082
}
81-
83+
8284
func terminate() async {
8385
await (try? createGitHubCopilotServiceIfNeeded())?.terminate()
8486
}

Core/Tests/GitHubCopilotServiceTests/FetchSuggestionsTests.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import XCTest
44
@testable import GitHubCopilotService
55

66
final class FetchSuggestionTests: XCTestCase {
7-
func test_process_sugestions_from_server() async throws {
7+
func test_process_suggestions_from_server() async throws {
88
struct TestServer: GitHubCopilotLSP {
99
func sendNotification(_ notif: LanguageServerProtocol.ClientNotification) async throws {
1010
fatalError()
@@ -44,7 +44,8 @@ final class FetchSuggestionTests: XCTestCase {
4444
tabSize: 4,
4545
indentSize: 4,
4646
usesTabsForIndentation: false,
47-
ignoreSpaceOnlySuggestions: false
47+
ignoreSpaceOnlySuggestions: false,
48+
ignoreTrailingNewLinesAndSpaces: false
4849
)
4950
XCTAssertEqual(completions.count, 3)
5051
}
@@ -89,7 +90,8 @@ final class FetchSuggestionTests: XCTestCase {
8990
tabSize: 4,
9091
indentSize: 4,
9192
usesTabsForIndentation: false,
92-
ignoreSpaceOnlySuggestions: true
93+
ignoreSpaceOnlySuggestions: true,
94+
ignoreTrailingNewLinesAndSpaces: false
9395
)
9496
XCTAssertEqual(completions.count, 1)
9597
XCTAssertEqual(completions.first?.text, "Hello World\n")
@@ -128,9 +130,10 @@ final class FetchSuggestionTests: XCTestCase {
128130
tabSize: 4,
129131
indentSize: 4,
130132
usesTabsForIndentation: false,
131-
ignoreSpaceOnlySuggestions: false
133+
ignoreSpaceOnlySuggestions: false,
134+
ignoreTrailingNewLinesAndSpaces: true
132135
)
133136
XCTAssertEqual(completions.count, 1)
134-
XCTAssertEqual(completions.first?.text, "Hello World\n")
137+
XCTAssertEqual(completions.first?.text, "Hello World")
135138
}
136139
}

Core/Tests/ServiceTests/Environment.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ class MockSuggestionService: GitHubCopilotSuggestionServiceType {
7171
tabSize: Int,
7272
indentSize: Int,
7373
usesTabsForIndentation: Bool,
74-
ignoreSpaceOnlySuggestions: Bool
74+
ignoreSpaceOnlySuggestions: Bool,
75+
ignoreTrailingNewLinesAndSpaces: Bool
7576
) async throws -> [SuggestionModel.CodeSuggestion] {
7677
completions
7778
}

0 commit comments

Comments
 (0)