summaryrefslogtreecommitdiff
path: root/lsp.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-01-07 13:01:09 -0500
committerpommicket <pommicket@gmail.com>2023-01-07 13:01:09 -0500
commit7640ecce499fc49cad3d9b9f391cce0b74e435c9 (patch)
treec0936d64de36d84d61be0e3f7cfa2f6bdaa42749 /lsp.c
parente2aad67eedd07cff24a51faf31b8c6984a23d777 (diff)
improve request cancellation, fix hover bug
Diffstat (limited to 'lsp.c')
-rw-r--r--lsp.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/lsp.c b/lsp.c
index 1cbe9e6..34f56ae 100644
--- a/lsp.c
+++ b/lsp.c
@@ -492,8 +492,8 @@ LSP *lsp_create(const char *root_dir, const char *command, const char *configura
lsp->log = log;
#if DEBUG
- printf("Starting up LSP %p `%s` in %s\n",
- (void *)lsp, command, root_dir);
+ printf("Starting up LSP %p (ID %u) `%s` in %s\n",
+ (void *)lsp, (unsigned)lsp->id, command, root_dir);
#endif
str_hash_table_create(&lsp->document_ids, sizeof(u32));
@@ -657,8 +657,31 @@ bool lsp_covers_path(LSP *lsp, const char *path) {
void lsp_cancel_request(LSP *lsp, LSPRequestID id) {
if (!id) return;
if (!lsp) return;
-
- LSPRequest request = {.type = LSP_REQUEST_CANCEL};
- request.data.cancel.id = id;
- lsp_send_request(lsp, &request);
+ bool sent = false;
+ SDL_LockMutex(lsp->messages_mutex);
+ for (u32 i = 0; i < arr_len(lsp->requests_sent); ++i) {
+ LSPRequest *req = &lsp->requests_sent[i];
+ if (req->id == id) {
+ // we sent this request but haven't received a response
+ sent = true;
+ arr_remove(lsp->requests_sent, i);
+ break;
+ }
+ }
+
+ for (u32 i = 0; i < arr_len(lsp->messages_client2server); ++i) {
+ LSPMessage *message = &lsp->messages_client2server[i];
+ if (message->type == LSP_REQUEST && message->u.request.id == id) {
+ // we haven't sent this request yet
+ arr_remove(lsp->messages_client2server, i);
+ break;
+ }
+
+ }
+ SDL_UnlockMutex(lsp->messages_mutex);
+ if (sent) {
+ LSPRequest request = {.type = LSP_REQUEST_CANCEL};
+ request.data.cancel.id = id;
+ lsp_send_request(lsp, &request);
+ }
}