summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2022-12-30 14:57:26 -0500
committerpommicket <pommicket@gmail.com>2022-12-30 14:57:26 -0500
commit547bfbba7a1ef84d397711882a501fc4914addba (patch)
treefd702946ac77db0c828e871f4ad90ae6fe99198b
parentf2c8a3a77fdd7f397e04edcaf5dae5e7777f03b6 (diff)
show location in definitions menu
-rw-r--r--ide-autocomplete.c2
-rw-r--r--ide-definitions.c7
-rw-r--r--main.c3
-rw-r--r--ted.h5
-rw-r--r--ui.c22
-rw-r--r--util.c20
6 files changed, 51 insertions, 8 deletions
diff --git a/ide-autocomplete.c b/ide-autocomplete.c
index f1c3c13..a30a33f 100644
--- a/ide-autocomplete.c
+++ b/ide-autocomplete.c
@@ -502,6 +502,7 @@ static void autocomplete_frame(Ted *ted) {
const char *detail = completion->detail;
if (detail) {
+ // draw detail
double label_end_x = state.x;
char show_text[128] = {0};
@@ -524,7 +525,6 @@ static void autocomplete_frame(Ted *ted) {
if (!detail[amount_detail]) break;
}
if (amount_detail >= 3) {
- //rgba_u32_to_floats(colors[COLOR_COMMENT], state.color);
text_utf8_anchored(font, show_text, state.max_x, state.y,
colors[COLOR_COMMENT], ANCHOR_TOP_RIGHT);
}
diff --git a/ide-definitions.c b/ide-definitions.c
index fa4d999..d76925b 100644
--- a/ide-definitions.c
+++ b/ide-definitions.c
@@ -76,6 +76,7 @@ void definitions_frame(Ted *ted) {
static void definitions_clear_entries(Definitions *defs) {
arr_foreach_ptr(defs->selector_all_definitions, SymbolInfo, def) {
free(def->name);
+ free(def->detail);
}
arr_clear(defs->selector_all_definitions);
arr_clear(defs->selector.entries);
@@ -107,6 +108,7 @@ static void definitions_selector_filter_entries(Ted *ted) {
SelectorEntry *entry = arr_addp(sel->entries);
entry->name = info->name;
entry->color = info->color;
+ entry->detail = info->detail;
}
}
free(search_term);
@@ -128,6 +130,7 @@ void definitions_process_lsp_response(Ted *ted, LSP *lsp, const LSPResponse *res
switch (response->request.type) {
case LSP_REQUEST_DEFINITION: {
+ // handle textDocument/definition response
const LSPResponseDefinition *response_def = &response->data.definition;
if (!arr_len(response_def->locations)) {
@@ -145,6 +148,7 @@ void definitions_process_lsp_response(Ted *ted, LSP *lsp, const LSPResponse *res
ted_go_to_lsp_document_position(ted, lsp, position);
} break;
case LSP_REQUEST_WORKSPACE_SYMBOLS: {
+ // handle workspace/symbol response
const LSPResponseWorkspaceSymbols *response_syms = &response->data.workspace_symbols;
const LSPSymbolInformation *symbols = response_syms->symbols;
const Settings *settings = ted_active_settings(ted);
@@ -161,6 +165,9 @@ void definitions_process_lsp_response(Ted *ted, LSP *lsp, const LSPResponse *res
def->color = colors[color_for_symbol_kind(kind)];
def->from_lsp = true;
def->position = lsp_location_start_position(symbol->location);
+ def->detail = a_sprintf("%s:%" PRIu32,
+ path_filename(lsp_document_path(lsp, def->position.document)),
+ def->position.pos.line + 1);
}
definitions_selector_filter_entries(ted);
diff --git a/main.c b/main.c
index 18379f5..c2b9638 100644
--- a/main.c
+++ b/main.c
@@ -1,6 +1,5 @@
/*
@TODO:
-- show location in definitions menu
- handle multiple symbols with same name
- cancelling requests e.g. in ide-definitions.c
- more LSP stuff:
@@ -20,7 +19,7 @@
- TESTING: make rust-analyzer-slow (waits 10s before sending response)
- run everything through valgrind ideally with leak checking
- grep -i -n TODO *.[ch]
-- when searching files/definitions, sort by length? or put exact matches at the top?
+- when searching files, put exact matches at the top
--- LSP MERGE ---
- improve structure of ted source code to make LSP completions better
(make every c file a valid translation unit)
diff --git a/ted.h b/ted.h
index 22a8362..8132e1e 100644
--- a/ted.h
+++ b/ted.h
@@ -272,7 +272,9 @@ ENUM_U16 {
} ENUM_U16_END(Menu);
typedef struct {
- char const *name;
+ const char *name;
+ // if not NULL, this will show on the right side of the entry.
+ const char *detail;
u32 color;
} SelectorEntry;
@@ -415,6 +417,7 @@ typedef struct {
typedef struct {
char *name;
+ char *detail;
u32 color;
bool from_lsp;
LSPDocumentPosition position; // only set if from_lsp = true
diff --git a/ui.c b/ui.c
index 94648f8..ebaa0ef 100644
--- a/ui.c
+++ b/ui.c
@@ -111,9 +111,10 @@ static char *selector_update(Ted *ted, Selector *s) {
// NOTE: also renders the line buffer
static void selector_render(Ted *ted, Selector *s) {
- Settings const *settings = ted_active_settings(ted);
- u32 const *colors = settings->colors;
+ const Settings *settings = ted_active_settings(ted);
+ const u32 *colors = settings->colors;
Font *font = ted->font;
+ float padding = settings->padding;
Rect bounds = s->bounds;
@@ -149,10 +150,23 @@ static void selector_render(Ted *ted, Selector *s) {
for (u32 i = 0; i < s->n_entries; ++i) {
Rect r;
if (selector_entry_pos(ted, s, i, &r)) {
+ SelectorEntry *entry = &entries[i];
float x = r.pos.x, y = r.pos.y;
text_state.x = x; text_state.y = y;
- rgba_u32_to_floats(entries[i].color, text_state.color);
- text_utf8_with_state(font, &text_state, entries[i].name);
+
+ // draw name
+ rgba_u32_to_floats(entry->color, text_state.color);
+ text_utf8_with_state(font, &text_state, entry->name);
+
+ if (entry->detail) {
+ // draw detail
+ float detail_size = text_get_size_v2(font, entry->detail).x;
+ TextRenderState detail_state = text_state;
+ detail_state.x = maxd(text_state.x + 2 * padding, x2 - detail_size);
+
+ rgba_u32_to_floats(colors[COLOR_COMMENT], detail_state.color);
+ text_utf8_with_state(font, &detail_state, entry->detail);
+ }
}
}
text_render(font);
diff --git a/util.c b/util.c
index 3962069..856558a 100644
--- a/util.c
+++ b/util.c
@@ -222,6 +222,26 @@ static void str_cpy(char *dst, size_t dst_sz, char const *src) {
#define strbuf_cpy(dst, src) str_cpy(dst, sizeof dst, src)
#define strbuf_cat(dst, src) str_cat(dst, sizeof dst, src)
+
+char *a_sprintf(PRINTF_FORMAT_STRING const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2);
+char *a_sprintf(const char *fmt, ...) {
+ // idk if you can always just pass NULL to vsnprintf
+ va_list args;
+ char fakebuf[2] = {0};
+ va_start(args, fmt);
+ int ret = vsnprintf(fakebuf, 1, fmt, args);
+ va_end(args);
+
+ if (ret < 0) return NULL; // bad format or something
+ u32 n = (u32)ret;
+ char *str = calloc(1, n + 1);
+ va_start(args, fmt);
+ vsnprintf(str, n + 1, fmt, args);
+ va_end(args);
+ return str;
+}
+
+
// advances str to the start of the next UTF8 character
static void utf8_next_char_const(char const **str) {
if (**str) {