summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-30 15:51:35 -0500
committerpommicket <pommicket@gmail.com>2022-12-30 15:51:35 -0500
commitad841a324e905559ab7640956b0fbe2d2fdb3b77 (patch)
tree105be53e3181a7391e167c26894a7436bea27a23
parent056ccc31cc2cfc1037a47a0b6ae35d0033602cbf (diff)
fixed hover bug
-rw-r--r--ide-hover.c20
-rw-r--r--lsp-json.c2
-rw-r--r--main.c1
-rw-r--r--ted.c18
4 files changed, 28 insertions, 13 deletions
diff --git a/ide-hover.c b/ide-hover.c
index 9742e58..5136d79 100644
--- a/ide-hover.c
+++ b/ide-hover.c
@@ -8,20 +8,16 @@ void hover_close(Ted *ted) {
}
static bool get_hover_position(Ted *ted, LSPDocumentPosition *pos, TextBuffer **pbuffer, LSP **lsp) {
- // find the buffer where the mouse is
- for (int i = 0; i < TED_MAX_BUFFERS; ++i) {
- TextBuffer *buffer = &ted->buffers[i];
- if (!buffer->filename) continue;
+ BufferPos mouse_pos = {0};
+ TextBuffer *buffer = NULL;
+ if (ted_get_mouse_buffer_pos(ted, &buffer, &mouse_pos)) {
LSP *l = buffer_lsp(buffer);
- if (!l) continue;
- BufferPos mouse_pos = {0};
- if (buffer_pixels_to_pos(buffer, ted->mouse_pos, &mouse_pos)) {
- if (pos) *pos = buffer_pos_to_lsp_document_position(buffer, mouse_pos);
- if (pbuffer) *pbuffer = buffer;
- if (lsp) *lsp = l;
- return true;
- }
+ if (pos) *pos = buffer_pos_to_lsp_document_position(buffer, mouse_pos);
+ if (pbuffer) *pbuffer = buffer;
+ if (lsp) *lsp = l;
+ return true;
}
+
return false;
}
diff --git a/lsp-json.c b/lsp-json.c
index 5bf50c6..2f6f0f1 100644
--- a/lsp-json.c
+++ b/lsp-json.c
@@ -2,6 +2,8 @@
// provides FAST(ish) parsing but SLOW lookup
// this is especially fast for small objects
// this actually supports "extended json", where objects can have arbitrary values as keys.
+
+// a string
typedef struct {
u32 pos;
u32 len;
diff --git a/main.c b/main.c
index 6f26bde..211b47a 100644
--- a/main.c
+++ b/main.c
@@ -1,6 +1,5 @@
/*
@TODO:
-- if you hover, open a new file, then hover, you get results for the old file
- handle multiple symbols with same name
- more LSP stuff:
- find usages
diff --git a/ted.c b/ted.c
index 7e14d0a..831242d 100644
--- a/ted.c
+++ b/ted.c
@@ -516,6 +516,24 @@ void ted_press_key(Ted *ted, SDL_Scancode scancode, SDL_Keymod modifier) {
}
}
+bool ted_get_mouse_buffer_pos(Ted *ted, TextBuffer **pbuffer, BufferPos *ppos) {
+ for (u32 i = 0; i < TED_MAX_NODES; ++i) {
+ if (ted->nodes_used[i]) {
+ Node *node = &ted->nodes[i];
+ if (node->tabs) {
+ TextBuffer *buffer = &ted->buffers[node->tabs[node->active_tab]];
+ BufferPos pos = {0};
+ if (buffer_pixels_to_pos(buffer, ted->mouse_pos, &pos)) {
+ if (ppos) *ppos = pos;
+ if (pbuffer) *pbuffer = buffer;
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
+
// make the cursor red for a bit to indicate an error (e.g. no autocompletions)
void ted_flash_error_cursor(Ted *ted) {
ted->cursor_error_time = time_get_seconds();