From 2bd513a012901a47560e0f69163841aefc61a752 Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Wed, 18 Jan 2023 10:44:07 +0100 Subject: [PATCH] fix client/registerCapability, fix #299, fix #272 Co-authored-by: davu --- lsp/source/served/lsp/jsonrpc.d | 35 ++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/lsp/source/served/lsp/jsonrpc.d b/lsp/source/served/lsp/jsonrpc.d index 44bbad31..e10bf5d7 100644 --- a/lsp/source/served/lsp/jsonrpc.d +++ b/lsp/source/served/lsp/jsonrpc.d @@ -224,16 +224,33 @@ class RPCProcessor : Fiber void registerCapability(T)(scope const(char)[] id, scope const(char)[] method, T options) { - const(char)[][7] parts = [ - `{"jsonrpc":"2.0","method":"client/registerCapability","registrations":[{"id":"`, - id.escapeJsonStringContent, - `","method":"`, - method.escapeJsonStringContent, - `","registerOptions":`, - options.serializeJson, - `]}` + import mir.serde; + + @serdeFallbackStruct + struct RegistrationT + { + const(char)[] id; + const(char)[] method; + T registerOptions; + } + + @serdeFallbackStruct + struct RegistrationParamsT + { + RegistrationT[] registrations; + } + + static assert(RegistrationParamsT.tupleof.stringof == RegistrationParams.tupleof.stringof, + "Fields of templated `RegistrationParams` differ from regular struct, please verify correct field names in LSP spec!"); + static assert(RegistrationT.tupleof.stringof == Registration.tupleof.stringof, + "Fields of templated `Registration` differ from regular struct, please verify correct field names in LSP spec!"); + + scope RegistrationParamsT params; + params.registrations = [ + RegistrationT(id, method, options) ]; - sendRawPacket(parts[]); + + sendMethod("client/registerCapability", params); } /// Sends a request with the given `method` name to the other RPC side without any parameters.