From d86d2af6d098af2f98c776e648c649e35958c9c9 Mon Sep 17 00:00:00 2001 From: Aaron Cook Date: Sat, 20 Jun 2026 01:53:38 -0500 Subject: [PATCH] Add didOpen handler (WIP) --- src/pawn_lsp.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/pawn_lsp.c b/src/pawn_lsp.c index 56c3d18..0ac4ce2 100644 --- a/src/pawn_lsp.c +++ b/src/pawn_lsp.c @@ -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 _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); int @@ -79,7 +80,9 @@ _notify_handler(json_rpc_request_t *req, void *arg) 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); } else { log_warn("Unrecognized notification method\r\n"); @@ -151,6 +154,31 @@ _shutdown(json_rpc_request_t *req, cJSON **resp, void *arg) 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 _exit_notf(json_rpc_request_t *req, void *arg) {