Requests should be constructible with implicit member expressions when the expected type is RequestType.
func handle<Request: RequestType>(request: Request) async -> Request.Response { .... }
func test() {
handle(.<COMPLETE>)
}
To do that,
- Introduce
LSPRequestType that inherits RequestType
- Every LSP request should inherit
LSPRequestType
- All LSP request handling function should accept
LSPRequestType instead of RequestType
- For every request type, declare
extension LSPRequestType where Self == XXXRequest to declare a static factory func
I.e.
public protocol LSPRequestType: RequestType {}
public struct ApplyEditRequest: LSPRequestType, Hashable { ... }
extension LSPRequestType where Self == ApplyEditRequest {
public static func applyEdit(label: String? = nil, edit: WorkspaceEdit) -> Self {
.init(label: label, edit: edit)
}
}
This applies to LSP requests and notifications, and BSP requests and notifications