Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix FetchSuggestionTests
  • Loading branch information
intitni committed Jul 18, 2023
commit 94a480f475fea885257701f59c485c1e1afdabc4
8 changes: 5 additions & 3 deletions Core/Sources/GitHubCopilotService/GitHubCopilotService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public protocol GitHubCopilotSuggestionServiceType {
tabSize: Int,
indentSize: Int,
usesTabsForIndentation: Bool,
ignoreSpaceOnlySuggestions: Bool
ignoreSpaceOnlySuggestions: Bool,
ignoreTrailingNewLinesAndSpaces: Bool
) async throws -> [CodeSuggestion]
func notifyAccepted(_ completion: CodeSuggestion) async
func notifyRejected(_ completions: [CodeSuggestion]) async
Expand Down Expand Up @@ -269,7 +270,8 @@ public final class GitHubCopilotSuggestionService: GitHubCopilotBaseService,
tabSize: Int,
indentSize: Int,
usesTabsForIndentation: Bool,
ignoreSpaceOnlySuggestions: Bool
ignoreSpaceOnlySuggestions: Bool,
ignoreTrailingNewLinesAndSpaces: Bool
) async throws -> [CodeSuggestion] {
let languageId = languageIdentifierFromFileURL(fileURL)

Expand Down Expand Up @@ -313,7 +315,7 @@ public final class GitHubCopilotSuggestionService: GitHubCopilotBaseService,
return true
}
.map {
if UserDefaults.shared.value(for: \.gitHubCopilotIgnoreTrailingNewLines) {
if ignoreTrailingNewLinesAndSpaces {
var updated = $0
var text = updated.text[...]
while let last = text.last, last.isNewline || last.isWhitespace {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ final class CopilotPromptToCodeAPI: PromptToCodeAPI {
tabSize: indentSize,
indentSize: indentSize,
usesTabsForIndentation: usesTabsForIndentation,
ignoreSpaceOnlySuggestions: true
ignoreSpaceOnlySuggestions: true,
ignoreTrailingNewLinesAndSpaces: false
)
try Task.checkCancellation()
guard let first = result.first else { throw CancellationError() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ extension GitHubCopilotSuggestionProvider {
tabSize: tabSize,
indentSize: indentSize,
usesTabsForIndentation: usesTabsForIndentation,
ignoreSpaceOnlySuggestions: ignoreSpaceOnlySuggestions
ignoreSpaceOnlySuggestions: ignoreSpaceOnlySuggestions,
ignoreTrailingNewLinesAndSpaces: UserDefaults.shared
.value(for: \.gitHubCopilotIgnoreTrailingNewLines)
)
}

Expand Down Expand Up @@ -73,12 +75,12 @@ extension GitHubCopilotSuggestionProvider {
try await (try? createGitHubCopilotServiceIfNeeded())?
.notifySaveTextDocument(fileURL: fileURL)
}

func cancelRequest() async {
await (try? createGitHubCopilotServiceIfNeeded())?
.cancelRequest()
}

func terminate() async {
await (try? createGitHubCopilotServiceIfNeeded())?.terminate()
}
Expand Down
13 changes: 8 additions & 5 deletions Core/Tests/GitHubCopilotServiceTests/FetchSuggestionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import XCTest
@testable import GitHubCopilotService

final class FetchSuggestionTests: XCTestCase {
func test_process_sugestions_from_server() async throws {
func test_process_suggestions_from_server() async throws {
struct TestServer: GitHubCopilotLSP {
func sendNotification(_ notif: LanguageServerProtocol.ClientNotification) async throws {
fatalError()
Expand Down Expand Up @@ -44,7 +44,8 @@ final class FetchSuggestionTests: XCTestCase {
tabSize: 4,
indentSize: 4,
usesTabsForIndentation: false,
ignoreSpaceOnlySuggestions: false
ignoreSpaceOnlySuggestions: false,
ignoreTrailingNewLinesAndSpaces: false
)
XCTAssertEqual(completions.count, 3)
}
Expand Down Expand Up @@ -89,7 +90,8 @@ final class FetchSuggestionTests: XCTestCase {
tabSize: 4,
indentSize: 4,
usesTabsForIndentation: false,
ignoreSpaceOnlySuggestions: true
ignoreSpaceOnlySuggestions: true,
ignoreTrailingNewLinesAndSpaces: false
)
XCTAssertEqual(completions.count, 1)
XCTAssertEqual(completions.first?.text, "Hello World\n")
Expand Down Expand Up @@ -128,9 +130,10 @@ final class FetchSuggestionTests: XCTestCase {
tabSize: 4,
indentSize: 4,
usesTabsForIndentation: false,
ignoreSpaceOnlySuggestions: false
ignoreSpaceOnlySuggestions: false,
ignoreTrailingNewLinesAndSpaces: true
)
XCTAssertEqual(completions.count, 1)
XCTAssertEqual(completions.first?.text, "Hello World\n")
XCTAssertEqual(completions.first?.text, "Hello World")
}
}
3 changes: 2 additions & 1 deletion Core/Tests/ServiceTests/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class MockSuggestionService: GitHubCopilotSuggestionServiceType {
tabSize: Int,
indentSize: Int,
usesTabsForIndentation: Bool,
ignoreSpaceOnlySuggestions: Bool
ignoreSpaceOnlySuggestions: Bool,
ignoreTrailingNewLinesAndSpaces: Bool
) async throws -> [SuggestionModel.CodeSuggestion] {
completions
}
Expand Down