Skip to content

Code to update spinner on notify spams notifications #109

@nick4tech

Description

@nick4tech

Describe the bug
When using the following code to handle updates to percentage value updates on an existing notification while also enabling noice, causes a spam of notify notifications

Which version of Neovim are you using?
0.8.0 in kitty terminal

To Reproduce
Steps to reproduce the behavior:

  1. Use the following code to configure notify
vim.lsp.handlers["$/progress"] = function(_, result, ctx)
   local client_id = ctx.client_id

   local val = result.value

   if not val.kind then
     return
   end

   local notif_data = get_notif_data(client_id, result.token)

   if val.kind == "begin" then
     local message = format_message(val.message, val.percentage)

     notif_data.notification = vim.notify(message, "info", {
       title = format_title(val.title, vim.lsp.get_client_by_id(client_id).name),
       icon = spinner_frames[1],
       timeout = false,
       hide_from_history = false,
     })

     notif_data.spinner = 1
     update_spinner(client_id, result.token)
   elseif val.kind == "report" and notif_data then
     notif_data.notification = vim.notify(format_message(val.message, val.percentage), "info", {
       replace = notif_data.notification,
       hide_from_history = true,
     })
   elseif val.kind == "end" and notif_data then
     notif_data.notification =
       vim.notify(val.message and format_message(val.message) or "Complete", "info", {
         icon = "",
         replace = notif_data.notification,
         timeout = 3000,
       })

     notif_data.spinner = nil
   end
  end

If the following code is commented (updates the value of the notification) the issue disappears:

   elseif val.kind == "report" and notif_data then
     notif_data.notification = vim.notify(format_message(val.message, val.percentage), "info", {
       replace = notif_data.notification,
       hide_from_history = true,
     })
  1. Enable noice

Expected Behavior
Receive a single notification that updates as the percentage increases

Screenshots
Espected behavior:
image

Actual behavior:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions