diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2023-01-08 12:05:34 -0500 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2023-01-08 12:05:34 -0500 |
commit | bb6d6850bd7d1e7fb65bae6f4d1bae32534f3455 (patch) | |
tree | 74b40c5ec7877043802ebc8b325df8552f002e8e | |
parent | 34212b559d7bb0eb0d4e7797ba3e9b1a718cedac (diff) |
start windows support
-rw-r--r-- | lsp.c | 23 | ||||
-rw-r--r-- | lsp.h | 10 | ||||
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | make.bat | 9 | ||||
-rw-r--r-- | util.c | 1 |
5 files changed, 37 insertions, 8 deletions
@@ -6,11 +6,17 @@ const char *language_to_str(Language language); +static LSPMutex request_id_mutex; + // it's nice to have request IDs be totally unique, including across LSP servers. static LSPRequestID get_request_id(void) { // it's important that this never returns 0, since that's reserved for "no ID" - static _Atomic LSPRequestID last_request_id; - return ++last_request_id; + static LSPRequestID last_request_id; + assert(request_id_mutex); + SDL_LockMutex(request_id_mutex); + u32 id = ++last_request_id; + SDL_UnlockMutex(request_id_mutex); + return id; } bool lsp_get_error(LSP *lsp, char *error, size_t error_size, bool clear) { @@ -271,7 +277,7 @@ static bool lsp_receive(LSP *lsp, size_t max_size) { // read stderr. if all goes well, we shouldn't get anything over stderr. char stderr_buf[1024] = {0}; for (size_t i = 0; i < (max_size + sizeof stderr_buf) / sizeof stderr_buf; ++i) { - ssize_t nstderr = process_read_stderr(lsp->process, stderr_buf, sizeof stderr_buf - 1); + long long nstderr = process_read_stderr(lsp->process, stderr_buf, sizeof stderr_buf - 1); if (nstderr > 0) { // uh oh stderr_buf[nstderr] = '\0'; @@ -496,7 +502,9 @@ const char *lsp_document_path(LSP *lsp, LSPDocumentID document) { LSP *lsp_create(const char *root_dir, const char *command, const char *configuration, FILE *log) { LSP *lsp = calloc(1, sizeof *lsp); if (!lsp) return NULL; - + if (!request_id_mutex) + request_id_mutex = SDL_CreateMutex(); + static LSPID curr_id = 1; lsp->id = curr_id++; lsp->log = log; @@ -700,3 +708,10 @@ void lsp_cancel_request(LSP *lsp, LSPRequestID id) { lsp_send_request(lsp, &request); } } + +void lsp_quit(void) { + if (request_id_mutex) { + SDL_DestroyMutex(request_id_mutex); + request_id_mutex = NULL; + } +} @@ -557,10 +557,10 @@ typedef struct LSP { // has the response to the initialize request been sent? // thread-safety: this starts out false, and only gets set to true once // (when the initialize response is received) - _Atomic bool initialized; + bool initialized; // has the LSP server exited? - // thread-safety: atomic - _Atomic bool exited; + // thread-safety: this starts out false, and only gets set to true once (when the server exits) + 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). @@ -628,6 +628,10 @@ LSPDocumentPosition lsp_location_start_position(LSPLocation location); // get the end of location's range as a LSPDocumentPosition LSPDocumentPosition lsp_location_end_position(LSPLocation location); void lsp_free(LSP *lsp); +// call this to free any global resources used by lsp*.c +// not strictly necessary, but prevents valgrind errors & stuff. +// make sure you call lsp_free on every LSP you create before calling this. +void lsp_quit(void); #endif // LSP_H_ @@ -1115,6 +1115,8 @@ int main(int argc, char **argv) { lsp_free(ted->lsps[i]); ted->lsps[i] = NULL; } + lsp_quit(); + arr_foreach_ptr(ted->shell_history, char *, cmd) { free(*cmd); } @@ -13,7 +13,14 @@ if not exist pcre2-32-static.lib ( SET C_FLAGS=/nologo /W4 /MD /wd4200 /wd4204 /wd4221 /wd4706 /wd4214 /D_CRT_SECURE_NO_WARNINGS /I SDL2/include /I pcre2 SDL2/lib/x64/SDL2main.lib SDL2/lib/x64/SDL2.lib pcre2-32-static.lib rc /nologo ted.rc if _%1 == _ ( - cl main.c stb_image.c stb_truetype.c ted.res /DDEBUG /DEBUG /Zi %C_FLAGS% /Fe:ted + cl buffer.c build.c colors.c command.c^ + config.c find.c gl.c ide-autocomplete.c^ + ide-definitions.c ide-highlights.c ide-hover.c^ + ide-signature-help.c ide-usages.c lsp.c lsp-json.c^ + lsp-parse.c lsp-write.c main.c menu.c node.c^ + os-win.c session.c stb_image.c stb_truetype.c^ + syntax.c tags.c ted.c text.c ui.c util.c ted.res^ + /DDEBUG /DEBUG /Zi %C_FLAGS% /Fe:ted ) if _%1 == _release cl main.c ted.res /O2 /wd4702 %C_FLAGS% /Fe:ted if _%1 == _release_with_debug_info cl main.c ted.res /DEBUG /Zi /O2 /wd4702 %C_FLAGS% /Fe:ted @@ -5,6 +5,7 @@ #if _WIN32 #include <intrin.h> #include <direct.h> +#include <io.h> #elif __unix__ #include <unistd.h> #else |