diff options
author | pommicket <pommicket@gmail.com> | 2023-01-09 21:59:51 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2023-01-09 22:00:23 -0500 |
commit | 7f0255cb40bb85276191ec3ddffe507e53abf2ac (patch) | |
tree | 2376d10183d4085a7e8c85bba008f8ba3516d731 | |
parent | ce158f26b9136b3fc831c6325ad911e3bf403a4b (diff) |
fixed a bunch of windows stuff
also compile_commands.json does fix the usages problem!
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | lsp-parse.c | 12 | ||||
-rw-r--r-- | lsp-write.c | 16 | ||||
-rw-r--r-- | lsp.c | 6 | ||||
-rw-r--r-- | main.c | 7 | ||||
-rw-r--r-- | make.bat | 3 | ||||
-rw-r--r-- | os-win.c | 2 | ||||
-rw-r--r-- | session.c | 2 | ||||
-rw-r--r-- | ted.c | 3 | ||||
-rw-r--r-- | ted.cfg | 2 | ||||
-rw-r--r-- | util.c | 9 | ||||
-rw-r--r-- | util.h | 1 |
12 files changed, 39 insertions, 25 deletions
@@ -29,3 +29,4 @@ SDL2 test.txt log.txt UpgradeLog.htm +compile_commands.json diff --git a/lsp-parse.c b/lsp-parse.c index f794c4b..fd07913 100644 --- a/lsp-parse.c +++ b/lsp-parse.c @@ -101,7 +101,17 @@ static bool parse_document_uri(LSP *lsp, const JSON *json, JSONValue value, LSPD free(string); return false; } - *id = lsp_document_id(lsp, string + strlen("file://")); + char *path; + #if _WIN32 + path = string + strlen("file:///"); + // replace slashes with backslashes + for (char *p = path; *p; ++p) + if (*p == '/') + *p = '\\'; + #else + path = string + strlen("file://"); + #endif + *id = lsp_document_id(lsp, path); free(string); return true; } diff --git a/lsp-write.c b/lsp-write.c index 0883929..8472190 100644 --- a/lsp-write.c +++ b/lsp-write.c @@ -181,26 +181,22 @@ static void write_arr_elem_string(JSONWriter *o, const char *s) { write_string(o, s); } -static void write_file_uri_direct(JSONWriter *o, const char *path) { +static void write_file_uri(JSONWriter *o, LSPDocumentID document) { + const char *path = lsp_document_path(o->lsp, document); str_builder_append(&o->builder, "\"file://"); + #if _WIN32 + // why the fuck is there another slash it makes no goddamn sense + str_builder_append(&o->builder, "/"); + #endif write_escaped(o, path); str_builder_append(&o->builder, "\""); } -static void write_file_uri(JSONWriter *o, LSPDocumentID document) { - write_file_uri_direct(o, lsp_document_path(o->lsp, document)); -} - static void write_key_file_uri(JSONWriter *o, const char *key, LSPDocumentID document) { write_key(o, key); write_file_uri(o, document); } -static void write_key_file_uri_direct(JSONWriter *o, const char *key, const char *path) { - write_key(o, key); - write_file_uri_direct(o, path); -} - static void write_position(JSONWriter *o, LSPPosition position) { write_obj_start(o); write_key_number(o, "line", (double)position.line); @@ -481,6 +481,12 @@ u32 lsp_document_id(LSP *lsp, const char *path) { *value = id; LSPDocumentData *data = arr_addp(lsp->document_data); data->path = str_dup(path); + #if _WIN32 + // file URIs use slashes: https://en.wikipedia.org/wiki/File_URI_scheme + for (char *p = data->path; *p; ++p) + if (*p == '\\') + *p = '/'; + #endif } u32 id = *value; SDL_UnlockMutex(lsp->document_mutex); @@ -1,13 +1,10 @@ /* @TODO: +- make sure buffer_load_file/buffer_new_file handle paths with forward slashes on windows - why are all requests failing on windows? - 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 - textDocument/references to work? - - does adding compile_commands.json help? - - maybe it can be done with the clangd config instead. - - does vscode have the same problem? +- add note to README about compile_commands.json - rust-analyzer bug reports: - bad json can give "Unexpected error: client exited without proper shutdown sequence" - containerName not always given in workspace/symbols @@ -16,7 +16,8 @@ if _%1 == _ ( pushd debug cmake -DCMAKE_BUILD_TYPE=Debug -GNinja .. ninja - copy ted.exe .. + ninja -t compdb C_COMPILER__ted_Debug > ..\compile_commands.json + copy /y ted.exe .. popd ) if _%1 == _release cl main.c ted.res /O2 /wd4702 %C_FLAGS% /Fe:ted @@ -123,7 +123,7 @@ int os_rename_overwrite(const char *oldname, const char *newname) { // 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; +// return -1 if (remove(oldname) != 0) return -1; return 0; @@ -338,7 +338,7 @@ void session_write(Ted *ted) { success &= fclose(fp) == 0; if (success) { remove(filename2); - rename(filename1, filename2); // overwrite old session + os_rename_overwrite(filename1, filename2); // overwrite old session } } } @@ -387,6 +387,7 @@ static Status ted_open_buffer(Ted *ted, u16 *buffer_idx, u16 *tab) { if (arr_len(node->tabs) < TED_MAX_TABS) { arr_add(node->tabs, (u16)new_buffer_index); TextBuffer *new_buffer = &ted->buffers[new_buffer_index]; + buffer_create(new_buffer, ted); node->active_tab = (u16)(arr_len(node->tabs) - 1); *buffer_idx = (u16)new_buffer_index; *tab = node->active_tab; @@ -445,7 +446,6 @@ bool ted_open_file(Ted *ted, const char *filename) { } else { ted_error_from_buffer(ted, buffer); node_tab_close(ted, ted->active_node, tab_idx); - ted_delete_buffer(ted, (u16)buffer_idx); return false; } } else { @@ -472,7 +472,6 @@ bool ted_new_file(Ted *ted, const char *filename) { } else { ted_error_from_buffer(ted, buffer); node_tab_close(ted, ted->active_node, tab_idx); - ted_delete_buffer(ted, (u16)buffer_idx); return false; } } else { @@ -41,7 +41,7 @@ lsp-enabled = yes # enable this to log all messages between ted and the LSP server # (may require restarting ted to update) # the log file is in the same folder as ted.cfg. -lsp-log = off +lsp-log = on # display function signature help? (only with LSP running) # this is the thing at the bottom of ted which shows the parameters to the function you're calling signature-help-enabled = yes @@ -126,11 +126,14 @@ bool str_has_prefix(const char *str, const char *prefix) { return strncmp(str, prefix, strlen(prefix)) == 0; } -// e.g. "/usr/share/bla" has the path prefix "/usr/share" but not "/usr/sha" bool str_has_path_prefix(const char *path, const char *prefix) { size_t prefix_len = strlen(prefix); - if (strncmp(path, prefix, prefix_len) != 0) - return false; + for (int i = 0; i < prefix_len; ++i) { + if (strchr(ALL_PATH_SEPARATORS, path[i]) && strchr(ALL_PATH_SEPARATORS, prefix[i])) + continue; // treat all path separators as the same + if (prefix[i] != path[i]) + return false; + } return path[prefix_len] == '\0' || strchr(ALL_PATH_SEPARATORS, path[prefix_len]); } @@ -76,6 +76,7 @@ const char32_t *util_mem32chr_const(const char32_t *s, char32_t c, size_t n); // does `str` have this prefix? bool str_has_prefix(const char *str, const char *prefix); // like str_has_prefix, but for paths. "ab/cd" is a path-prefix of "ab/cd/ef", but not "ab/cde". +// also handles the fact that \ and / are the same on windows bool str_has_path_prefix(const char *path, const char *prefix); // are these two strings equal? bool streq(const char *a, const char *b); |