Skip to content

Commit

Permalink
Add custom server requests
Browse files Browse the repository at this point in the history
This mirrors existing custom client requests for the server.
  • Loading branch information
mchakravarty committed Mar 27, 2024
1 parent 9d9ea23 commit da0312d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,8 @@ public actor JSONRPCServerConnection: ServerConnection {
let id = anyRequest.id

do {
guard let method = ServerRequest.Method(rawValue: methodName) else {
throw ServerError.unrecognizedMethod(methodName)
}

let method = ServerRequest.Method(rawValue: methodName) ?? .custom
switch method {
case .workspaceConfiguration:
let params = try decodeRequestParams(ConfigurationParams.self, from: data)
Expand Down Expand Up @@ -348,6 +346,11 @@ public actor JSONRPCServerConnection: ServerConnection {

yield(
id: id, request: ServerRequest.windowWorkDoneProgressCreate(params, reqHandler))
case .custom:
let params = try decodeRequestParams(LSPAny.self, from: data)
let reqHandler: ServerRequest.Handler<LSPAny> = makeHandler(handler)

yield(id: id, request: ServerRequest.custom(methodName, params, reqHandler))

}

Expand Down
6 changes: 6 additions & 0 deletions Sources/LanguageServerProtocol/LanguageServerProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ public enum ServerRequest: Sendable {
case windowShowMessageRequest = "window/showMessageRequest"
case windowShowDocument = "window/showDocument"
case windowWorkDoneProgressCreate = "window/workDoneProgress/create"
case custom
}

case workspaceConfiguration(ConfigurationParams, Handler<[LSPAny]>)
Expand All @@ -515,6 +516,7 @@ public enum ServerRequest: Sendable {
case windowShowMessageRequest(ShowMessageRequestParams, Handler<ShowMessageRequestResponse>)
case windowShowDocument(ShowDocumentParams, Handler<ShowDocumentResult>)
case windowWorkDoneProgressCreate(WorkDoneProgressCreateParams, ErrorOnlyHandler)
case custom(String, LSPAny, Handler<LSPAny>)

public var method: Method {
switch self {
Expand All @@ -538,6 +540,8 @@ public enum ServerRequest: Sendable {
return .windowShowDocument
case .windowWorkDoneProgressCreate:
return .windowWorkDoneProgressCreate
case .custom:
return .custom
}
}

Expand Down Expand Up @@ -566,6 +570,8 @@ public enum ServerRequest: Sendable {
await handler(.failure(protocolError))
case let .windowWorkDoneProgressCreate(_, handler):
await handler(protocolError)
case let .custom(_, _, handler):
await handler(.failure(protocolError))
}
}
}
Expand Down

0 comments on commit da0312d

Please sign in to comment.