diff options
author | pommicket <pommicket@gmail.com> | 2022-12-23 15:00:20 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-12-23 15:00:20 -0500 |
commit | 431a785f20127a7f1b6c1a6f1cd2a5031a7236ca (patch) | |
tree | a94ca3c12cdb666f56e7a8677225a71129989af4 | |
parent | 214dae3a7b58077436ffd173ae9fe8f2a6d9b97b (diff) |
only ask for completions if the server actually supports it
-rw-r--r-- | lsp.c | 29 | ||||
-rw-r--r-- | lsp.h | 3 | ||||
-rw-r--r-- | main.c | 1 |
3 files changed, 30 insertions, 3 deletions
@@ -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); @@ -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); @@ -1,6 +1,5 @@ /* @TODO: -- dont do completion if provides_completion = false - scroll through completions - LSP setting - figure out workspace |