folke / noice.nvim

💥 Highly experimental plugin that completely replaces the UI for messages, cmdline and the popupmenu.
Apache License 2.0
3.94k stars 88 forks source link

bug: lag when quitting nvim #864

Open serhez opened 2 weeks ago

serhez commented 2 weeks ago

Did you check docs and existing issues?

Neovim version (nvim -v)

0.10

Operating system/version

MacOS 14.4.1

Describe the bug

When quitting, nvim lags for about 1-1.5s. This happens only when I enable noice. I've been using noice for a long time and this has been happening only for a few weeks (I update my plugins regularly), hence I would expect it's due to a recent change. Perhaps it has something to do with commit 31ec80c?

Steps To Reproduce

  1. Install noice and use my config (given below in the repro section).
  2. Quit neovim.

Expected Behavior

I would expect quitting neovim to take about the same time as when not using noice.

Repro

require("noice").setup({
  health = {
    checker = false, -- Disable if you don't want health checks to run
  },

  cmdline = {
    view = "cmdline",
    format = {
      cmdline = { icon = " " .. icons.arrow.right_short_thick },
      search_down = { icon = " " .. icons.lupa .. " " .. icons.arrow.double_down_short },
      search_up = { icon = " " .. icons.lupa .. " " .. icons.arrow.double_up_short },
      filter = { icon = " " .. icons.filter },
      lua = { icon = " " .. icons.language.lua },
      help = { icon = " " .. icons.question },
    },
  },

  override = {
    -- override the default lsp markdown formatter with Noice
    ["vim.lsp.util.convert_input_to_markdown_lines"] = true,
    -- override the lsp markdown formatter with Noice
    ["vim.lsp.util.stylize_markdown"] = true,
    -- override cmp documentation with Noice (needs the other options to work)
    ["cmp.entry.get_documentation"] = true,
  },

  views = {
    hover = {
      border = {
        style = "none",
        padding = { 1, 2 },
      },
      position = { row = 0, col = 0 },
    },
    mini = {
      timeout = 4000, -- Duration between show() and hide(), in milliseconds
      win_options = {
        winblend = 0,
      },
      winhighlight = {},
    },
  },

  notify = {
    enabled = true,
    view = "mini",
  },

  messages = {
    enabled = true, -- enables the Noice messages UI
    view = false, -- default view for messages
    view_error = "mini", -- view for errors
    view_warn = "mini", -- view for warnings
    view_history = "messages", -- view for :messages
    view_search = "virtualtext", -- view for search count messages. Set to `false` to disable
  },

  lsp = {
    override = {
      -- override the default lsp markdown formatter with Noice
      ["vim.lsp.util.convert_input_to_markdown_lines"] = true,
      -- override the lsp markdown formatter with Noice
      ["vim.lsp.util.stylize_markdown"] = true,
      -- override cmp documentation with Noice (needs the other options to work)
      ["cmp.entry.get_documentation"] = true,
    },
    message = {
      enabled = true,
      view = "mini",
    },
    hover = {
      enabled = true,
      silent = true,
    },
  },

  routes = {
    {
      view = "confirm",
      filter = {
        any = {
          { event = "msg_show", kind = "confirm" },
          { event = "msg_show", kind = { "echo", "echomsg", "" }, before = true },
          { event = "msg_show", kind = { "echo", "echomsg" }, instant = true },
        },
      },
    },
    {
      view = "cmdline",
        filter = {
        any = {
          { event = "msg_show", kind = "confirm_sub" },
        },
      },
    },

    -- Send long messages to a split window
    {
      view = "split",
      filter = { event = "msg_show", min_height = 5 },
    },
  },
})
folke commented 2 weeks ago

Can't reproduce. Does :Noice log show something useful?

Do you still see the issue with Noice's default options?

serhez commented 2 weeks ago

@folke Unfortunately no, the last log is almost a month old. Which issue about the default options are you referring to?

If you cannot reproduce it with my config, I wonder what other plugin or general nvim option could be interfering with this. If I just set enabled = false in my lazy config for noice, the issue goes away.

serhez commented 2 weeks ago

I just did a small test: when I'm on commit 69c6ad5c1f1c0777125d0275f9871d8609cb0521, neovim quitting is instantaneous , when I upgrade to commit 31ec80c99ee699ea4e90248c2e87e5a669be5e93 (the next commit), I see the lag when quitting. I think this VimLeavePre logic (disabling the plugin I assume) is taking ~1sec and slowing down the quitting process. If it helps, I'm running it on a 2021 M1 Pro MacbookPro.

EDIT: A small thing to consider if you want to try what I mention above is that, sometimes, it takes a few tries of "Update"/"Sync" in the lazy panel to upgrade/downgrade to some commit; sometimes I see the plugin as being updated but then I look into the plugin's information (hitting enter on its name in the lazy panel) and the commit listed there is the previous one I had specified in my config. This is not just a visual bug. After two/three updates/syncs, this is fixed and the plugin is updated to the newly specified commit.

b0ae989c commented 2 weeks ago

Do you have any other plugin that creates autocmd for VimLeavePre?

folke commented 2 weeks ago

If you don't see anything in the logs, then I have no idea what might be happening here. Most likely some other plugin that interacts with Noice. Typically when you see a delay in closing Neovim, it means a plugin is triggering an error. Unfortunately it's not always easy to figure out what plugin and even what error.

serhez commented 2 weeks ago

@b0ae989c is there any way to find out which functions have been registered for a given autocmd like VimLeavePre? I'm not well versed into the inner workings of most of the plugins I use, so I can't tell if they would be using this autocmd. Perhaps some session-related features?

@folke As I mentioned previously, this only happens after 31ec80c. I see that you introduce a pcall in those changes:

if Config.is_running() then
    pcall(M.disable)
end

I'm not a lua guy, but if the pcall to M.disable fails we would not get an error/log right? But still, could this be slowing the quitting process?

telbizov commented 2 weeks ago

For what it's worth. I also started experiencing this recently. Every other time I quit neovim it takes about 1-2 seconds to exit. I see a stale screen of partial content while I am waiting for the exit to take place. I usually see the line numbers and some window borders. However, disabling noice does not resolve the issue fully for me. It does make it better, i.e. it happens less frequently. Maybe once every 5 exits. I'm trying to figure out what is going on and I am at a loss.