Skip to content

feat: changed loading to actual animation#178

Open
NikoPit wants to merge 1 commit into
saecki:mainfrom
NikoPit:main
Open

feat: changed loading to actual animation#178
NikoPit wants to merge 1 commit into
saecki:mainfrom
NikoPit:main

Conversation

@NikoPit

@NikoPit NikoPit commented Jul 1, 2026

Copy link
Copy Markdown
image made this spinner actually spin

@saecki saecki left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also thought about implementing this myself, but there was always something else that felt more important. So thanks opening this PR :D

In the spirit of the plugin, I'd like to make things more configurable instead of hardcoding them. While we're at it, the very similar search indicator should also be animated the same way.

Comment thread lua/crates/ui.lua

local timer = assert(vim.loop.new_timer())
buf_state.loading_timer = timer
timer:start(120, 120, vim.schedule_wrap(function()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make the update rate configurable?
I think a new section called loading with the following fields would be nice.

  • show_indicator: boolean
  • frames: {string}
  • rate: integer // 0 should be handled specially and not start the timer at all

The text.searching and text.loading strings should be changed to include a %s format specifier where the loading spinner will be inserted.

The loading_indicator options should be deprecated like this in config/init.lua

deprecated = {
    new_field = { "loading", "show_indicator" },
},

Comment thread lua/crates/ui.lua
UPDATE = 3,
}

local LOADING_FRAMES = {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These can become the default frames in the config.

Comment thread lua/crates/ui.lua
---@type integer
local CUSTOM_NS = vim.api.nvim_create_namespace("crates.nvim")
---@type integer
local LOADING_NS = vim.api.nvim_create_namespace("crates.nvim.loading")

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the mentioned changes I'd rename this to SPINNER_NS

Comment thread lua/crates/ui.lua

---@enum LineState
local LineState = {
SEARCHING = 1,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The search indicator should also be handled the same. And be configurable with a separate search section that accepts the same fields as loading.

Comment thread lua/crates/ui.lua
end

---@param buf_state BufUiState
local function stop_loading_timer(buf_state)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would become stop_spin_timer

Comment thread lua/crates/ui.lua

---@param buf integer
---@param buf_state BufUiState
local function render_loading(buf, buf_state)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would become render_spinners

Comment thread lua/crates/ui.lua
---@field line_state table<integer,LineState>
---@field loading_timer uv.uv_timer_t?
---@field loading_frame integer
---@field loading_lines table<integer,boolean>

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can get rid of the separate table of loading lines, and instead just use the line_state and check if it's LOADING OR SEARCHING.

Comment thread lua/crates/ui.lua
@@ -25,13 +28,28 @@
UPDATE = 3,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed the UPDATE state is and was never used, so could you also remove it?

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.

2 participants