From 498b670de076909452c0fd6bc4629aca8974d9f7 Mon Sep 17 00:00:00 2001 From: pommicket Date: Sun, 8 Jan 2023 09:39:39 -0500 Subject: fix up stuff for when LSP server exits --- lsp.c | 3 ++- lsp.h | 4 ++-- main.c | 1 - ted.c | 6 ++++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lsp.c b/lsp.c index 12c5be1..a7d7e2f 100644 --- a/lsp.c +++ b/lsp.c @@ -407,7 +407,6 @@ static bool lsp_send(LSP *lsp) { quit = true; } } - lsp->died = true; free(messages); return quit; @@ -428,6 +427,8 @@ static int lsp_communication_thread(void *data) { break; } + lsp->exited = true; + if (!lsp->process) { // process already exited return 0; diff --git a/lsp.h b/lsp.h index 5d5fc1b..68e90e6 100644 --- a/lsp.h +++ b/lsp.h @@ -559,8 +559,8 @@ typedef struct LSP { // (when the initialize response is received) _Atomic bool initialized; // has the LSP server exited? - // thread-safety: only set to false once when the process dies - _Atomic bool died; + // thread-safety: atomic + _Atomic bool exited; // thread-safety: only set once in lsp_create. char *command; // this is set in lsp_create, then later set to NULL when we send over the configuration (after the initialized notification). diff --git a/main.c b/main.c index 71467ba..32553da 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,5 @@ /* @TODO: -- test that signature help requests and hover requests are cancelled - don't let 0 be a valid LSPDocumentID - TESTING: check all IDE features with different servers - run everything through valgrind ideally with leak checking diff --git a/ted.c b/ted.c index e3f5aeb..dd2a759 100644 --- a/ted.c +++ b/ted.c @@ -151,7 +151,7 @@ LSP *ted_get_lsp_by_id(Ted *ted, LSPID id) { for (int i = 0; ted->lsps[i]; ++i) { LSP *lsp = ted->lsps[i]; if (lsp->id == id) - return lsp->died ? NULL : lsp; + return lsp->exited ? NULL : lsp; } return NULL; } @@ -173,8 +173,10 @@ LSP *ted_get_lsp(Ted *ted, const char *path, Language language) { // if the server supports workspaceFolders. return NULL; } - if (lsp->died) + if (lsp_covers_path(lsp, path) && lsp->exited) { + // this server died. give up. return NULL; + } // check if root matches up or if we can add a workspace folder char *root = ted_get_root_dir_of(ted, path); -- cgit v1.2.3