Skip to content

fix: use counter for winbar spinner updates - #586

Open
jakubbortlik wants to merge 8 commits into
harrisoncramer:developfrom
jakubbortlik:push-kxzrxtkxslqq
Open

fix: use counter for winbar spinner updates#586
jakubbortlik wants to merge 8 commits into
harrisoncramer:developfrom
jakubbortlik:push-kxzrxtkxslqq

Conversation

@jakubbortlik

@jakubbortlik jakubbortlik commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

Before this PR the spinner's phase came from a module-level spinner_index incremented once per winbar render, which ties the animation to redraw count rather than to time. That is merely imprecise with a single discussion tree window, but breaks once a second view renders its own copy of the tree: the two winbars share the counter, so each shows only a subset of the spinner characters and they pulse out of phase. Taking the phase from vim.uv.hrtime makes it a pure function of wall-clock time, so any number of winbars stay in step.

Also, by tracking discussion tree updates with a counter, rather than the nil-as-flag on last_updated, the spinner becomes a more reliable indicator of ongoing updates. Before this PR, when two updates happened to overlap, the spinner would stop moving after the first and before the second update finished, thus misleading users into believing all updates finished. With this PR, the spinner spins until the last ongoing update finishes.

The time since the last update is no longer hidden when an update is in progress, which gives users a better idea of the progress if multiple updates are going on.

To be able to reliably decrement the counter, I've refactored the run_job function in the job.lua module heavily. It is now called send_request and the module is called client.lua, to more clearly show the purpose of the module. The on_error callback is now called on all failure paths, not just when the Go server returned an error message. The handling of vim.system output is extracted to a helper function which is more clearly structured and is covered by tests.

Details in ErrorResponse (cmd/app/response_types.go) is renamed to Error to more clearly mark its intent in the lua client. This changes the wire format: a server response using the old key is still accepted, with a warning to rebuild, so users supplying their own binary via server.binary_provided aren't broken.

Notifications that echo the curl command now redact the request body, which can contain comment and MR text. Users may notice REDACTED in :messages.

Previously a transport failure, an empty response body, or unparseable
JSON returned without running any callback, leaving callers unable to
tell that the request had finished. Now exactly one callback runs for
every outcome, including curl failing to spawn.
The handler was a nested anonymous function, which obscured the outcome
branches and could not be exercised directly. Move it to M._make_on_exit
and cover the branches with specs.
The module sends requests to the Go server rather than managing jobs, so name
it for what it does: run_job becomes send_request, and the spec follows.
Redact the request body from the notifications that echo the curl
command, since it can carry comment and MR text.
"error" states what the field holds, which reads better on the Lua side where
it gates the on_error callback. This changes the wire format, so a response
carrying the old key is still accepted, with a warning to rebuild, for users
who supply their own binary via server.binary_provided.
last_updated doubled as the in-flight marker, so the timestamp
disappeared while a refresh ran. Track the two states separately, and
drive the spinner phase from vim.uv.hrtime so it advances with
wall-clock time rather than with the number of winbar renders.
A single Boolean `updating` flag stopped the spinner as soon as the
first of two overlapping refreshes finished, suggesting all work was
done. An integer counter updates for each refresh individually, so the
spinner runs until the last one completes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant