kevinhwang91 / nvim-ufo

Not UFO in the sky, but an ultra fold in Neovim.
BSD 3-Clause "New" or "Revised" License
2.3k stars 47 forks source link

Initial fold gets delayed #119

Closed meijieru closed 1 year ago

meijieru commented 1 year ago

Neovim version (nvim -v | head -n1)

NVIM v0.9.0-dev-1206+g829d92eca3

Operating system/version

archlinux

How to reproduce the issue

I have the following setup for ufo

M["kevinhwang91/nvim-ufo"] = {
  event = "User FileOpened",
  dependencies = "kevinhwang91/promise-async",
  config = function()
    local ft_map = {
      ["neotest-summary"] = "",
    }
    require("ufo").setup {
      fold_virt_text_handler = handler,
      provider_selector = function(_, filetype, _)
        if vim.tbl_contains(ft_map, filetype) then
          return ft_map[filetype]
        else
          return { "lsp", "indent" }
        end
      end,
    }
  end,
  init = function()
    -- Neovim hasn't added foldingRange to default capabilities, users must add it manually
    local _make_client_capabilities = vim.lsp.protocol.make_client_capabilities
    vim.lsp.protocol.make_client_capabilities = function()
      local capabilities = _make_client_capabilities()
      if capabilities.textDocument.foldingRange ~= nil then
        vim.notify("foldingRange added", "warn", { title = "Ufo Init" })
      end
      capabilities.textDocument.foldingRange = {
        dynamicRegistration = false,
        lineFoldingOnly = true,
      }
      return capabilities
    end
  end,
}

Expected behavior

The initial fold takes >10s. I tried even {"indent"} fallback, which doesn't help.

Actual behavior

Initial fold shouldn't be so slow.

kevinhwang91 commented 1 year ago
  1. Use stable nvim like v0.8.3;
  2. Execute tail -f ~/.cache/nvim/ufo.log in a shell;
  3. Run UFO_LOG=trace nvim and reproduce the issue;
  4. Post the log here.
meijieru commented 1 year ago

Sorry for late reply.

The log is attached below

[23-05-27 06:12:53] [TRACE] event.lua:52 : event: BufAttach listeners: { <function 1> } args: 1
[23-05-27 06:12:53] [DEBUG] init.lua:128 : attach bufnr: 1
[23-05-27 06:12:53] [TRACE] event.lua:52 : event: TextChanged listeners: { <function 1> } args: 1
[23-05-27 06:12:55] [TRACE] event.lua:52 : event: BufDetach listeners: { <function 1>, <function 2>, <function 3> } args: 1
[23-05-27 06:12:55] [TRACE] event.lua:52 : event: BufEnter listeners: { <function 1>, <function 2> } args: 3
[23-05-27 06:12:55] [TRACE] event.lua:52 : event: BufAttach listeners: { <function 1> } args: 3
[23-05-27 06:12:55] [DEBUG] init.lua:128 : attach bufnr: 3
[23-05-27 06:13:18] [TRACE] event.lua:52 : event: InsertLeave listeners: { <function 1> } args: 3

The UfoInspect shows it's still starting after 10s

Buffer: 3
Fold Status: start
Main provider: lsp
Fallback provider: indent
Selected provider: nil
Fold kinds: 
kevinhwang91 commented 1 year ago

This is normal log, I guess the issue is plugins conflict, please use binary search and debug yourself.

[23-05-28 22:02:03] [TRACE] event.lua:52 : event: BufAttach listeners: { <function 1> } args: 3
[23-05-28 22:02:03] [DEBUG] init.lua:128 : attach bufnr: 3
[23-05-28 22:02:03] [DEBUG] decorator.lua:77 : folded lnums: {} didOpen: false
[23-05-28 22:02:03] [INFO] init.lua:89 : providers: { "lsp", "indent" }
[23-05-28 22:02:03] [DEBUG] decorator.lua:77 : folded lnums: {} didOpen: false
[23-05-28 22:02:03] [DEBUG] init.lua:53 : requestFoldingRange({ "lsp", "indent" }, 3) has elapsed: 191ms
[23-05-28 22:02:03] [INFO] init.lua:96 : selected provider: lsp
[23-05-28 22:02:03] [INFO] manager.lua:204 : apply fold ranges: { {
    endLine = 151,
    kind = "region",
    startLine = 146
  }, {
    endLine = 143,
    kind = "region",
    startLine = 141
  }, {
    endLine = 138,
    kind = "region",
    startLine = 134
  }, {
    endLine = 131,
    kind = "region",
    startLine = 129
  }, {
    endLine = 126,
    kind = "region",
    startLine = 124
  }, {
    endLine = 121,
    kind = "region",
    startLine = 118
  }, {
    endLine = 112,
    kind = "region",
    startLine = 111
  }, {
    endLine = 107,
    kind = "region",
    startLine = 106
  }, {
    endLine = 108,
    kind = "region",
    startLine = 105
  }, {
    endLine = 101,
    kind = "region",
    startLine = 100
  }, {
    endLine = 93,
    kind = "region",
    startLine = 92
  }, {
    endLine = 115,
    kind = "region",
    startLine = 89
  }, {
    endLine = 82,
    kind = "region",
    startLine = 81
  }, {
    endLine = 86,
    kind = "region",
    startLine = 80
  }, {
    endLine = 64,
    kind = "region",
    startLine = 63
  }, {
    endLine = 77,
    kind = "region",
    startLine = 62
  }, {
    endLine = 58,
    kind = "region",
    startLine = 51
  }, {
    endLine = 59,
    kind = "region",
    startLine = 50
  }, {
    endLine = 45,
    kind = "region",
    startLine = 43
  }, {
    endLine = 46,
    kind = "region",
    startLine = 42
  }, {
    endLine = 38,
    kind = "region",
    startLine = 37
  }, {
    endLine = 35,
    kind = "region",
    startLine = 33
  }, {
    endLine = 28,
    kind = "region",
    startLine = 20
  }, {
    endLine = 47,
    kind = "region",
    startLine = 18
  } }
[23-05-28 22:02:03] [INFO] manager.lua:205 : apply fold rowPairs: {}
[23-05-28 22:02:03] [DEBUG] decorator.lua:77 : folded lnums: {} didOpen: false
meijieru commented 1 year ago

Thanks for the guidance, would check that.