Skip to content

Commit 5d42fcd

Browse files
committed
Add a variant of send to TestSourceKitLSPClient that allows implicit discarding of VoidResponse
Cleans up tests slightly.
1 parent 6aba969 commit 5d42fcd

11 files changed

+25
-20
lines changed

Sources/SKTestSupport/IndexedSingleSwiftFileTestProject.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public struct IndexedSingleSwiftFileTestProject {
136136
)
137137

138138
// Wait for the indexstore-db to finish indexing
139-
_ = try await testClient.send(PollIndexRequest())
139+
try await testClient.send(PollIndexRequest())
140140

141141
// Open the document
142142
self.fileURI = DocumentURI(testFileURL)

Sources/SKTestSupport/SwiftPMTestProject.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public class SwiftPMTestProject: MultiFileTestProject {
200200

201201
if pollIndex {
202202
// Wait for the indexstore-db to finish indexing
203-
_ = try await testClient.send(PollIndexRequest())
203+
try await testClient.send(PollIndexRequest())
204204
}
205205
}
206206

Sources/SKTestSupport/TestSourceKitLSPClient.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ public final class TestSourceKitLSPClient: MessageHandler, Sendable {
192192
}
193193
}
194194

195+
/// Variant of `send` above that allows the response to be discarded if it is a `VoidResponse`.
196+
public func send<R: RequestType>(_ request: R) async throws where R.Response == VoidResponse {
197+
let _: VoidResponse = try await self.send(request)
198+
}
199+
195200
/// Send the request to `server` and return the result via a completion handler.
196201
///
197202
/// This version of the `send` function should only be used if some action needs to be performed after the request is

Tests/SourceKitLSPTests/BackgroundIndexingTests.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ final class BackgroundIndexingTests: XCTestCase {
437437
)
438438

439439
project.testClient.send(DidChangeWatchedFilesNotification(changes: [FileEvent(uri: otherFileUri, type: .changed)]))
440-
_ = try await project.testClient.send(PollIndexRequest())
440+
try await project.testClient.send(PollIndexRequest())
441441

442442
let callsAfterEdit = try await project.testClient.send(
443443
CallHierarchyIncomingCallsRequest(item: try XCTUnwrap(prepare?.only))
@@ -503,7 +503,7 @@ final class BackgroundIndexingTests: XCTestCase {
503503
)
504504

505505
project.testClient.send(DidChangeWatchedFilesNotification(changes: [FileEvent(uri: uri, type: .changed)]))
506-
_ = try await project.testClient.send(PollIndexRequest())
506+
try await project.testClient.send(PollIndexRequest())
507507

508508
let callsAfterEdit = try await project.testClient.send(
509509
CallHierarchyIncomingCallsRequest(item: try XCTUnwrap(prepare?.only))
@@ -713,11 +713,11 @@ final class BackgroundIndexingTests: XCTestCase {
713713
// Ensure that LibC gets opened before LibD, so that LibD is the latest document. Two open requests don't have
714714
// dependencies between each other, so SourceKit-LSP is free to execute them in parallel or re-order them without
715715
// the barrier.
716-
_ = try await project.testClient.send(BarrierRequest())
716+
try await project.testClient.send(BarrierRequest())
717717
_ = try project.openDocument("LibD.swift")
718718

719719
// Send a barrier request to ensure we have finished opening LibD before allowing the preparation of LibB to finish.
720-
_ = try await project.testClient.send(BarrierRequest())
720+
try await project.testClient.send(BarrierRequest())
721721

722722
allDocumentsOpened.signal()
723723
try libDPreparedForEditing.waitOrThrow()
@@ -847,7 +847,7 @@ final class BackgroundIndexingTests: XCTestCase {
847847
WorkspaceFolder(uri: DocumentURI(project.scratchDirectory))
848848
]
849849
)
850-
_ = try await otherClient.send(PollIndexRequest())
850+
try await otherClient.send(PollIndexRequest())
851851
}
852852

853853
func testOpeningFileThatIsNotPartOfThePackageDoesntGenerateABuildFolderThere() async throws {
@@ -900,7 +900,7 @@ final class BackgroundIndexingTests: XCTestCase {
900900
return VoidResponse()
901901
}
902902
_ = try project.openDocument("Lib.swift")
903-
_ = try await project.testClient.send(BarrierRequest())
903+
try await project.testClient.send(BarrierRequest())
904904
}
905905

906906
func testImportPreparedModuleWithFunctionBodiesSkipped() async throws {
@@ -1185,7 +1185,7 @@ final class BackgroundIndexingTests: XCTestCase {
11851185
FileEvent(uri: DocumentURI(project.scratchDirectory.appendingPathComponent("Package.resolved")), type: .changed)
11861186
])
11871187
)
1188-
_ = try await project.testClient.send(PollIndexRequest())
1188+
try await project.testClient.send(PollIndexRequest())
11891189
XCTAssertEqual(try String(contentsOf: packageResolvedURL), originalPackageResolvedContents)
11901190

11911191
// Simulate a package update which goes as follows:
@@ -1206,7 +1206,7 @@ final class BackgroundIndexingTests: XCTestCase {
12061206
FileEvent(uri: DocumentURI(project.scratchDirectory.appendingPathComponent("Package.resolved")), type: .changed)
12071207
])
12081208
)
1209-
_ = try await project.testClient.send(PollIndexRequest())
1209+
try await project.testClient.send(PollIndexRequest())
12101210
project.testClient.send(
12111211
DidChangeWatchedFilesNotification(
12121212
changes: FileManager.default.findFiles(named: "Dependency.swift", in: project.scratchDirectory).map {

Tests/SourceKitLSPTests/CompilationDatabaseTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ final class CompilationDatabaseTests: XCTestCase {
6565
)
6666

6767
// Ensure that the DidChangeWatchedFilesNotification is handled before we continue.
68-
_ = try await project.testClient.send(BarrierRequest())
68+
try await project.testClient.send(BarrierRequest())
6969

7070
// DocumentHighlight should now point to the definition in the `#else` block.
7171

Tests/SourceKitLSPTests/DocumentTestDiscoveryTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ final class DocumentTestDiscoveryTests: XCTestCase {
178178
)
179179

180180
try await SwiftPMTestProject.build(at: project.scratchDirectory)
181-
_ = try await project.testClient.send(PollIndexRequest())
181+
try await project.testClient.send(PollIndexRequest())
182182

183183
// After indexing, we know that `LooksLikeTestCaseButIsNot` does not inherit from `XCTestCase` and we don't report any tests.
184184
let indexBasedTests = try await project.testClient.send(

Tests/SourceKitLSPTests/IndexTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ final class IndexTests: XCTestCase {
144144
XCTAssertEqual(versionContentsBefore.count, 1)
145145
XCTAssert(versionContentsBefore.first?.lastPathComponent.starts(with: "p") ?? false)
146146

147-
_ = try await project.testClient.send(ShutdownRequest())
147+
try await project.testClient.send(ShutdownRequest())
148148
return versionedPath
149149
}
150150

Tests/SourceKitLSPTests/RenameTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,7 @@ final class RenameTests: XCTestCase {
11451145
])
11461146
)
11471147

1148-
_ = try await project.testClient.send(PollIndexRequest())
1148+
try await project.testClient.send(PollIndexRequest())
11491149

11501150
let resultAfterFileMove = try await project.testClient.send(
11511151
RenameRequest(textDocument: TextDocumentIdentifier(callerUri), position: callerPositions["3️⃣"], newName: "bar")

Tests/SourceKitLSPTests/SwiftPMIntegration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ final class SwiftPMIntegrationTests: XCTestCase {
135135
)
136136

137137
// Ensure that the DidChangeWatchedFilesNotification is handled before we continue.
138-
_ = try await project.testClient.send(BarrierRequest())
138+
try await project.testClient.send(BarrierRequest())
139139

140140
let completions = try await project.testClient.send(
141141
CompletionRequest(textDocument: TextDocumentIdentifier(newFileUri), position: newFilePositions["2️⃣"])

Tests/SourceKitLSPTests/WorkspaceSymbolsTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class WorkspaceSymbolsTests: XCTestCase {
6464
enableBackgroundIndexing: true
6565
)
6666

67-
_ = try await project.testClient.send(PollIndexRequest())
67+
try await project.testClient.send(PollIndexRequest())
6868
let response = try await project.testClient.send(WorkspaceSymbolsRequest(query: "funcFrom"))
6969

7070
// Ideally, the item from the current package (PackageB) should be returned before the item from PackageA

Tests/SourceKitLSPTests/WorkspaceTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ final class WorkspaceTests: XCTestCase {
7777
},
7878
enableBackgroundIndexing: true
7979
)
80-
_ = try await project.testClient.send(PollIndexRequest())
80+
try await project.testClient.send(PollIndexRequest())
8181

8282
let (bUri, bPositions) = try project.openDocument("execB.swift")
8383

@@ -229,7 +229,7 @@ final class WorkspaceTests: XCTestCase {
229229

230230
let (uri, positions) = try project.openDocument("execA.swift")
231231

232-
_ = try await project.testClient.send(PollIndexRequest())
232+
try await project.testClient.send(PollIndexRequest())
233233

234234
let otherCompletions = try await project.testClient.send(
235235
CompletionRequest(textDocument: TextDocumentIdentifier(uri), position: positions["1️⃣"])
@@ -320,7 +320,7 @@ final class WorkspaceTests: XCTestCase {
320320
enableBackgroundIndexing: true
321321
)
322322

323-
_ = try await project.testClient.send(PollIndexRequest())
323+
try await project.testClient.send(PollIndexRequest())
324324

325325
let (bUri, bPositions) = try project.openDocument("execB.swift")
326326

@@ -362,7 +362,7 @@ final class WorkspaceTests: XCTestCase {
362362

363363
let (aUri, aPositions) = try project.openDocument("execA.swift")
364364

365-
_ = try await project.testClient.send(PollIndexRequest())
365+
try await project.testClient.send(PollIndexRequest())
366366

367367
let otherCompletions = try await project.testClient.send(
368368
CompletionRequest(textDocument: TextDocumentIdentifier(aUri), position: aPositions["1️⃣"])

0 commit comments

Comments
 (0)