From f029ca734af1b4e16b7320ae2f85b3cb41b06324 Mon Sep 17 00:00:00 2001 From: pommicket Date: Tue, 30 Sep 2025 11:51:45 -0400 Subject: Fix code actions being screwed up when there are lots of options --- ide-code-action.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'ide-code-action.c') diff --git a/ide-code-action.c b/ide-code-action.c index edcae7c..f357e6d 100644 --- a/ide-code-action.c +++ b/ide-code-action.c @@ -105,7 +105,7 @@ bool code_action_process_lsp_response(Ted *ted, const LSPResponse *response) { // then, prefer 'quickfix' to other kinds of actions. // then, prefer whichever action comes first. int best_score = -1; - Action *best_action = NULL; + ptrdiff_t best_action = -1; arr_foreach_ptr(response->data.code_action.actions, const LSPCodeAction, action) { Action *action_out = arr_addp(c->actions); action_out->lsp = action; @@ -116,14 +116,14 @@ bool code_action_process_lsp_response(Ted *ted, const LSPResponse *response) { if (action->kind == LSP_CODE_ACTION_QUICKFIX) score += 1; if (score > best_score) { - best_action = action_out; + best_action = action_out - c->actions; best_score = score; } } - if (best_action != c->actions) { + if (best_action != -1) { // move "best" action to top - Action best = *best_action; - memmove(c->actions + 1, c->actions, (size_t)(best_action - c->actions) * sizeof *c->actions); + Action best = c->actions[best_action]; + memmove(c->actions + 1, c->actions, (size_t)best_action * sizeof *c->actions); *c->actions = best; } return true; -- cgit v1.2.3