Skip to content

Commit

Permalink
Send empty result for requests without response
Browse files Browse the repository at this point in the history
All requests need to respond, otherwise it is a notification, not a request
  • Loading branch information
koliyo committed Nov 3, 2023
1 parent c4954f7 commit 57d5c87
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Sources/LSPClient/Client.ServerConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public extension ServerConnection {
}

func shutdown() async throws {
try await sendRequestWithErrorOnlyResult(.shutdown)
try await sendRequestWithErrorOnlyResult(.shutdown(ClientRequest.NullHandler))
}

func exit() async throws {
Expand Down Expand Up @@ -188,7 +188,7 @@ public extension ServerConnection {
// Workspace Requests
public extension ServerConnection {
func inlayHintRefresh() async throws {
try await sendRequestWithErrorOnlyResult(.workspaceInlayHintRefresh)
try await sendRequestWithErrorOnlyResult(.workspaceInlayHintRefresh(ClientRequest.NullHandler))
}

func willCreateFiles(params: CreateFilesParams) async throws -> WorkspaceWillCreateFilesResponse {
Expand Down
8 changes: 6 additions & 2 deletions Sources/LSPServer/Server.JSONRPCClientConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public actor JSONRPCClientConnection : ClientConnection {
eventContinuation.finish()
}

public func stop() {
eventContinuation.finish()
}


private func decodeNotificationParams<Params>(_ type: Params.Type, from data: Data) throws -> Params where Params : Decodable {
let note = try JSONDecoder().decode(JSONRPCNotification<Params>.self, from: data)
Expand Down Expand Up @@ -167,9 +171,9 @@ public actor JSONRPCClientConnection : ClientConnection {
case .initialize:
yield(id: id, request: ClientRequest.initialize(try decodeRequestParams(data), makeHandler(handler)))
case .shutdown:
yield(id: id, request: ClientRequest.shutdown)
yield(id: id, request: ClientRequest.shutdown(makeHandler(handler)))
case .workspaceInlayHintRefresh:
yield(id: id, request: ClientRequest.workspaceInlayHintRefresh)
yield(id: id, request: ClientRequest.workspaceInlayHintRefresh(makeHandler(handler)))
case .workspaceExecuteCommand:
yield(id: id, request: ClientRequest.workspaceExecuteCommand(try decodeRequestParams(data), makeHandler(handler)))
case .workspaceWillCreateFiles:
Expand Down
6 changes: 4 additions & 2 deletions Sources/LSPServer/Server.RequestHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ public extension RequestHandler {
switch request {
case let .initialize(params, handler):
await handler(await initialize(id: id, params: params))
case .shutdown:
case let .shutdown(handler):
await shutdown(id: id)
case .workspaceInlayHintRefresh:
await handler(.success(nil))
case let .workspaceInlayHintRefresh(handler):
await workspaceInlayHintRefresh(id: id)
await handler(.success(nil))
case let .workspaceExecuteCommand(params, handler):
await handler(await workspaceExecuteCommand(id: id, params: params))
case let .workspaceWillCreateFiles(params, handler):
Expand Down
6 changes: 4 additions & 2 deletions Sources/LanguageServerProtocol/LanguageServerProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public enum ClientRequest: Sendable {
// throw NullHandlerError.notImplemented(result)
}


public enum Method: String {
case initialize
case shutdown
Expand Down Expand Up @@ -175,9 +176,9 @@ public enum ClientRequest: Sendable {
}

case initialize(InitializeParams, Handler<InitializationResponse>)
case shutdown
case shutdown(Handler<LSPAny?>)
case workspaceExecuteCommand(ExecuteCommandParams, Handler<LSPAny?>)
case workspaceInlayHintRefresh
case workspaceInlayHintRefresh(Handler<LSPAny?>)
case workspaceWillCreateFiles(CreateFilesParams, Handler<WorkspaceEdit?>)
case workspaceWillRenameFiles(RenameFilesParams, Handler<WorkspaceEdit?>)
case workspaceWillDeleteFiles(DeleteFilesParams, Handler<WorkspaceEdit?>)
Expand Down Expand Up @@ -367,6 +368,7 @@ public enum ServerNotification: Sendable, Hashable {

public enum ServerRequest: Sendable {
public typealias Handler<T: Sendable & Encodable> = @Sendable (Result<T, AnyJSONRPCResponseError>) async -> Void
public typealias VoidHandler = @Sendable () async -> Void
public typealias ErrorOnlyHandler = @Sendable (AnyJSONRPCResponseError?) async -> Void

public enum Method: String {
Expand Down

0 comments on commit 57d5c87

Please sign in to comment.