From adbfd5f248d390ae73eb9da636a457ce770c9ac0 Mon Sep 17 00:00:00 2001 From: pommicket Date: Thu, 29 Dec 2022 22:45:37 -0500 Subject: error LSPResponse member --- lsp-parse.c | 21 ++++++++++----------- lsp.c | 1 + lsp.h | 1 + main.c | 8 +++++++- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/lsp-parse.c b/lsp-parse.c index a892539..a6ef49f 100644 --- a/lsp-parse.c +++ b/lsp-parse.c @@ -643,15 +643,8 @@ static void process_message(LSP *lsp, JSON *json) { } JSONValue error = json_get(json, "error.message"); - if (error.type == JSON_STRING) { - char err[256] = {0}; - json_string_get(json, error.val.string, err, sizeof err); - printf("%s\n",err); - goto ret; - } - JSONValue result = json_get(json, "result"); - if (result.type != JSON_UNDEFINED) { + if (result.type != JSON_UNDEFINED || error.type == JSON_STRING) { // server-to-client response LSPResponse response = {0}; bool add_to_messages = false; @@ -659,7 +652,13 @@ static void process_message(LSP *lsp, JSON *json) { // make sure (LSPString){0} gets treated as an empty string arr_add(response.string_data, '\0'); - switch (response_to.type) { + if (error.type == JSON_STRING) { + response.error = json_string_get_alloc(json, error.val.string); + } + + if (response.error) { + add_to_messages = true; + } else switch (response_to.type) { case LSP_REQUEST_COMPLETION: add_to_messages = parse_completion(lsp, json, &response); break; @@ -700,13 +699,14 @@ static void process_message(LSP *lsp, JSON *json) { // it's some response we don't care about break; } + if (add_to_messages) { SDL_LockMutex(lsp->messages_mutex); LSPMessage *message = arr_addp(lsp->messages_server2client); message->type = LSP_RESPONSE; message->u.response = response; SDL_UnlockMutex(lsp->messages_mutex); - response_to.type = 0; // don't free + memset(&response_to, 0, sizeof response_to); // don't free } else { lsp_response_free(&response); } @@ -725,7 +725,6 @@ static void process_message(LSP *lsp, JSON *json) { } else { lsp_set_error(lsp, "Bad message from server (no result, no method)."); } - ret: lsp_request_free(&response_to); json_free(json); diff --git a/lsp.c b/lsp.c index 830f90d..e1fdd16 100644 --- a/lsp.c +++ b/lsp.c @@ -87,6 +87,7 @@ static void lsp_response_free(LSPResponse *r) { break; } lsp_request_free(&r->request); + free(r->error); memset(r, 0, sizeof *r); } diff --git a/lsp.h b/lsp.h index b97df7d..7d45f5b 100644 --- a/lsp.h +++ b/lsp.h @@ -298,6 +298,7 @@ typedef struct { typedef LSPRequestType LSPResponseType; typedef struct { LSPRequest request; // the request which this is a response to + char *error; // if not NULL, the data field will just be zeroed // LSP responses tend to have a lot of strings. // to avoid doing a ton of allocations+frees, // they're all stored here. diff --git a/main.c b/main.c index 766a426..2162577 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,5 @@ /* @TODO: -- LSPResponse is_error member (and make sure ide-*.c handles it) - some way of showing that we're currently loading the definition location (different cursor color?) - more LSP stuff: - go to definition using LSP @@ -892,6 +891,13 @@ int main(int argc, char **argv) { } break; case LSP_RESPONSE: { LSPResponse *r = &message.u.response; + if (r->error) { + // not displaying this right now + // idk it might be spammy + //ted_seterr(ted, "%s", r->error); + } + // it's important that we send error responses here too. + // we don't want to be waiting around for a response that's never coming. autocomplete_process_lsp_response(ted, r); signature_help_process_lsp_response(ted, r); hover_process_lsp_response(ted, r); -- cgit v1.2.3