summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-01-09 21:59:51 -0500
committerpommicket <pommicket@gmail.com>2023-01-09 22:00:23 -0500
commit7f0255cb40bb85276191ec3ddffe507e53abf2ac (patch)
tree2376d10183d4085a7e8c85bba008f8ba3516d731
parentce158f26b9136b3fc831c6325ad911e3bf403a4b (diff)
fixed a bunch of windows stuff
also compile_commands.json does fix the usages problem!
-rw-r--r--.gitignore1
-rw-r--r--lsp-parse.c12
-rw-r--r--lsp-write.c16
-rw-r--r--lsp.c6
-rw-r--r--main.c7
-rw-r--r--make.bat3
-rw-r--r--os-win.c2
-rw-r--r--session.c2
-rw-r--r--ted.c3
-rw-r--r--ted.cfg2
-rw-r--r--util.c9
-rw-r--r--util.h1
12 files changed, 39 insertions, 25 deletions
diff --git a/.gitignore b/.gitignore
index bda84df..9046bce 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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);
diff --git a/lsp.c b/lsp.c
index b9b0398..c5aaef8 100644
--- a/lsp.c
+++ b/lsp.c
@@ -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);
diff --git a/main.c b/main.c
index 8e95cdc..21a53d6 100644
--- a/main.c
+++ b/main.c
@@ -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
diff --git a/make.bat b/make.bat
index 924d68e..c43974c 100644
--- a/make.bat
+++ b/make.bat
@@ -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
diff --git a/os-win.c b/os-win.c
index 8dd8ce8..043d54f 100644
--- a/os-win.c
+++ b/os-win.c
@@ -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;
diff --git a/session.c b/session.c
index a4c7744..8860cd1 100644
--- a/session.c
+++ b/session.c
@@ -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
}
}
}
diff --git a/ted.c b/ted.c
index dd2a759..d5335d4 100644
--- a/ted.c
+++ b/ted.c
@@ -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 {
diff --git a/ted.cfg b/ted.cfg
index c316ff3..4d0f3f3 100644
--- a/ted.cfg
+++ b/ted.cfg
@@ -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
diff --git a/util.c b/util.c
index d1daa7d..ef96d29 100644
--- a/util.c
+++ b/util.c
@@ -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]);
}
diff --git a/util.h b/util.h
index c41a17f..4b043ba 100644
--- a/util.h
+++ b/util.h
@@ -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);