Add didOpen handler (WIP)

This commit is contained in:
Aaron Cook 2026-06-20 01:53:38 -05:00
commit d86d2af6d0

View file

@ -16,6 +16,7 @@ static void _notify_handler(json_rpc_request_t *req, void *arg);
static int _initialize(json_rpc_request_t *req, cJSON **resp, void *arg); static int _initialize(json_rpc_request_t *req, cJSON **resp, void *arg);
static int _shutdown(json_rpc_request_t *req, cJSON **resp, void *arg); static int _shutdown(json_rpc_request_t *req, cJSON **resp, void *arg);
static void _didopen_notf(json_rpc_request_t *req, void *arg);
static void _exit_notf(json_rpc_request_t *req, void *arg); static void _exit_notf(json_rpc_request_t *req, void *arg);
int int
@ -79,7 +80,9 @@ _notify_handler(json_rpc_request_t *req, void *arg)
log_info("Handle notification \"%s\"\r\n", method); log_info("Handle notification \"%s\"\r\n", method);
if (!strcmp(method, "exit")) { if (!strcmp(method, "textDocument/didOpen")) {
_didopen_notf(req, arg);
} else if (!strcmp(method, "exit")) {
_exit_notf(req, arg); _exit_notf(req, arg);
} else { } else {
log_warn("Unrecognized notification method\r\n"); log_warn("Unrecognized notification method\r\n");
@ -151,6 +154,31 @@ _shutdown(json_rpc_request_t *req, cJSON **resp, void *arg)
return (0); return (0);
} }
static void
_didopen_notf(json_rpc_request_t *req, void *arg) {
cJSON *textdoc = cJSON_GetObjectItem(req->params, "textDocument");
cJSON *val;
if ((textdoc == NULL) || (!cJSON_IsObject(textdoc))) {
log_error("Invalid textDocument field\r\n");
return;
}
val = cJSON_GetObjectItem(textdoc, "uri");
if (val && cJSON_IsString(val)) {
log_info("textdoc uri: %s\r\n", val->valuestring);
} else {
log_warn("Invalid uri\r\n");
}
val = cJSON_GetObjectItem(textdoc, "text");
if (val && cJSON_IsString(val)) {
log_info("textdoc text: \"%s\"\r\n", val->valuestring);
} else {
log_warn("Invalid text\r\n");
}
}
static void static void
_exit_notf(json_rpc_request_t *req, void *arg) _exit_notf(json_rpc_request_t *req, void *arg)
{ {