From 4e73c6a204383667aad6ce3905e16aee2a172fb6 Mon Sep 17 00:00:00 2001 From: pommicket Date: Tue, 3 Jan 2023 23:35:02 -0500 Subject: fix double-free response_to also cancel old workspace/symbols requests --- development.md | 2 ++ ide-definitions.c | 5 ++++- lsp-parse.c | 6 ++++-- main.c | 1 + 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/development.md b/development.md index 4f59f1f..7193bfa 100644 --- a/development.md +++ b/development.md @@ -21,6 +21,8 @@ in `util.c` even if they use OS-specific library functions.) ## Adding languages +## Adding LSP features + ## Releasing When releasing a new version of `ted`: diff --git a/ide-definitions.c b/ide-definitions.c index d86e6b3..67ac51d 100644 --- a/ide-definitions.c +++ b/ide-definitions.c @@ -55,7 +55,7 @@ void definition_goto(Ted *ted, LSP *lsp, const char *name, LSPDocumentPosition p Definitions *defs = &ted->definitions; if (lsp) { // cancel old request - ted_cancel_lsp_request(ted, defs->last_request_lsp, defs->last_request_id); + definition_cancel_lookup(ted); LSPRequestType request_type = LSP_REQUEST_DEFINITION; switch (type) { case GOTO_DEFINITION: @@ -153,6 +153,7 @@ static void definitions_selector_filter_entries(Ted *ted) { arr_qsort(sel->entries, definition_entry_qsort_cmp); sel->n_entries = arr_len(sel->entries); + sel->cursor = clamp_u32(sel->cursor, 0, sel->n_entries); } @@ -232,6 +233,8 @@ void definitions_send_request_if_needed(Ted *ted) { LSPRequest request = {.type = LSP_REQUEST_WORKSPACE_SYMBOLS}; LSPRequestWorkspaceSymbols *syms = &request.data.workspace_symbols; syms->query = str_dup(query); + // cancel old request + definition_cancel_lookup(ted); defs->last_request_id = lsp_send_request(lsp, &request); defs->last_request_lsp = lsp->id; defs->last_request_time = ted->frame_time; diff --git a/lsp-parse.c b/lsp-parse.c index 42f2291..4c3e95f 100644 --- a/lsp-parse.c +++ b/lsp-parse.c @@ -879,6 +879,9 @@ void process_message(LSP *lsp, JSON *json) { LSPResponse response = {0}; bool add_to_messages = false; response.request = response_to; + // now response_to is response's responsibility + memset(&response_to, 0, sizeof response_to); + // make sure (LSPString){0} gets treated as an empty string arr_add(response.string_data, '\0'); @@ -889,7 +892,7 @@ void process_message(LSP *lsp, JSON *json) { if (response.error) { if (error_code != LSP_ERROR_REQUEST_CANCELLED) add_to_messages = true; - } else switch (response_to.type) { + } else switch (response.request.type) { case LSP_REQUEST_COMPLETION: add_to_messages = parse_completion(lsp, json, &response); break; @@ -952,7 +955,6 @@ void process_message(LSP *lsp, JSON *json) { message->type = LSP_RESPONSE; message->u.response = response; SDL_UnlockMutex(lsp->messages_mutex); - memset(&response_to, 0, sizeof response_to); // don't free } else { lsp_response_free(&response); } diff --git a/main.c b/main.c index a130706..231177f 100644 --- a/main.c +++ b/main.c @@ -2,6 +2,7 @@ @TODO: - ted.h documentation - document lsp.h and lsp.c. +- debug-lsp option (which logs LSP messages) - check LSP process status (TEST: what happens if LSP server is not installed) - make tags_dir the root folder - check that tags still works -- cgit v1.2.3