Skip to content

Commit d0924ae

Browse files
committed
Merge branch 'feature/passing-relevant-snippets-to-suggestion-service' into develop
2 parents 437105f + c410167 commit d0924ae

12 files changed

Lines changed: 72 additions & 15 deletions

File tree

Copilot for Xcode.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@
448448
isa = PBXProject;
449449
attributes = {
450450
BuildIndependentTargetsInParallel = 1;
451-
LastSwiftUpdateCheck = 1420;
451+
LastSwiftUpdateCheck = 1520;
452452
LastUpgradeCheck = 1410;
453453
TargetAttributes = {
454454
C814588B2939EFDC00135263 = {

Core/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ let package = Package(
8989
],
9090
dependencies: [
9191
.package(path: "../Tool"),
92-
.package(url: "https://github.com/apple/swift-async-algorithms", from: "0.1.0"),
92+
.package(url: "https://github.com/apple/swift-async-algorithms", from: "1.0.0"),
9393
.package(url: "https://github.com/gonzalezreal/swift-markdown-ui", from: "2.1.0"),
9494
.package(url: "https://github.com/sparkle-project/Sparkle", from: "2.0.0"),
9595
.package(url: "https://github.com/pointfreeco/swift-parsing", from: "0.12.1"),

Core/Sources/Service/RealtimeSuggestionController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public actor RealtimeSuggestionController {
8181
}
8282

8383
if #available(macOS 13.0, *) {
84-
for await _ in valueChange.throttle(for: .milliseconds(200)) {
84+
for await _ in valueChange._throttle(for: .milliseconds(200)) {
8585
if Task.isCancelled { return }
8686
await handler()
8787
}
@@ -103,7 +103,7 @@ public actor RealtimeSuggestionController {
103103
}
104104

105105
if #available(macOS 13.0, *) {
106-
for await _ in selectedTextChanged.throttle(for: .milliseconds(200)) {
106+
for await _ in selectedTextChanged._throttle(for: .milliseconds(200)) {
107107
if Task.isCancelled { return }
108108
await handler()
109109
}

Core/Sources/SuggestionService/SuggestionService.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import ProExtension
1111
public protocol SuggestionServiceType: SuggestionServiceProvider {}
1212

1313
public actor SuggestionService: SuggestionServiceType {
14+
public var configuration: SuggestionServiceConfiguration {
15+
get async { await suggestionProvider.configuration }
16+
}
17+
1418
var middlewares: [SuggestionServiceMiddleware] {
1519
SuggestionServiceMiddlewareContainer.middlewares
1620
}
@@ -50,7 +54,7 @@ public actor SuggestionService: SuggestionServiceType {
5054
return provider
5155
}
5256
#endif
53-
57+
5458
switch serviceType {
5559
case .builtIn(.codeium):
5660
return CodeiumSuggestionProvider(
@@ -75,10 +79,15 @@ public extension SuggestionService {
7579
_ request: SuggestionRequest
7680
) async throws -> [SuggestionModel.CodeSuggestion] {
7781
var getSuggestion = suggestionProvider.getSuggestions
82+
let configuration = await configuration
7883

7984
for middleware in middlewares.reversed() {
8085
getSuggestion = { [getSuggestion] request in
81-
try await middleware.getSuggestion(request, next: getSuggestion)
86+
try await middleware.getSuggestion(
87+
request,
88+
configuration: configuration,
89+
next: getSuggestion
90+
)
8291
}
8392
}
8493

Pro

Submodule Pro updated from a26917f to 21e4551

Tool/Package.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ let package = Package(
5252
// TODO: Update LanguageClient some day.
5353
.package(url: "https://github.com/ChimeHQ/LanguageClient", exact: "0.3.1"),
5454
.package(url: "https://github.com/ChimeHQ/LanguageServerProtocol", exact: "0.8.0"),
55-
.package(url: "https://github.com/apple/swift-async-algorithms", from: "0.1.0"),
55+
.package(url: "https://github.com/apple/swift-async-algorithms", from: "1.0.0"),
5656
.package(url: "https://github.com/pointfreeco/swift-parsing", from: "0.12.1"),
5757
.package(url: "https://github.com/ChimeHQ/JSONRPC", exact: "0.6.0"),
5858
.package(url: "https://github.com/scinfu/SwiftSoup.git", from: "2.6.0"),
@@ -66,6 +66,7 @@ let package = Package(
6666
.package(url: "https://github.com/GottaGetSwifty/CodableWrappers", from: "2.0.7"),
6767
.package(url: "https://github.com/krzyzanowskim/STTextView", from: "0.8.21"),
6868
.package(url: "https://github.com/google/generative-ai-swift", from: "0.4.4"),
69+
.package(url: "https://github.com/intitni/CopilotForXcodeKit", from: "0.4.0"),
6970

7071
// TreeSitter
7172
.package(url: "https://github.com/intitni/SwiftTreeSitter.git", branch: "main"),
@@ -279,6 +280,7 @@ let package = Package(
279280
"GitHubCopilotService",
280281
"CodeiumService",
281282
"UserDefaultsObserver",
283+
.product(name: "CopilotForXcodeKit", package: "CopilotForXcodeKit"),
282284
]),
283285

284286
// MARK: - GitHub Copilot

Tool/Sources/CustomAsyncAlgorithms/TimedDebounce.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ private actor TimedDebounceFunction<Element> {
4343

4444
public extension AsyncSequence {
4545
/// Debounce, but only if the value is received within a certain time frame.
46+
///
47+
/// In the future when we drop macOS 12 support we should just use chunked from AsyncAlgorithms.
4648
func timedDebounce(
4749
for duration: TimeInterval
4850
) -> AsyncThrowingStream<Element, Error> {

Tool/Sources/SuggestionProvider/CodeiumSuggestionProvider.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ import Preferences
44
import SuggestionModel
55

66
public actor CodeiumSuggestionProvider: SuggestionServiceProvider {
7+
public nonisolated var configuration: SuggestionServiceConfiguration {
8+
.init(
9+
acceptsRelevantCodeSnippets: true,
10+
mixRelevantCodeSnippetsInSource: true,
11+
acceptsRelevantSnippetsFromOpenedFiles: false
12+
)
13+
}
14+
715
let projectRootURL: URL
816
let onServiceLaunched: (SuggestionServiceProvider) -> Void
917
var codeiumService: CodeiumSuggestionServiceType?

Tool/Sources/SuggestionProvider/GitHubCopilotSuggestionProvider.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,22 @@ import Preferences
44
import SuggestionModel
55

66
public actor GitHubCopilotSuggestionProvider: SuggestionServiceProvider {
7+
public nonisolated var configuration: SuggestionServiceConfiguration {
8+
.init(
9+
acceptsRelevantCodeSnippets: true,
10+
mixRelevantCodeSnippetsInSource: true,
11+
acceptsRelevantSnippetsFromOpenedFiles: false
12+
)
13+
}
14+
715
let projectRootURL: URL
816
let onServiceLaunched: (SuggestionServiceProvider) -> Void
917
var gitHubCopilotService: GitHubCopilotSuggestionServiceType?
1018

11-
public init(projectRootURL: URL, onServiceLaunched: @escaping (SuggestionServiceProvider) -> Void) {
19+
public init(
20+
projectRootURL: URL,
21+
onServiceLaunched: @escaping (SuggestionServiceProvider) -> Void
22+
) {
1223
self.projectRootURL = projectRootURL
1324
self.onServiceLaunched = onServiceLaunched
1425
}

Tool/Sources/SuggestionProvider/SuggestionProvider.swift

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import AppKit
1+
import AppKit
2+
import struct CopilotForXcodeKit.SuggestionServiceConfiguration
23
import Foundation
34
import Preferences
45
import SuggestionModel
@@ -13,7 +14,8 @@ public struct SuggestionRequest {
1314
public var tabSize: Int
1415
public var indentSize: Int
1516
public var usesTabsForIndentation: Bool
16-
public var ignoreSpaceOnlySuggestions: Bool
17+
public var ignoreSpaceOnlySuggestions: Bool
18+
public var relevantCodeSnippets: [RelevantCodeSnippet]
1719

1820
public init(
1921
fileURL: URL,
@@ -24,7 +26,8 @@ public struct SuggestionRequest {
2426
tabSize: Int,
2527
indentSize: Int,
2628
usesTabsForIndentation: Bool,
27-
ignoreSpaceOnlySuggestions: Bool
29+
ignoreSpaceOnlySuggestions: Bool,
30+
relevantCodeSnippets: [RelevantCodeSnippet]
2831
) {
2932
self.fileURL = fileURL
3033
self.relativePath = relativePath
@@ -35,12 +38,24 @@ public struct SuggestionRequest {
3538
self.indentSize = indentSize
3639
self.usesTabsForIndentation = usesTabsForIndentation
3740
self.ignoreSpaceOnlySuggestions = ignoreSpaceOnlySuggestions
41+
self.relevantCodeSnippets = relevantCodeSnippets
42+
}
43+
}
44+
45+
public struct RelevantCodeSnippet: Codable {
46+
public var content: String
47+
public var priority: Int
48+
public var filePath: String
49+
50+
public init(content: String, priority: Int, filePath: String) {
51+
self.content = content
52+
self.priority = priority
53+
self.filePath = filePath
3854
}
3955
}
4056

4157
public protocol SuggestionServiceProvider {
4258
func getSuggestions(_ request: SuggestionRequest) async throws -> [CodeSuggestion]
43-
4459
func notifyAccepted(_ suggestion: CodeSuggestion) async
4560
func notifyRejected(_ suggestions: [CodeSuggestion]) async
4661
func notifyOpenTextDocument(fileURL: URL, content: String) async throws
@@ -49,5 +64,8 @@ public protocol SuggestionServiceProvider {
4964
func notifySaveTextDocument(fileURL: URL) async throws
5065
func cancelRequest() async
5166
func terminate() async
67+
68+
var configuration: SuggestionServiceConfiguration { get async }
5269
}
5370

71+
public typealias SuggestionServiceConfiguration = CopilotForXcodeKit.SuggestionServiceConfiguration

0 commit comments

Comments
 (0)