Compare commits

..

3 Commits

Author SHA1 Message Date
d489362a28
json-rpc-test-server: implement rpc.discover 2020-10-13 20:54:27 +02:00
c87869bef7
Cleanup
Prevent the last fuck-up from happening again.
2020-10-13 20:30:33 +02:00
fcf65f8377
Add libedit autocompletion back in
I've mistakenly removed it in the M-Enter change.
2020-10-13 20:19:19 +02:00
2 changed files with 51 additions and 11 deletions

View File

@ -663,6 +663,14 @@ input_el_install_prompt (struct input_el *self)
static unsigned char input_el_on_complete (EditLine *editline, int key); static unsigned char input_el_on_complete (EditLine *editline, int key);
static void
input_el_addbind (EditLine *editline, const char *name, const char *desc,
unsigned char (*function) (EditLine *, int), const char *binding)
{
el_set (editline, EL_ADDFN, name, desc, function);
el_set (editline, EL_BIND, binding, name, NULL);
}
static void static void
input_el_start (struct input *input, const char *program_name) input_el_start (struct input *input, const char *program_name)
{ {
@ -681,16 +689,15 @@ input_el_start (struct input *input, const char *program_name)
el_set (self->editline, EL_BIND, "^u", "vi-kill-line-prev", NULL); el_set (self->editline, EL_BIND, "^u", "vi-kill-line-prev", NULL);
// It's probably better to handle these ourselves // It's probably better to handle these ourselves
el_set (self->editline, EL_ADDFN, input_el_addbind (self->editline, "send-line", "Send line",
"send-line", "Send line", input_el_on_return); input_el_on_return, "\n");
el_set (self->editline, EL_BIND, "\n", "send-line", NULL); input_el_addbind (self->editline, "run-editor", "Run editor to edit line",
el_set (self->editline, EL_ADDFN, input_el_on_run_editor, "M-e");
"run-editor", "Run editor to edit line", input_el_on_run_editor);
el_set (self->editline, EL_BIND, "M-e", "run-editor", NULL);
el_set (self->editline, EL_ADDFN, input_el_addbind (self->editline, "complete", "Complete word",
"newline-insert", "Insert a newline", input_el_on_newline_insert); input_el_on_complete, "\t");
el_set (self->editline, EL_BIND, "M-\n", "newline-insert", NULL); input_el_addbind (self->editline, "newline-insert", "Insert a newline",
input_el_on_newline_insert, "M-\n");
// Source the user's defaults file // Source the user's defaults file
el_source (self->editline, NULL); el_source (self->editline, NULL);

View File

@ -1446,6 +1446,38 @@ json_rpc_handler_info_cmp (const void *first, const void *second)
((struct json_rpc_handler_info *) second)->method_name); ((struct json_rpc_handler_info *) second)->method_name);
} }
static json_t *
open_rpc_describe (const char *method, json_t *result)
{
return json_pack ("{sssoso}", "name", method, "params", json_pack ("[]"),
"result", json_pack ("{ssso}", "name", method, "schema", result));
}
// This server rarely sees changes and we can afford to hardcode the schema
static json_t *
json_rpc_discover (struct server_context *ctx, json_t *params)
{
(void) ctx;
(void) params;
json_t *info = json_pack ("{ssss}",
"title", PROGRAM_NAME, "version", PROGRAM_VERSION);
json_t *methods = json_pack ("[ooo]",
open_rpc_describe ("date", json_pack ("{ssso}", "type", "object",
"properties", json_pack ("{s{ss}s{ss}s{ss}s{ss}s{ss}s{ss}}",
"year", "type", "number",
"month", "type", "number",
"day", "type", "number",
"hours", "type", "number",
"minutes", "type", "number",
"seconds", "type", "number"))),
open_rpc_describe ("ping", json_pack ("{ss}", "type", "string")),
open_rpc_describe ("rpc.discover", json_pack ("{ss}", "$ref",
"https://github.com/open-rpc/meta-schema/raw/master/schema.json")));
return json_rpc_response (NULL, json_pack ("{sssoso}",
"openrpc", "1.2.6", "info", info, "methods", methods), NULL);
}
static json_t * static json_t *
json_rpc_ping (struct server_context *ctx, json_t *params) json_rpc_ping (struct server_context *ctx, json_t *params)
{ {
@ -1487,8 +1519,9 @@ process_json_rpc_request (struct server_context *ctx, json_t *request)
// Eventually it might be better to move this into a map in the context. // Eventually it might be better to move this into a map in the context.
static struct json_rpc_handler_info handlers[] = static struct json_rpc_handler_info handlers[] =
{ {
{ "date", json_rpc_date }, { "date", json_rpc_date },
{ "ping", json_rpc_ping }, { "ping", json_rpc_ping },
{ "rpc.discover", json_rpc_discover },
}; };
if (!json_is_object (request)) if (!json_is_object (request))