Skip to content

Commit

Permalink
fix client/registerCapability, fix #299, fix #272
Browse files Browse the repository at this point in the history
Co-authored-by: davu <davu@mir-robots.com>
  • Loading branch information
WebFreak001 and vushu committed Jan 18, 2023
1 parent c942913 commit 2bd513a
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions lsp/source/served/lsp/jsonrpc.d
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 2bd513a

Please sign in to comment.