Skip to content

Commit 9e49f67

Browse files
committed
Rename TestSourceKitLSPClient.handleNextRequest to handleSingleRequest
Since `handleNextRequest` handling doesn’t have to be in the order that the request handlers were specified anymore, the naming was misleading.
1 parent 950a74a commit 9e49f67

File tree

9 files changed

+19
-23
lines changed

9 files changed

+19
-23
lines changed

Sources/SKTestSupport/TestSourceKitLSPClient.swift

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public final class TestSourceKitLSPClient: MessageHandler {
147147
throw ConflictingDiagnosticsError()
148148
}
149149
capabilities.textDocument!.diagnostic = .init(dynamicRegistration: true)
150-
self.handleNextRequest { (request: RegisterCapabilityRequest) in
150+
self.handleSingleRequest { (request: RegisterCapabilityRequest) in
151151
XCTAssertEqual(request.registrations.only?.method, DocumentDiagnosticsRequest.method)
152152
return VoidResponse()
153153
}
@@ -258,22 +258,17 @@ public final class TestSourceKitLSPClient: MessageHandler {
258258
}
259259
}
260260

261-
/// Handle the next request that is sent to the client with the given handler.
261+
/// Handle the next request of the given type that is sent to the client.
262262
///
263-
/// By default, `TestSourceKitLSPClient` emits an `XCTFail` if a request is sent
264-
/// to the client, since it doesn't know how to handle it. This allows the
265-
/// simulation of a single request's handling on the client.
266-
///
267-
/// If the next request that is sent to the client is of a different kind than
268-
/// the given handler, `TestSourceKitLSPClient` will emit an `XCTFail`.
269-
public func handleNextRequest<R: RequestType>(_ requestHandler: @escaping RequestHandler<R>) {
263+
/// The request handler will only handle a single request. If the request is called again, the request handler won't
264+
/// call again
265+
public func handleSingleRequest<R: RequestType>(_ requestHandler: @escaping RequestHandler<R>) {
270266
requestHandlers.value.append(requestHandler)
271267
}
272268

273269
// MARK: - Conformance to MessageHandler
274270

275-
/// - Important: Implementation detail of `TestSourceKitLSPServer`. Do not call
276-
/// from tests.
271+
/// - Important: Implementation detail of `TestSourceKitLSPServer`. Do not call from tests.
277272
public func handle(_ params: some NotificationType) {
278273
notificationYielder.yield(params)
279274
}

Tests/SourceKitDTests/CrashRecoveryTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ final class CrashRecoveryTests: XCTestCase {
7575
"Sanity check failed. The Hover response did not contain foo(), even before crashing sourcekitd. Received response: \(String(describing: preCrashHoverResponse))"
7676
)
7777

78-
testClient.handleNextRequest { (request: CreateWorkDoneProgressRequest) -> VoidResponse in
78+
testClient.handleSingleRequest { (request: CreateWorkDoneProgressRequest) -> VoidResponse in
7979
return VoidResponse()
8080
}
8181

Tests/SourceKitLSPTests/BackgroundIndexingTests.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ final class BackgroundIndexingTests: XCTestCase {
346346
capabilities: ClientCapabilities(window: WindowClientCapabilities(workDoneProgress: true)),
347347
serverOptions: backgroundIndexingOptions,
348348
preInitialization: { testClient in
349-
testClient.handleNextRequest { (request: CreateWorkDoneProgressRequest) in
349+
testClient.handleSingleRequest { (request: CreateWorkDoneProgressRequest) in
350350
workDoneProgressCreated.fulfill()
351351
return VoidResponse()
352352
}
@@ -577,7 +577,8 @@ final class BackgroundIndexingTests: XCTestCase {
577577
)
578578

579579
let receivedEmptyDiagnostics = self.expectation(description: "Received diagnostic refresh request")
580-
project.testClient.handleNextRequest { (_: DiagnosticsRefreshRequest) in
580+
581+
project.testClient.handleSingleRequest { (_: DiagnosticsRefreshRequest) in
581582
Task {
582583
let updatedDiagnostics = try await project.testClient.send(
583584
DocumentDiagnosticsRequest(textDocument: TextDocumentIdentifier(uri))

Tests/SourceKitLSPTests/CodeActionTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ final class CodeActionTests: XCTestCase {
470470

471471
let editReceived = self.expectation(description: "Received ApplyEdit request")
472472

473-
testClient.handleNextRequest { (request: ApplyEditRequest) -> ApplyEditResponse in
473+
testClient.handleSingleRequest { (request: ApplyEditRequest) -> ApplyEditResponse in
474474
defer {
475475
editReceived.fulfill()
476476
}

Tests/SourceKitLSPTests/DefinitionTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ class DefinitionTests: XCTestCase {
414414
// Wait until SourceKit-LSP has handled the `DidChangeWatchedFilesNotification` (which it only does after a delay
415415
// because it debounces these notifications), indicated by it telling us that we should refresh diagnostics.
416416
let diagnosticRefreshRequestReceived = self.expectation(description: "DiagnosticsRefreshRequest received")
417-
project.testClient.handleNextRequest { (request: DiagnosticsRefreshRequest) in
417+
project.testClient.handleSingleRequest { (request: DiagnosticsRefreshRequest) in
418418
diagnosticRefreshRequestReceived.fulfill()
419419
return VoidResponse()
420420
}
@@ -489,7 +489,7 @@ class DefinitionTests: XCTestCase {
489489
// Wait until SourceKit-LSP has handled the `DidChangeWatchedFilesNotification` (which it only does after a delay
490490
// because it debounces these notifications), indicated by it telling us that we should refresh diagnostics.
491491
let diagnosticRefreshRequestReceived = self.expectation(description: "DiagnosticsRefreshRequest received")
492-
project.testClient.handleNextRequest { (request: DiagnosticsRefreshRequest) in
492+
project.testClient.handleSingleRequest { (request: DiagnosticsRefreshRequest) in
493493
diagnosticRefreshRequestReceived.fulfill()
494494
return VoidResponse()
495495
}

Tests/SourceKitLSPTests/ExecuteCommandTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ final class ExecuteCommandTests: XCTestCase {
4444

4545
let request = ExecuteCommandRequest(command: command.command, arguments: command.arguments)
4646

47-
testClient.handleNextRequest { (req: ApplyEditRequest) -> ApplyEditResponse in
47+
testClient.handleSingleRequest { (req: ApplyEditRequest) -> ApplyEditResponse in
4848
return ApplyEditResponse(applied: true, failureReason: nil)
4949
}
5050

@@ -100,7 +100,7 @@ final class ExecuteCommandTests: XCTestCase {
100100

101101
let request = ExecuteCommandRequest(command: command.command, arguments: command.arguments)
102102

103-
testClient.handleNextRequest { (req: ApplyEditRequest) -> ApplyEditResponse in
103+
testClient.handleSingleRequest { (req: ApplyEditRequest) -> ApplyEditResponse in
104104
return ApplyEditResponse(applied: true, failureReason: nil)
105105
}
106106

Tests/SourceKitLSPTests/LocalClangTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ final class LocalClangTests: XCTestCase {
201201
XCTAssertEqual(command.command, "clangd.applyTweak")
202202

203203
let applyEdit = XCTestExpectation(description: "applyEdit")
204-
testClient.handleNextRequest { (request: ApplyEditRequest) -> ApplyEditResponse in
204+
testClient.handleSingleRequest { (request: ApplyEditRequest) -> ApplyEditResponse in
205205
XCTAssertNotNil(request.edit.changes)
206206
applyEdit.fulfill()
207207
return ApplyEditResponse(applied: true, failureReason: nil)

Tests/SourceKitLSPTests/PullDiagnosticsTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ final class PullDiagnosticsTests: XCTestCase {
161161
XCTAssert(fullReportBeforeChangingFileA.items.contains(where: { $0.message == "Cannot find 'sayHello' in scope" }))
162162

163163
let diagnosticsRefreshRequestReceived = self.expectation(description: "DiagnosticsRefreshRequest received")
164-
project.testClient.handleNextRequest { (request: DiagnosticsRefreshRequest) in
164+
project.testClient.handleSingleRequest { (request: DiagnosticsRefreshRequest) in
165165
diagnosticsRefreshRequestReceived.fulfill()
166166
return VoidResponse()
167167
}
@@ -224,7 +224,7 @@ final class PullDiagnosticsTests: XCTestCase {
224224
XCTAssert(fullReportBeforeBuilding.items.contains(where: { $0.message == "No such module 'LibA'" }))
225225

226226
let diagnosticsRefreshRequestReceived = self.expectation(description: "DiagnosticsRefreshRequest received")
227-
project.testClient.handleNextRequest { (request: DiagnosticsRefreshRequest) in
227+
project.testClient.handleSingleRequest { (request: DiagnosticsRefreshRequest) in
228228
diagnosticsRefreshRequestReceived.fulfill()
229229
return VoidResponse()
230230
}

Tests/SourceKitLSPTests/SemanticTokensTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ final class SemanticTokensTests: XCTestCase {
7171
// We will wait for the server to dynamically register semantic tokens
7272

7373
let registerCapabilityExpectation = expectation(description: "\(#function) - register semantic tokens capability")
74-
testClient.handleNextRequest { (req: RegisterCapabilityRequest) -> VoidResponse in
74+
testClient.handleSingleRequest { (req: RegisterCapabilityRequest) -> VoidResponse in
7575
let capabilityRegistration = req.registrations.first { reg in
7676
reg.method == SemanticTokensRegistrationOptions.method
7777
}

0 commit comments

Comments
 (0)