From 2d9c5407fdc923a2e8c1fe39213b09c769a74e2e Mon Sep 17 00:00:00 2001 From: pommicket Date: Mon, 9 Jan 2023 13:51:46 -0500 Subject: fix some windows problems --- CMakeLists.txt | 3 ++- lsp.c | 8 +++++++- main.c | 7 +------ make.bat | 13 +++++-------- os-win.c | 15 +++++++++------ 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a12c9b3..d1a59e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,8 @@ target_compile_definitions(ted PUBLIC DEBUG=1) if(MSVC) target_sources(ted PRIVATE ted.res) target_include_directories(ted PUBLIC ${CMAKE_SOURCE_DIR}/SDL2/include ${CMAKE_SOURCE_DIR}/pcre2) - target_compile_options(ted PRIVATE /MD /W4 /wd4200 /wd4204 /wd4221 /wd4706 /wd4214 /D_CRT_SECURE_NO_WARNINGS) + set(CMAKE_C_FLAGS "/MD /W4 /wd4200 /wd4204 /wd4221 /wd4706 /wd4214 /D_CRT_SECURE_NO_WARNINGS") + set(CMAKE_C_FLAGS_DEBUG "/Zi /Ob0 /Od /RTC1") set(SDL2_LIB_DIR ${CMAKE_SOURCE_DIR}/SDL2/lib/x64) target_link_libraries(ted ${SDL2_LIB_DIR}/SDL2.lib) target_link_libraries(ted ${CMAKE_SOURCE_DIR}/pcre2-32-static.lib) diff --git a/lsp.c b/lsp.c index af61254..b9b0398 100644 --- a/lsp.c +++ b/lsp.c @@ -538,7 +538,13 @@ LSP *lsp_create(const char *root_dir, const char *command, const char *configura lsp->process = process_run_ex(command, &settings); const char *error = process_geterr(lsp->process); if (error) { - lsp_set_error(lsp, "Couldn't start LSP server: %s", error); + // don't show an error box if the server is not installed + #if _WIN32 + if (strstr(error, " 2)")) { + if (lsp->log) fprintf(lsp->log, "Couldn't start LSP server %s: file not found.", command); + } else + #endif + lsp_set_error(lsp, "Couldn't start LSP server: %s", error); lsp->exited = true; process_kill(&lsp->process); } else { diff --git a/main.c b/main.c index 9d85a49..7ee9bfc 100644 --- a/main.c +++ b/main.c @@ -1,12 +1,7 @@ /* @TODO: -- set commit authors correctly -- finish fixing buffer backup (windows) -- fix calls to WideCharToMultiByte and reverse -- get rid of ninja warnings -- test LSP on windows -- what status does cmd return if the program is not found? (lsp.c:301) - switch to CreateProcessW +- why are all requests failing? - are we freeing process if process_run(_ex) fails? - test time_last_modified (windows) - some way of opening + closing all C files in directory for clangd diff --git a/make.bat b/make.bat index b53da09..924d68e 100644 --- a/make.bat +++ b/make.bat @@ -13,14 +13,11 @@ 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 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 + pushd debug + cmake -DCMAKE_BUILD_TYPE=Debug -GNinja .. + ninja + copy ted.exe .. + popd ) 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 diff --git a/os-win.c b/os-win.c index 6d05601..e641c8c 100644 --- a/os-win.c +++ b/os-win.c @@ -119,13 +119,14 @@ int os_rename_overwrite(const char *oldname, const char *newname) { return -1; if (CopyFileW(wide_oldname, wide_newname, false) == 0) return -1; + // ideally we would do this instead but clangd seems to have a problem with this: + // it's keeping an open handle to main.c in ted. presumably blocks deletion but not writing. + // ReplaceFileW has the same problem. +// if (CreateHardLinkW(wide_oldname, wide_newname, NULL) == 0) +// return -1; if (remove(oldname) != 0) return -1; - - // ideally we would just do this but clangd seems to have a problem with this: - // it's keeping an open handle to main.c in ted. presumably blocks deletion but not writing. -// return ReplaceFileW(wide_newname, wide_oldname, NULL, REPLACEFILE_IGNORE_MERGE_ERRORS|REPLACEFILE_IGNORE_ACL_ERRORS, NULL, NULL) -// ? 0 : -1; + return 0; } struct timespec time_last_modified(const char *path) { @@ -177,11 +178,13 @@ struct Process { }; static void get_last_error_str(char *out, size_t out_sz) { + DWORD errnum = GetLastError(); size_t size = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), out, (DWORD)out_sz - 1, NULL); + NULL, errnum, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), out, (DWORD)out_sz - 1, NULL); out[size] = 0; char *cr = strchr(out, '\r'); if (cr) *cr = '\0'; // get rid of carriage return+newline at end of error + str_printf(out + strlen(out), out_sz - strlen(out), " (error code %u)", (unsigned)errnum); } Process *process_run_ex(const char *command, const ProcessSettings *settings) { -- cgit v1.2.3