From dd474cc38d4bd6af067b735f9b9e0788cbfc41ca Mon Sep 17 00:00:00 2001 From: Syed Daanish Date: Thu, 5 Feb 2026 13:03:41 +0000 Subject: [PATCH] Fix deadlock --- TODO.md | 13 ++++++++----- include/lsp/lsp.h | 25 +++++++++++-------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/TODO.md b/TODO.md index 7501cf9..237b61b 100644 --- a/TODO.md +++ b/TODO.md @@ -9,11 +9,11 @@ Copyright 2025 Syed Daanish 128M -> 412.0M (expected worst case 2.3G) ``` -* Next few super long boring things to do -* redo lsp threads such that no mutex needed for any rope stuff (necessary rn) - - Also make the classes own the methods in lsp - - This will mean that parsers/renderers and keystrokes will not need to be individually locked - - And so it will be much faster +## Next few super long boring things to do:: +* redo lsp threads such that no mutex needed for any rope stuff (done) + - Also make the classes own the methods in lsp (done) + - This will mean that parsers/renderers and keystrokes will not need to be individually locked (done) + - And so it will be much faster (done) - At which point the main thread can also be blocked on user input or lsp responses and still be fast * Add a superclass for editor called Window (which can be popup or tiled) (done) * Add a recursive tiling class for windows (done) @@ -23,6 +23,9 @@ Copyright 2025 Syed Daanish - Seperate system functions into a class that branches to support local / ssh / server modes. - Even lsp shouldnt be directly controlled because it can branch on local and server modes - check wolfSSH stuff for remote editing + - Thick and thin mode + - thin mode only shares screen diffing over the network - uses server settings / themes + - thick only shared fileio and lsp data with local used for all else - uses local settings / themes - Redo hooks as a engine of its own. - And factorize renderer into its own class (and make it just return an array of the render without knowing teh x,y) - which is just managed by the renderer diff --git a/include/lsp/lsp.h b/include/lsp/lsp.h index 56db3e2..15239dd 100644 --- a/include/lsp/lsp.h +++ b/include/lsp/lsp.h @@ -95,7 +95,6 @@ struct LSPInstance { return; } json response = *read_lsp_message(); - log("Lsp response: %s", response.dump().c_str()); if (response.contains("result") && response["result"].contains("capabilities")) { auto &caps = response["result"]["capabilities"]; @@ -191,11 +190,11 @@ struct LSPInstance { json shutdown = {{"id", ++last_id}, {"method", "shutdown"}}; send_raw(shutdown); pollfd pfd{stdout_fd, POLLIN, 0}; - poll(&pfd, 1, LSP_TIMEOUT); + poll(&pfd, 1, 500); json exit_msg = {{"method", "exit"}}; send_raw(exit_msg); int waited = 0; - while (waited < LSP_TIMEOUT) { + while (waited < 100) { int status; pid_t res = waitpid(pid, &status, WNOHANG); if (res == pid) @@ -252,22 +251,20 @@ struct LSPInstance { return true; } void add(Editor *ed) { - std::unique_lock lock(lsp::lsp_mutex); editors.push_back(ed); - lock.unlock(); ed->lsp.store(this); char *buf = read(ed->root, 0, ed->root->char_count); std::string text(buf); free(buf); - auto message = std::make_unique(); - message->message = {{"method", "textDocument/didOpen"}, - {"params", - {{"textDocument", - {{"uri", ed->uri}, - {"languageId", ed->lang.name}, - {"version", 1}, - {"text", text}}}}}}; - send(std::move(message)); + json message = {{"jsonrpc", "2.0"}, + {"method", "textDocument/didOpen"}, + {"params", + {{"textDocument", + {{"uri", ed->uri}, + {"languageId", ed->lang.name}, + {"version", 1}, + {"text", text}}}}}}; + send_raw(message); } void remove(Editor *ed) { std::unique_lock lock(lsp::lsp_mutex);