diff options
author | pommicket <pommicket@gmail.com> | 2022-12-29 22:45:37 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-12-29 22:45:37 -0500 |
commit | adbfd5f248d390ae73eb9da636a457ce770c9ac0 (patch) | |
tree | 5b989332e857cb2dc9078595d8a46f654a82928a | |
parent | 43eea17544e4bed4384c76d3d95be2c0688b9e27 (diff) |
error LSPResponse member
-rw-r--r-- | lsp-parse.c | 21 | ||||
-rw-r--r-- | lsp.c | 1 | ||||
-rw-r--r-- | lsp.h | 1 | ||||
-rw-r--r-- | 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); @@ -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); } @@ -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. @@ -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); |