From e1b3296d7ecae1bf1620f53714ec3ba5b31709d4 Mon Sep 17 00:00:00 2001 From: pommicket Date: Sat, 24 Dec 2022 12:24:29 -0500 Subject: LSP setting! --- buffer.c | 17 ++++++++++------- main.c | 11 ++--------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/buffer.c b/buffer.c index 831bf89..a8baa26 100644 --- a/buffer.c +++ b/buffer.c @@ -735,13 +735,16 @@ static void buffer_line_free(Line *line) { // Free a buffer. Once a buffer is freed, you can call buffer_create on it again. // Does not free the pointer `buffer` (buffer might not have even been allocated with malloc) void buffer_free(TextBuffer *buffer) { - LSP *lsp = buffer_lsp(buffer); - if (lsp) { - LSPRequest did_close = {.type = LSP_REQUEST_DID_CLOSE}; - did_close.data.close = (LSPRequestDidClose){ - .document = lsp_document_id(lsp, buffer->filename) - }; - lsp_send_request(lsp, &did_close); + if (!buffer->ted->quit) { // don't send didClose on quit (calling buffer_lsp would actually create a LSP if this is called after destroying all the LSPs which isnt good) + + LSP *lsp = buffer_lsp(buffer); + if (lsp) { + LSPRequest did_close = {.type = LSP_REQUEST_DID_CLOSE}; + did_close.data.close = (LSPRequestDidClose){ + .document = lsp_document_id(lsp, buffer->filename) + }; + lsp_send_request(lsp, &did_close); + } } Line *lines = buffer->lines; diff --git a/main.c b/main.c index 9df6824..6cb5161 100644 --- a/main.c +++ b/main.c @@ -1,7 +1,8 @@ /* @TODO: -- why is it creating the LSP on exit +- why arent we always sending didOpen? - make sure "save as" works +- workspaceFolders support (so we don't need to start up multiple instances of rust-analyzer) - more LSP stuff: - go to definition using LSP - find usages @@ -362,14 +363,6 @@ int main(int argc, char **argv) { } ted->last_save_time = -1e50; - - // @TODO TEMPORARY - ted->lsps[0] = lsp_create("/p/autosdf", LANG_RUST, "rust-analyzer"); - if (!ted->lsps[0]) { - printf("couldn't create LSP\n"); - exit(1); - } - // make sure signal handler has access to ted. error_signal_handler_ted = ted; -- cgit v1.2.3