Skip to content

Commit 479fc77

Browse files
committed
Update project to work in the new structure
1 parent b1795e4 commit 479fc77

24 files changed

+271
-281
lines changed

Copilot for Xcode.xcodeproj/project.pbxproj

Lines changed: 15 additions & 216 deletions
Large diffs are not rendered by default.

Copilot for Xcode/CopilotView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import AppKit
2+
import Client
23
import CopilotModel
34
import SwiftUI
45

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1410"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "Service"
18+
BuildableName = "Service"
19+
BlueprintName = "Service"
20+
ReferencedContainer = "container:">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
<TestableReference
32+
skipped = "NO">
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "ServiceTests"
36+
BuildableName = "ServiceTests"
37+
BlueprintName = "ServiceTests"
38+
ReferencedContainer = "container:">
39+
</BuildableReference>
40+
</TestableReference>
41+
</Testables>
42+
</TestAction>
43+
<LaunchAction
44+
buildConfiguration = "Debug"
45+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
46+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
47+
launchStyle = "0"
48+
useCustomWorkingDirectory = "NO"
49+
ignoresPersistentStateOnLaunch = "NO"
50+
debugDocumentVersioning = "YES"
51+
debugServiceExtension = "internal"
52+
allowLocationSimulation = "YES">
53+
</LaunchAction>
54+
<ProfileAction
55+
buildConfiguration = "Release"
56+
shouldUseLaunchSchemeArgsEnv = "YES"
57+
savedToolIdentifier = ""
58+
useCustomWorkingDirectory = "NO"
59+
debugDocumentVersioning = "YES">
60+
<MacroExpansion>
61+
<BuildableReference
62+
BuildableIdentifier = "primary"
63+
BlueprintIdentifier = "Service"
64+
BuildableName = "Service"
65+
BlueprintName = "Service"
66+
ReferencedContainer = "container:">
67+
</BuildableReference>
68+
</MacroExpansion>
69+
</ProfileAction>
70+
<AnalyzeAction
71+
buildConfiguration = "Debug">
72+
</AnalyzeAction>
73+
<ArchiveAction
74+
buildConfiguration = "Release"
75+
revealArchiveInOrganizer = "YES">
76+
</ArchiveAction>
77+
</Scheme>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1410"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
</BuildAction>
9+
<TestAction
10+
buildConfiguration = "Debug"
11+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
12+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
13+
shouldUseLaunchSchemeArgsEnv = "YES">
14+
<Testables>
15+
<TestableReference
16+
skipped = "NO">
17+
<BuildableReference
18+
BuildableIdentifier = "primary"
19+
BlueprintIdentifier = "ServiceTests"
20+
BuildableName = "ServiceTests"
21+
BlueprintName = "ServiceTests"
22+
ReferencedContainer = "container:">
23+
</BuildableReference>
24+
</TestableReference>
25+
</Testables>
26+
</TestAction>
27+
<LaunchAction
28+
buildConfiguration = "Debug"
29+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
30+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
31+
launchStyle = "0"
32+
useCustomWorkingDirectory = "NO"
33+
ignoresPersistentStateOnLaunch = "NO"
34+
debugDocumentVersioning = "YES"
35+
debugServiceExtension = "internal"
36+
allowLocationSimulation = "YES">
37+
</LaunchAction>
38+
<ProfileAction
39+
buildConfiguration = "Release"
40+
shouldUseLaunchSchemeArgsEnv = "YES"
41+
savedToolIdentifier = ""
42+
useCustomWorkingDirectory = "NO"
43+
debugDocumentVersioning = "YES">
44+
</ProfileAction>
45+
<AnalyzeAction
46+
buildConfiguration = "Debug">
47+
</AnalyzeAction>
48+
<ArchiveAction
49+
buildConfiguration = "Release"
50+
revealArchiveInOrganizer = "YES">
51+
</ArchiveAction>
52+
</Scheme>

Core/Package.swift

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,12 @@ let package = Package(
88
platforms: [.macOS(.v12)],
99
products: [
1010
.library(
11-
name: "CopilotService",
12-
targets: ["CopilotService", "SuggestionInjector"]
11+
name: "Service",
12+
targets: ["Service", "SuggestionInjector"]
1313
),
1414
.library(
15-
name: "CopilotModel",
16-
targets: ["CopilotModel"]
17-
),
18-
.library(
19-
name: "SuggestionInjector",
20-
targets: ["SuggestionInjector"]
15+
name: "Client",
16+
targets: ["CopilotModel", "Client"]
2117
),
2218
],
2319
dependencies: [
@@ -48,5 +44,21 @@ let package = Package(
4844
name: "SuggestionInjectorTests",
4945
dependencies: ["SuggestionInjector"]
5046
),
47+
.target(
48+
name: "Client",
49+
dependencies: ["CopilotModel", "XPCShared"]
50+
),
51+
.target(
52+
name: "Service",
53+
dependencies: ["CopilotModel", "CopilotService", "XPCShared"]
54+
),
55+
.target(
56+
name: "XPCShared",
57+
dependencies: ["CopilotModel"]
58+
),
59+
.testTarget(
60+
name: "ServiceTests",
61+
dependencies: ["Service", "Client", "CopilotService", "SuggestionInjector", "XPCShared"]
62+
),
5163
]
5264
)

Core/Sources/Client/AsyncXPCService.swift

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
import CopilotModel
22
import Foundation
3+
import XPCShared
34

4-
struct AsyncXPCService {
5+
public struct AsyncXPCService {
56
let connection: NSXPCConnection
7+
8+
public init(connection: NSXPCConnection) {
9+
self.connection = connection
10+
}
611

7-
func checkStatus() async throws -> CopilotStatus {
12+
public func checkStatus() async throws -> CopilotStatus {
813
try await withXPCServiceConnected(connection: connection) {
914
service, continuation in
1015
service.checkStatus { status, error in
@@ -20,7 +25,7 @@ struct AsyncXPCService {
2025
}
2126
}
2227

23-
func getVersion() async throws -> String {
28+
public func getVersion() async throws -> String {
2429
try await withXPCServiceConnected(connection: connection) {
2530
service, continuation in
2631
service.getVersion { version, error in
@@ -33,7 +38,7 @@ struct AsyncXPCService {
3338
}
3439
}
3540

36-
func signInInitiate() async throws -> (verificationUri: String, userCode: String) {
41+
public func signInInitiate() async throws -> (verificationUri: String, userCode: String) {
3742
try await withXPCServiceConnected(connection: connection) {
3843
service, continuation in
3944
service.signInInitiate { verificationUri, userCode, error in
@@ -46,7 +51,7 @@ struct AsyncXPCService {
4651
}
4752
}
4853

49-
func signInConfirm(userCode: String) async throws -> (username: String, status: CopilotStatus) {
54+
public func signInConfirm(userCode: String) async throws -> (username: String, status: CopilotStatus) {
5055
try await withXPCServiceConnected(connection: connection) {
5156
service, continuation in
5257
service.signInConfirm(userCode: userCode) { username, status, error in
@@ -62,7 +67,7 @@ struct AsyncXPCService {
6267
}
6368
}
6469

65-
func signOut() async throws -> CopilotStatus {
70+
public func signOut() async throws -> CopilotStatus {
6671
try await withXPCServiceConnected(connection: connection) {
6772
service, continuation in
6873
service.signOut { finishstatus, error in
@@ -75,39 +80,39 @@ struct AsyncXPCService {
7580
}
7681
}
7782

78-
func getSuggestedCode(editorContent: EditorContent) async throws -> UpdatedContent {
83+
public func getSuggestedCode(editorContent: EditorContent) async throws -> UpdatedContent {
7984
try await suggestionRequest(
8085
connection,
8186
editorContent,
8287
{ $0.getSuggestedCode }
8388
)
8489
}
8590

86-
func getNextSuggestedCode(editorContent: EditorContent) async throws -> UpdatedContent {
91+
public func getNextSuggestedCode(editorContent: EditorContent) async throws -> UpdatedContent {
8792
try await suggestionRequest(
8893
connection,
8994
editorContent,
9095
{ $0.getNextSuggestedCode }
9196
)
9297
}
9398

94-
func getPreviousSuggestedCode(editorContent: EditorContent) async throws -> UpdatedContent {
99+
public func getPreviousSuggestedCode(editorContent: EditorContent) async throws -> UpdatedContent {
95100
try await suggestionRequest(
96101
connection,
97102
editorContent,
98103
{ $0.getPreviousSuggestedCode }
99104
)
100105
}
101106

102-
func getSuggestionAcceptedCode(editorContent: EditorContent) async throws -> UpdatedContent {
107+
public func getSuggestionAcceptedCode(editorContent: EditorContent) async throws -> UpdatedContent {
103108
try await suggestionRequest(
104109
connection,
105110
editorContent,
106111
{ $0.getSuggestionAcceptedCode }
107112
)
108113
}
109114

110-
func getSuggestionRejectedCode(editorContent: EditorContent) async throws -> UpdatedContent {
115+
public func getSuggestionRejectedCode(editorContent: EditorContent) async throws -> UpdatedContent {
111116
try await suggestionRequest(
112117
connection,
113118
editorContent,
@@ -116,7 +121,7 @@ struct AsyncXPCService {
116121
}
117122
}
118123

119-
private struct AutoFinishContinuation<T> {
124+
struct AutoFinishContinuation<T> {
120125
var continuation: AsyncThrowingStream<T, Error>.Continuation
121126

122127
func resume(_ value: T) {
@@ -129,7 +134,7 @@ private struct AutoFinishContinuation<T> {
129134
}
130135
}
131136

132-
private func withXPCServiceConnected<T>(
137+
func withXPCServiceConnected<T>(
133138
connection: NSXPCConnection,
134139
_ fn: @escaping (XPCServiceProtocol, AutoFinishContinuation<T>) -> Void
135140
) async throws -> T {
@@ -142,7 +147,7 @@ private func withXPCServiceConnected<T>(
142147
return try await stream.first(where: { _ in true })!
143148
}
144149

145-
private func suggestionRequest(
150+
func suggestionRequest(
146151
_ connection: NSXPCConnection,
147152
_ editorContent: EditorContent,
148153
_ fn: @escaping (any XPCServiceProtocol) -> (Data, @escaping (Data?, Error?) -> Void) -> Void

Core/Sources/Client/XPCService.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import Foundation
2+
import XPCShared
23

3-
private var asyncService: AsyncXPCService?
4-
private var shared = XPCService()
4+
var asyncService: AsyncXPCService?
5+
var shared = XPCService()
56

6-
func getService() throws -> AsyncXPCService {
7+
public func getService() throws -> AsyncXPCService {
78
if ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1" {
89
struct RunningInPreview: Error {}
910
throw RunningInPreview()
@@ -18,7 +19,7 @@ func getService() throws -> AsyncXPCService {
1819
return service
1920
}
2021

21-
private class XPCService {
22+
class XPCService {
2223
var isInvalidated = false
2324

2425
lazy var connection: NSXPCConnection = {

Core/Sources/Service/Environment.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ private struct FailedToFetchFileURLError: Error, LocalizedError {
1616
enum Environment {
1717
static var now = { Date() }
1818

19-
static func fetchCurrentProjectRootURL() async throws -> URL? {
19+
static var fetchCurrentProjectRootURL: () async throws -> URL? = {
2020
let appleScript = """
2121
tell application "Xcode"
2222
return path of document of the first window
@@ -46,7 +46,7 @@ enum Environment {
4646
return nil
4747
}
4848

49-
static func fetchCurrentFileURL() async throws -> URL {
49+
static var fetchCurrentFileURL: () async throws -> URL = {
5050
var activeXcodes = [NSRunningApplication]()
5151
var retryCount = 0
5252
// Sometimes runningApplications returns 0 items.
@@ -97,11 +97,11 @@ enum Environment {
9797
throw FailedToFetchFileURLError()
9898
}
9999

100-
static func createAuthService() -> CopilotAuthServiceType {
100+
static var createAuthService: () -> CopilotAuthServiceType = {
101101
return CopilotAuthService()
102102
}
103103

104-
static func createSuggestionService(_ projectRootURL: URL) -> CopilotSuggestionServiceType {
104+
static var createSuggestionService: (_ projectRootURL: URL) -> CopilotSuggestionServiceType = { projectRootURL in
105105
return CopilotSuggestionService(projectRootURL: projectRootURL)
106106
}
107107
}

Core/Sources/Service/Workspace.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import CopilotModel
22
import CopilotService
33
import Foundation
44
import SuggestionInjector
5+
import XPCShared
56

67
@ServiceActor
78
final class Filespace {

0 commit comments

Comments
 (0)