Skip to content

Commit 7a95075

Browse files
authored
Merge pull request #1842 from ahoppen/shutdown-null
Reply with `null` to `shutdown` request
2 parents 4688242 + e073a01 commit 7a95075

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

Sources/LanguageServerProtocol/Requests/ShutdownRequest.swift

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,17 @@
1818
/// - Returns: Void.
1919
public struct ShutdownRequest: RequestType, Hashable {
2020
public static let method: String = "shutdown"
21-
public typealias Response = VoidResponse
21+
22+
public struct Response: ResponseType, Equatable {
23+
public init() {}
24+
25+
public init(from decoder: any Decoder) throws {}
26+
27+
public func encode(to encoder: any Encoder) throws {
28+
var container = encoder.singleValueContainer()
29+
try container.encodeNil()
30+
}
31+
}
2232

2333
public init() {}
2434
}
25-
26-
@available(*, deprecated, renamed: "ShutdownRequest")
27-
public typealias Shutdown = ShutdownRequest

Sources/SourceKitLSP/SourceKitLSPServer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ extension SourceKitLSPServer {
11381138
}
11391139
}
11401140

1141-
func shutdown(_ request: ShutdownRequest) async throws -> VoidResponse {
1141+
func shutdown(_ request: ShutdownRequest) async throws -> ShutdownRequest.Response {
11421142
await prepareForExit()
11431143

11441144
await withTaskGroup(of: Void.self) { taskGroup in
@@ -1169,7 +1169,7 @@ extension SourceKitLSPServer {
11691169
// Otherwise we might terminate sourcekit-lsp while it still has open
11701170
// connections to the toolchain servers, which could send messages to
11711171
// sourcekit-lsp while it is being deallocated, causing crashes.
1172-
return VoidResponse()
1172+
return ShutdownRequest.Response()
11731173
}
11741174

11751175
func exit(_ notification: ExitNotification) async {

Tests/LanguageServerProtocolTests/CodingTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,10 @@ final class CodingTests: XCTestCase {
13431343
"""
13441344
)
13451345
}
1346+
1347+
func testShutdownResponse() {
1348+
checkCoding(ShutdownRequest.Response(), json: "null")
1349+
}
13461350
}
13471351

13481352
func with<T>(_ value: T, mutate: (inout T) -> Void) -> T {

Tests/SourceKitLSPTests/IndexTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ final class IndexTests: XCTestCase {
141141
"Received unexpected version: \(versionContentsBefore.first?.lastPathComponent ?? "<nil>")"
142142
)
143143

144-
try await project.testClient.send(ShutdownRequest())
144+
_ = try await project.testClient.send(ShutdownRequest())
145145
return versionedPath
146146
}
147147

0 commit comments

Comments
 (0)