summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-01-06 22:04:38 -0500
committerpommicket <pommicket@gmail.com>2023-01-06 22:04:38 -0500
commita654b666c20aa4bb42116689f90f83d55484786f (patch)
tree02b3f0b5019d8fadb8ca9c743cc6085698576e9c
parent42ae808f712efb7edac1bdc647a456cfcccb2d39 (diff)
fix some autocomplete issues
also untested higher-than-1-second-resolution windows time_last_modified
-rw-r--r--ide-autocomplete.c28
-rw-r--r--main.c6
-rw-r--r--os-win.c25
3 files changed, 47 insertions, 12 deletions
diff --git a/ide-autocomplete.c b/ide-autocomplete.c
index 4443c2b..bee99bf 100644
--- a/ide-autocomplete.c
+++ b/ide-autocomplete.c
@@ -394,11 +394,28 @@ void autocomplete_open(Ted *ted, uint32_t trigger) {
static void autocomplete_find_phantom(Ted *ted) {
Autocomplete *ac = &ted->autocomplete;
- if (ac->open) return;
- if (!ted->active_buffer) return;
+ if (ac->open) {
+ autocomplete_clear_phantom(ac);
+ return;
+ }
+ if (!ted->active_buffer) {
+ autocomplete_clear_phantom(ac);
+ return;
+ }
TextBuffer *buffer = ted->active_buffer;
- if (!buffer->path) return;
- if (buffer->view_only) return;
+ if (!buffer->path) {
+ autocomplete_clear_phantom(ac);
+ return;
+ }
+ if (buffer->view_only) {
+ autocomplete_clear_phantom(ac);
+ return;
+ }
+ char32_t after_cursor = buffer_char_after_cursor(buffer);
+ if (is32_word(after_cursor)) {
+ autocomplete_clear_phantom(ac);
+ return;
+ }
autocomplete_find_completions(ted, TRIGGER_INVOKED, true);
}
@@ -450,6 +467,9 @@ void autocomplete_frame(Ted *ted) {
colors[COLOR_TEXT] & 0xffffff7f);
text_render(font);
gl_geometry_draw();
+ } else {
+ // this phantom is no longer relevant
+ autocomplete_clear_phantom(ac);
}
} else {
// this phantom is no longer relevant
diff --git a/main.c b/main.c
index beb0acd..ba9c5e2 100644
--- a/main.c
+++ b/main.c
@@ -1,6 +1,5 @@
/*
@TODO:
-- do we need higher than 1-second resolution in time_last_modified on windows?
- when searching files, put exact matches at the top
- TESTING: make rust-analyzer-slow (waits 10s before sending response)
- TESTING: check all IDE features with different servers
@@ -22,15 +21,14 @@ FUTURE FEATURES:
- manual.md
- better handling of backspace with space indentation
- CSS highlighting
+- option for separate colors for read/write highlights
- styles ([color] sections)
- make go-to-definition/hover/highlight modifier key configurable
-- option for separate colors for read/write highlights
- return to previous location in buffer
- font setting & support for multiple fonts to cover more characters
- comment-start & comment-end settings
- robust find (results shouldn't move around when you type things)
-- multiple files with command line arguments
-- :set-build-command
+- open multiple files with command line arguments
- document links using LSP textDocument/documentLink request
- rename using LSP (textDocument/rename)
- we have request writing & response parsing support for it, but that hasn't been tested yet
diff --git a/os-win.c b/os-win.c
index d7f29ca..c565a5b 100644
--- a/os-win.c
+++ b/os-win.c
@@ -109,12 +109,29 @@ int os_get_cwd(char *buf, size_t buflen) {
return 1;
}
+#error "@TODO: test this"
struct timespec time_last_modified(const char *filename) {
- // windows' _stat does not have st_mtim
- struct _stat statbuf = {0};
struct timespec ts = {0};
- _stat(filename, &statbuf);
- ts.tv_sec = statbuf.st_mtime;
+ FILETIME write_time = {0};
+ WCHAR wide_path[4100];
+ if (MultiByteToWideChar(CP_UTF8, 0, path, -1, wide_path, sizeof wide_path) == 0)
+ return ts;
+ HANDLE file = CreateFileW(wide_path, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE, NULL,
+ OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL);
+ if (file == INVALID_HANDLE)
+ return ts;
+
+ if (GetFileTime(file, NULL, NULL, &write_time)) {
+ u64 qword = (u64)write_time.dwLowDateTime
+ | (u64)write_time.dwHighDateTime << 32;
+ // annoyingly, windows gives time since jan 1, 1601 not 1970
+ // https://www.wolframalpha.com/input?i=number+of+days+between+jan+1%2C+1601+and+jan+1%2C+1970
+ qword -= (u64)10000000 * 134774 * 60 * 60 * 24;
+ ts.tv_sec = qword / 10000000;
+ ts.tv_nsec = (qword % 10000000) * 100;
+ }
+
+ CloseHandle(file);
return ts;
}