summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-08-15 12:07:44 -0300
committerpommicket <pommicket@gmail.com>2023-08-15 12:07:44 -0300
commit87845777777058fa45c93df15e67b65ad41708a7 (patch)
treeadcb554b60193e1b8083d480f3793e87f396bbdc
parent2515bf34a97620ffbfcf5db8451c422ccf132cf8 (diff)
fix definitions selector
-rw-r--r--ide-definitions.c36
-rw-r--r--tags.c3
2 files changed, 21 insertions, 18 deletions
diff --git a/ide-definitions.c b/ide-definitions.c
index 8fe7582..aab145a 100644
--- a/ide-definitions.c
+++ b/ide-definitions.c
@@ -133,6 +133,21 @@ static int definition_entry_qsort_cmp(const void *av, const void *bv) {
return strcmp(a->detail, b->detail);
}
+/// put definitions from `ted->definitions->all_definitions` into `ted->definitions->selector`'s entries.
+static void definitions_selector_update_entries(Ted *ted) {
+ Definitions *defs = ted->definitions;
+ Selector *sel = defs->selector;
+ selector_clear(sel);
+ arr_foreach_ptr(defs->all_definitions, SymbolInfo, info) {
+ SelectorEntry entry = {
+ .color = info->color,
+ .name = info->name,
+ .detail = info->detail,
+ };
+ selector_add_entry(sel, &entry);
+ }
+}
+
void definitions_process_lsp_response(Ted *ted, LSP *lsp, const LSPResponse *response) {
Definitions *defs = ted->definitions;
if (response->request.id != defs->last_request.id) {
@@ -182,7 +197,6 @@ void definitions_process_lsp_response(Ted *ted, LSP *lsp, const LSPResponse *res
// 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);
definitions_clear_entries(defs);
arr_set_len(defs->all_definitions, arr_len(symbols));
@@ -192,7 +206,7 @@ void definitions_process_lsp_response(Ted *ted, LSP *lsp, const LSPResponse *res
def->name = str_dup(lsp_response_string(response, symbol->name));
SymbolKind kind = symbol_kind_to_ted(symbol->kind);
- def->color = settings_color(settings, color_for_symbol_kind(kind));
+ def->color = color_for_symbol_kind(kind);
def->from_lsp = true;
def->position = lsp_location_start_position(symbol->location);
const char *container_name = lsp_response_string(response, symbol->container);
@@ -205,6 +219,8 @@ void definitions_process_lsp_response(Ted *ted, LSP *lsp, const LSPResponse *res
def->position.pos.line + 1);
}
+ definitions_selector_update_entries(ted);
+
} break;
default:
debug_println("?? bad request type in %s : %u:%u", __func__, response->request.id, response->request.type);
@@ -244,6 +260,7 @@ static void definitions_selector_open(Ted *ted) {
definitions_send_request_if_needed(ted);
} else {
defs->all_definitions = tags_get_symbols(ted);
+ definitions_selector_update_entries(ted);
}
ted_switch_to_buffer(ted, ted->line_buffer);
buffer_select_all(ted->active_buffer);
@@ -270,20 +287,7 @@ static void definitions_selector_update(Ted *ted) {
char *chosen = selector_update(ted, sel);
if (chosen) {
- // for LSP go-to-definition, we ignore `chosen` and use the cursor instead.
- // this is because a single symbol can have multiple definitions,
- // e.g. with overloading.
- SelectorEntry cursor_entry = {0};
- if (!selector_get_cursor_entry(sel, &cursor_entry)) {
- assert(0); // shouldn't happen since `chosen` is true.
- return;
- }
-
- u64 def_idx = cursor_entry.userdata;
- if (def_idx >= arr_len(defs->all_definitions)) {
- assert(0);
- return;
- }
+ u64 def_idx = selector_get_cursor(sel);
SymbolInfo *info = &defs->all_definitions[def_idx];
if (info->from_lsp) {
// NOTE: we need to get this before calling menu_close,
diff --git a/tags.c b/tags.c
index 2851b17..436a615 100644
--- a/tags.c
+++ b/tags.c
@@ -382,7 +382,6 @@ SymbolInfo *tags_get_symbols(Ted *ted) {
if (!file) return NULL;
SymbolInfo *infos = NULL;
- u32 color = ted_active_color(ted, COLOR_TEXT);
if (file) {
char line[1024];
while (fgets(line, sizeof line, file)) {
@@ -390,7 +389,7 @@ SymbolInfo *tags_get_symbols(Ted *ted) {
size_t len = strcspn(line, "\t");
SymbolInfo *info = arr_addp(infos);
info->name = strn_dup(line, len);
- info->color = color;
+ info->color = COLOR_TEXT;
}
}
fclose(file);