Skip to content

Commit df06ffb

Browse files
authored
Merge pull request #1519 from ahoppen/discard-void-response
Add a variant of `send` to `TestSourceKitLSPClient` that allows implicit discarding of `VoidResponse`
2 parents a4ab8c4 + 5d42fcd commit df06ffb

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
@@ -438,7 +438,7 @@ final class BackgroundIndexingTests: XCTestCase {
438438
)
439439

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

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

506506
project.testClient.send(DidChangeWatchedFilesNotification(changes: [FileEvent(uri: uri, type: .changed)]))
507-
_ = try await project.testClient.send(PollIndexRequest())
507+
try await project.testClient.send(PollIndexRequest())
508508

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

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

723723
allDocumentsOpened.signal()
724724
try libDPreparedForEditing.waitOrThrow()
@@ -848,7 +848,7 @@ final class BackgroundIndexingTests: XCTestCase {
848848
WorkspaceFolder(uri: DocumentURI(project.scratchDirectory))
849849
]
850850
)
851-
_ = try await otherClient.send(PollIndexRequest())
851+
try await otherClient.send(PollIndexRequest())
852852
}
853853

854854
func testOpeningFileThatIsNotPartOfThePackageDoesntGenerateABuildFolderThere() async throws {
@@ -901,7 +901,7 @@ final class BackgroundIndexingTests: XCTestCase {
901901
return VoidResponse()
902902
}
903903
_ = try project.openDocument("Lib.swift")
904-
_ = try await project.testClient.send(BarrierRequest())
904+
try await project.testClient.send(BarrierRequest())
905905
}
906906

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

11921192
// Simulate a package update which goes as follows:
@@ -1207,7 +1207,7 @@ final class BackgroundIndexingTests: XCTestCase {
12071207
FileEvent(uri: DocumentURI(project.scratchDirectory.appendingPathComponent("Package.resolved")), type: .changed)
12081208
])
12091209
)
1210-
_ = try await project.testClient.send(PollIndexRequest())
1210+
try await project.testClient.send(PollIndexRequest())
12111211
project.testClient.send(
12121212
DidChangeWatchedFilesNotification(
12131213
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)