Skip to content

Commit 2120d12

Browse files
committed
Rename TestSourceKitServer to TestSourceKitClient
Really, what the class was mocking is a SourceKit-LSP client.
1 parent 0e85e54 commit 2120d12

26 files changed

+698
-621
lines changed

Sources/SKTestSupport/SKSwiftPMTestWorkspace.swift

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,16 @@ public final class SKSwiftPMTestWorkspace {
5353
public let toolchain: Toolchain
5454

5555
/// Connection to the language server.
56-
public let testServer: TestSourceKitServer
56+
public let testClient: TestSourceKitLSPClient
5757

5858
/// When `testServer` is not `nil`, the workspace will be opened in that server, otherwise a new server will be created for the workspace
59-
public init(projectDir: URL, tmpDir: URL, toolchain: Toolchain, testServer: TestSourceKitServer? = nil) async throws {
60-
self.testServer = testServer ?? TestSourceKitServer()
59+
public init(
60+
projectDir: URL,
61+
tmpDir: URL,
62+
toolchain: Toolchain,
63+
testClient: TestSourceKitLSPClient? = nil
64+
) async throws {
65+
self.testClient = testClient ?? TestSourceKitLSPClient()
6166

6267
self.projectDir = URL(
6368
fileURLWithPath: try resolveSymlinks(AbsolutePath(validating: projectDir.path)).pathString
@@ -103,7 +108,7 @@ public final class SKSwiftPMTestWorkspace {
103108
listenToUnitEvents: false
104109
)
105110

106-
let server = self.testServer.server
111+
let server = self.testClient.server
107112
let workspace = await Workspace(
108113
documentManager: DocumentManager(),
109114
rootUri: DocumentURI(sources.rootDirectory),
@@ -151,7 +156,7 @@ extension SKSwiftPMTestWorkspace {
151156

152157
extension SKSwiftPMTestWorkspace {
153158
public func openDocument(_ url: URL, language: Language) throws {
154-
testServer.send(
159+
testClient.send(
155160
DidOpenTextDocumentNotification(
156161
textDocument: TextDocumentItem(
157162
uri: DocumentURI(url),
@@ -164,15 +169,15 @@ extension SKSwiftPMTestWorkspace {
164169
}
165170

166171
public func closeDocument(_ url: URL) {
167-
testServer.send(DidCloseTextDocumentNotification(textDocument: TextDocumentIdentifier(DocumentURI(url))))
172+
testClient.send(DidCloseTextDocumentNotification(textDocument: TextDocumentIdentifier(DocumentURI(url))))
168173
}
169174
}
170175

171176
extension XCTestCase {
172177

173178
public func staticSourceKitSwiftPMWorkspace(
174179
name: String,
175-
server: TestSourceKitServer? = nil
180+
testClient: TestSourceKitLSPClient? = nil
176181
) async throws -> SKSwiftPMTestWorkspace? {
177182
let testDirName = testDirectoryName
178183
let toolchain = ToolchainRegistry.shared.default!
@@ -181,7 +186,7 @@ extension XCTestCase {
181186
tmpDir: URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true)
182187
.appendingPathComponent("sk-test-data/\(testDirName)/\(name)", isDirectory: true),
183188
toolchain: toolchain,
184-
testServer: server
189+
testClient: testClient
185190
)
186191

187192
let hasClangFile: Bool = workspace.sources.locations.contains { _, loc in

Sources/SKTestSupport/SKTibsTestWorkspace.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fileprivate extension SourceKitServer {
3636
public final class SKTibsTestWorkspace {
3737

3838
public let tibsWorkspace: TibsTestWorkspace
39-
public let testServer: TestSourceKitServer
39+
public let testClient: TestSourceKitLSPClient
4040

4141
public var index: IndexStoreDB { tibsWorkspace.index }
4242
public var builder: TibsBuilder { tibsWorkspace.builder }
@@ -49,9 +49,9 @@ public final class SKTibsTestWorkspace {
4949
removeTmpDir: Bool,
5050
toolchain: Toolchain,
5151
clientCapabilities: ClientCapabilities,
52-
testServer: TestSourceKitServer? = nil
52+
testClient: TestSourceKitLSPClient? = nil
5353
) async throws {
54-
self.testServer = testServer ?? TestSourceKitServer()
54+
self.testClient = testClient ?? TestSourceKitLSPClient()
5555
self.tibsWorkspace = try TibsTestWorkspace(
5656
immutableProjectDir: immutableProjectDir,
5757
persistentBuildDir: persistentBuildDir,
@@ -68,9 +68,9 @@ public final class SKTibsTestWorkspace {
6868
tmpDir: URL,
6969
toolchain: Toolchain,
7070
clientCapabilities: ClientCapabilities,
71-
testServer: TestSourceKitServer? = nil
71+
testClient: TestSourceKitLSPClient? = nil
7272
) async throws {
73-
self.testServer = testServer ?? TestSourceKitServer()
73+
self.testClient = testClient ?? TestSourceKitLSPClient()
7474

7575
self.tibsWorkspace = try TibsTestWorkspace(
7676
projectDir: projectDir,
@@ -98,8 +98,8 @@ public final class SKTibsTestWorkspace {
9898
indexDelegate: indexDelegate
9999
)
100100

101-
await workspace.buildSystemManager.setDelegate(testServer.server)
102-
await testServer.server.setWorkspaces([workspace])
101+
await workspace.buildSystemManager.setDelegate(testClient.server)
102+
await testClient.server.setWorkspaces([workspace])
103103
}
104104
}
105105

@@ -122,7 +122,7 @@ extension SKTibsTestWorkspace {
122122

123123
extension SKTibsTestWorkspace {
124124
public func openDocument(_ url: URL, language: Language) throws {
125-
testServer.send(
125+
testClient.send(
126126
DidOpenTextDocumentNotification(
127127
textDocument: TextDocumentItem(
128128
uri: DocumentURI(url),
@@ -142,7 +142,7 @@ extension XCTestCase {
142142
clientCapabilities: ClientCapabilities = .init(),
143143
tmpDir: URL? = nil,
144144
removeTmpDir: Bool = true,
145-
server: TestSourceKitServer? = nil
145+
testClient: TestSourceKitLSPClient? = nil
146146
) async throws -> SKTibsTestWorkspace? {
147147
let testDirName = testDirectoryName
148148
let workspace = try await SKTibsTestWorkspace(
@@ -156,7 +156,7 @@ extension XCTestCase {
156156
removeTmpDir: removeTmpDir,
157157
toolchain: ToolchainRegistry.shared.default!,
158158
clientCapabilities: clientCapabilities,
159-
testServer: server
159+
testClient: testClient
160160
)
161161

162162
if workspace.builder.targets.contains(where: { target in !target.clangTUs.isEmpty })

Sources/SKTestSupport/TestServer.swift renamed to Sources/SKTestSupport/TestSourceKitLSPClient.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ import SKSupport
1919
import SourceKitLSP
2020
import XCTest
2121

22-
public final class TestSourceKitServer: MessageHandler {
22+
/// A mock SourceKit-LSP client (aka. a mock editor) that behaves like an editor
23+
/// for testing purposes.
24+
///
25+
/// It can send requests to the LSP server and receive requests or notifications
26+
/// that the server sends to the client.
27+
public final class TestSourceKitLSPClient: MessageHandler {
28+
/// A function that takes a request and returns the request's response.
2329
public typealias RequestHandler<Request: RequestType> = (Request) -> Request.Response
2430

2531
public static let serverOptions: SourceKitServer.Options = SourceKitServer.Options()
@@ -37,7 +43,7 @@ public final class TestSourceKitServer: MessageHandler {
3743
public let server: SourceKitServer
3844

3945
/// The connection via which the server sends requests and notifications to us.
40-
private let clientConnection: LocalConnection
46+
private let serverToClientConnection: LocalConnection
4147

4248
/// Stream of the notifications that the server has sent to the client.
4349
private let notifications: AsyncStream<any NotificationType>
@@ -72,7 +78,7 @@ public final class TestSourceKitServer: MessageHandler {
7278
self.notificationYielder = notificationYielder
7379

7480
let clientConnection = LocalConnection()
75-
self.clientConnection = clientConnection
81+
self.serverToClientConnection = clientConnection
7682
server = SourceKitServer(
7783
client: clientConnection,
7884
options: serverOptions,
@@ -81,7 +87,7 @@ public final class TestSourceKitServer: MessageHandler {
8187
}
8288
)
8389

84-
self.clientConnection.start(handler: WeakMessageHandler(self))
90+
self.serverToClientConnection.start(handler: WeakMessageHandler(self))
8591
}
8692

8793
deinit {
@@ -207,6 +213,8 @@ public final class TestSourceKitServer: MessageHandler {
207213
}
208214
}
209215

216+
// MARK: - WeakMessageHelper
217+
210218
/// Wrapper around a weak `MessageHandler`.
211219
///
212220
/// This allows us to set the ``TestSourceKitServer`` as the message handler of

Tests/SKSwiftPMWorkspaceTests/SwiftPMWorkspaceTests.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ final class SwiftPMWorkspaceTests: XCTestCase {
4444
workspacePath: packageRoot,
4545
toolchainRegistry: tr,
4646
fileSystem: fs,
47-
buildSetup: TestSourceKitServer.serverOptions.buildSetup
47+
buildSetup: TestSourceKitLSPClient.serverOptions.buildSetup
4848
)
4949
)
5050
}
@@ -71,7 +71,7 @@ final class SwiftPMWorkspaceTests: XCTestCase {
7171
workspacePath: packageRoot,
7272
toolchainRegistry: tr,
7373
fileSystem: fs,
74-
buildSetup: TestSourceKitServer.serverOptions.buildSetup
74+
buildSetup: TestSourceKitLSPClient.serverOptions.buildSetup
7575
)
7676
)
7777
}
@@ -98,7 +98,7 @@ final class SwiftPMWorkspaceTests: XCTestCase {
9898
workspacePath: packageRoot,
9999
toolchainRegistry: ToolchainRegistry(),
100100
fileSystem: fs,
101-
buildSetup: TestSourceKitServer.serverOptions.buildSetup
101+
buildSetup: TestSourceKitLSPClient.serverOptions.buildSetup
102102
)
103103
)
104104
}
@@ -126,7 +126,7 @@ final class SwiftPMWorkspaceTests: XCTestCase {
126126
workspacePath: packageRoot,
127127
toolchainRegistry: tr,
128128
fileSystem: fs,
129-
buildSetup: TestSourceKitServer.serverOptions.buildSetup
129+
buildSetup: TestSourceKitLSPClient.serverOptions.buildSetup
130130
)
131131

132132
let aswift = packageRoot.appending(components: "Sources", "lib", "a.swift")
@@ -231,7 +231,7 @@ final class SwiftPMWorkspaceTests: XCTestCase {
231231
workspacePath: packageRoot,
232232
toolchainRegistry: tr,
233233
fileSystem: fs,
234-
buildSetup: TestSourceKitServer.serverOptions.buildSetup
234+
buildSetup: TestSourceKitLSPClient.serverOptions.buildSetup
235235
)
236236

237237
let source = try resolveSymlinks(packageRoot.appending(component: "Package.swift"))
@@ -265,7 +265,7 @@ final class SwiftPMWorkspaceTests: XCTestCase {
265265
workspacePath: packageRoot,
266266
toolchainRegistry: tr,
267267
fileSystem: fs,
268-
buildSetup: TestSourceKitServer.serverOptions.buildSetup
268+
buildSetup: TestSourceKitLSPClient.serverOptions.buildSetup
269269
)
270270

271271
let aswift = packageRoot.appending(components: "Sources", "lib", "a.swift")
@@ -309,7 +309,7 @@ final class SwiftPMWorkspaceTests: XCTestCase {
309309
workspacePath: packageRoot,
310310
toolchainRegistry: tr,
311311
fileSystem: fs,
312-
buildSetup: TestSourceKitServer.serverOptions.buildSetup
312+
buildSetup: TestSourceKitLSPClient.serverOptions.buildSetup
313313
)
314314

315315
let aswift = packageRoot.appending(components: "Sources", "libA", "a.swift")
@@ -371,7 +371,7 @@ final class SwiftPMWorkspaceTests: XCTestCase {
371371
workspacePath: packageRoot,
372372
toolchainRegistry: tr,
373373
fileSystem: fs,
374-
buildSetup: TestSourceKitServer.serverOptions.buildSetup
374+
buildSetup: TestSourceKitLSPClient.serverOptions.buildSetup
375375
)
376376

377377
let aswift = packageRoot.appending(components: "Sources", "libA", "a.swift")
@@ -407,7 +407,7 @@ final class SwiftPMWorkspaceTests: XCTestCase {
407407
workspacePath: packageRoot,
408408
toolchainRegistry: tr,
409409
fileSystem: fs,
410-
buildSetup: TestSourceKitServer.serverOptions.buildSetup
410+
buildSetup: TestSourceKitLSPClient.serverOptions.buildSetup
411411
)
412412

413413
let acxx = packageRoot.appending(components: "Sources", "lib", "a.cpp")
@@ -499,7 +499,7 @@ final class SwiftPMWorkspaceTests: XCTestCase {
499499
workspacePath: packageRoot,
500500
toolchainRegistry: ToolchainRegistry.shared,
501501
fileSystem: fs,
502-
buildSetup: TestSourceKitServer.serverOptions.buildSetup
502+
buildSetup: TestSourceKitLSPClient.serverOptions.buildSetup
503503
)
504504

505505
let aswift = packageRoot.appending(components: "Sources", "lib", "a.swift")
@@ -547,7 +547,7 @@ final class SwiftPMWorkspaceTests: XCTestCase {
547547
workspacePath: packageRoot,
548548
toolchainRegistry: tr,
549549
fileSystem: fs,
550-
buildSetup: TestSourceKitServer.serverOptions.buildSetup
550+
buildSetup: TestSourceKitLSPClient.serverOptions.buildSetup
551551
)
552552

553553
let aswift1 = packageRoot.appending(components: "Sources", "lib", "a.swift")
@@ -606,7 +606,7 @@ final class SwiftPMWorkspaceTests: XCTestCase {
606606
workspacePath: packageRoot,
607607
toolchainRegistry: tr,
608608
fileSystem: fs,
609-
buildSetup: TestSourceKitServer.serverOptions.buildSetup
609+
buildSetup: TestSourceKitLSPClient.serverOptions.buildSetup
610610
)
611611

612612
let acxx = packageRoot.appending(components: "Sources", "lib", "a.cpp")
@@ -651,7 +651,7 @@ final class SwiftPMWorkspaceTests: XCTestCase {
651651
workspacePath: packageRoot,
652652
toolchainRegistry: tr,
653653
fileSystem: fs,
654-
buildSetup: TestSourceKitServer.serverOptions.buildSetup
654+
buildSetup: TestSourceKitLSPClient.serverOptions.buildSetup
655655
)
656656

657657
let aswift = packageRoot.appending(components: "Sources", "lib", "a.swift")
@@ -687,7 +687,7 @@ final class SwiftPMWorkspaceTests: XCTestCase {
687687
workspacePath: packageRoot,
688688
toolchainRegistry: tr,
689689
fileSystem: fs,
690-
buildSetup: TestSourceKitServer.serverOptions.buildSetup
690+
buildSetup: TestSourceKitLSPClient.serverOptions.buildSetup
691691
)
692692

693693
assertEqual(await ws._packageRoot, try resolveSymlinks(tempDir.appending(component: "pkg")))
@@ -734,7 +734,7 @@ private func check(
734734

735735
private func buildPath(
736736
root: AbsolutePath,
737-
config: BuildSetup = TestSourceKitServer.serverOptions.buildSetup,
737+
config: BuildSetup = TestSourceKitLSPClient.serverOptions.buildSetup,
738738
platform: String
739739
) -> AbsolutePath {
740740
let buildPath = config.path ?? root.appending(component: ".build")

0 commit comments

Comments
 (0)