From 431a785f20127a7f1b6c1a6f1cd2a5031a7236ca Mon Sep 17 00:00:00 2001 From: pommicket Date: Fri, 23 Dec 2022 15:00:20 -0500 Subject: only ask for completions if the server actually supports it --- lsp.c | 29 ++++++++++++++++++++++++++++- lsp.h | 3 ++- main.c | 1 - 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lsp.c b/lsp.c index 087d757..01a2bf6 100644 --- a/lsp.c +++ b/lsp.c @@ -53,6 +53,7 @@ static void lsp_request_free(LSPRequest *r) { arr_free(c->changes); } break; } + memset(r, 0, sizeof *r); } static void lsp_response_free(LSPResponse *r) { @@ -65,6 +66,7 @@ static void lsp_response_free(LSPResponse *r) { break; } lsp_request_free(&r->request); + memset(r, 0, sizeof *r); } void lsp_message_free(LSPMessage *message) { @@ -97,7 +99,32 @@ static bool has_response(const char *data, size_t data_len, u64 *p_offset, u64 * return offset + size <= data_len; } -void lsp_send_request(LSP *lsp, const LSPRequest *request) { +static bool lsp_supports_request(LSP *lsp, const LSPRequest *request) { + switch (request->type) { + case LSP_REQUEST_NONE: + case LSP_REQUEST_SHOW_MESSAGE: + case LSP_REQUEST_LOG_MESSAGE: + return false; + case LSP_REQUEST_INITIALIZE: + case LSP_REQUEST_INITIALIZED: + case LSP_REQUEST_DID_OPEN: + case LSP_REQUEST_DID_CLOSE: + case LSP_REQUEST_DID_CHANGE: + case LSP_REQUEST_SHUTDOWN: + case LSP_REQUEST_EXIT: + return true; + case LSP_REQUEST_COMPLETION: + return lsp->provides_completion; + } + assert(0); + return false; +} + +void lsp_send_request(LSP *lsp, LSPRequest *request) { + if (!lsp_supports_request(lsp, request)) { + lsp_request_free(request); + return; + } SDL_LockMutex(lsp->requests_mutex); arr_add(lsp->requests_client2server, *request); SDL_UnlockMutex(lsp->requests_mutex); diff --git a/lsp.h b/lsp.h index b4a4aa3..16a6491 100644 --- a/lsp.h +++ b/lsp.h @@ -296,7 +296,8 @@ typedef struct LSP { bool lsp_get_error(LSP *lsp, char *error, size_t error_size, bool clear); void lsp_message_free(LSPMessage *message); u32 lsp_document_id(LSP *lsp, const char *path); -void lsp_send_request(LSP *lsp, const LSPRequest *request); +// don't free the contents of this request! let me handle it! +void lsp_send_request(LSP *lsp, LSPRequest *request); const char *lsp_response_string(const LSPResponse *response, LSPString string); bool lsp_create(LSP *lsp, const char *analyzer_command); bool lsp_next_message(LSP *lsp, LSPMessage *message); diff --git a/main.c b/main.c index 661f4e9..f7d91a3 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,5 @@ /* @TODO: -- dont do completion if provides_completion = false - scroll through completions - LSP setting - figure out workspace -- cgit v1.2.3