Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index out of bounds #235

Open
BrunoKrugel opened this issue Jul 17, 2024 · 7 comments
Open

Index out of bounds #235

BrunoKrugel opened this issue Jul 17, 2024 · 7 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@BrunoKrugel
Copy link

Neovim version (nvim -v | head -n1)

NVIM v0.10.0

Operating system/version

macOS M1

How to reproduce the issue

cat mini.lua

-- Use Vim packages install the plugin, also work with some plugins manager such as packer.nvim
vim.o.packpath = '~/.local/share/nvim/site'
vim.cmd('packadd promise-async')
vim.cmd('packadd nvim-ufo')

-- Setting
vim.o.foldcolumn = 'auto'
vim.o.foldlevel = 99
vim.o.foldlevelstart = -1
vim.o.foldenable = true

local ufo = require('ufo')
ufo.setup({
  close_fold_kinds_for_ft = {
    default = { "imports" },
  },
  open_fold_hl_timeout = 0,
  preview = {
    win_config = {
      border = "rounded",
      winblend = 0,
    },
  },
  provider_selector = function(_, filetype, buftype)
    -- use nested markdown folding
    if filetype == "markdown" then
      return ""
    end

    -- return ftMap[filetype] or { "treesitter", "indent" }
    -- return { "treesitter", "indent" }
    local function handleFallbackException(bufnr, err, providerName)
      if type(err) == "string" and err:match "UfoFallbackException" then
        return require("ufo").getFolds(bufnr, providerName)
      else
        return require("promise").reject(err)
      end
    end

    -- only use indent until a file is opened
    return (filetype == "" or buftype == "nofile") and "indent"
      or function(bufnr)
        return require("ufo")
          .getFolds(bufnr, "lsp")
          :catch(function(err)
            return handleFallbackException(bufnr, err, "treesitter")
          end)
          :catch(function(err)
            return handleFallbackException(bufnr, err, "indent")
          end)
      end
  end,
})
vim.keymap.set('n', 'zR', ufo.openAllFolds)
vim.keymap.set('n', 'zM', ufo.closeAllFolds)

nvim --clean +'so mini.lua'

  1. Open a go file

image

Expected behavior

The code above should open a Go file with the imports folded.

When UFO works:
image

Actual behavior

The code works most of the time, but sometimes when I open a file the folded code has a 0 instead of the default text and I get a lot of index out of bounds error.

Folded code:

0
}

Error

Error in decoration provider ufo.end:
Error executing lua: ....local/share/nvim/lazy/nvim-ufo/lua/ufo/model/buffer.lua:227: index out of bounds
stack traceback:
	[C]: in function 'error'
	...el/.local/share/nvim/lazy/nvim-ufo/lua/ufo/decorator.lua:143: in function <...el/.local/share/nvim/lazy/nvim-ufo/lua/ufo/decorator.lua:140

image

@BrunoKrugel BrunoKrugel added the bug Something isn't working label Jul 17, 2024
@kevinhwang91
Copy link
Owner

Have you searched your title from the repo issue?

@BrunoKrugel
Copy link
Author

Have you searched your title from the repo issue?

Sorry if missed some information, but yes.

output from UFO_LOG=debug:

[24-07-18 11:13:14] [INFO] manager.lua:202 : apply fold rowPairs: {}
[24-07-18 11:13:38] [DEBUG] init.lua:125 : attach bufnr: 634
[24-07-18 11:13:39] [DEBUG] init.lua:125 : attach bufnr: 634
[24-07-18 11:13:39] [INFO] init.lua:86 : providers: { <function 1> }
[24-07-18 11:13:39] [DEBUG] init.lua:53 : requestFoldingRange({ <function 1> }, 634) has elapsed: 0ms
[24-07-18 11:13:39] [INFO] init.lua:93 : selected provider: external
[24-07-18 11:15:05] [DEBUG] init.lua:125 : attach bufnr: 1
[24-07-18 11:15:06] [INFO] init.lua:86 : providers: { <function 1> }
[24-07-18 11:15:07] [DEBUG] init.lua:37 : using nvim as a lsp provider
[24-07-18 11:15:08] [DEBUG] init.lua:53 : requestFoldingRange({ <function 1> }, 1) has elapsed: 2020ms
[24-07-18 11:15:08] [INFO] init.lua:93 : selected provider: external
[24-07-18 11:15:08] [INFO] manager.lua:201 : apply fold ranges: { {
    endLine = 14,
    startLine = 5
  }, {
    endLine = 13,
    startLine = 6
  }, {
    endLine = 12,
    startLine = 7
  }, {
    endLine = 31,
    startLine = 17
  }, {
    endLine = 29,
    startLine = 19
  }, {
    endLine = 28,
    startLine = 21
  }, {
    endLine = 27,
    startLine = 22
  }, {
    endLine = 26,
    startLine = 23
  }, {
    endLine = 35,
    startLine = 34
  } }
[24-07-18 11:15:08] [INFO] manager.lua:202 : apply fold rowPairs: {}
[24-07-18 11:15:14] [DEBUG] init.lua:125 : attach bufnr: 2
[24-07-18 11:15:15] [INFO] init.lua:86 : providers: { "indent" }
[24-07-18 11:15:15] [DEBUG] init.lua:53 : requestFoldingRange({ "indent" }, 2) has elapsed: 3ms
[24-07-18 11:15:15] [INFO] init.lua:93 : selected provider: indent

@kevinhwang91
Copy link
Owner

Have you searched your title from the repo issue?

Sorry if missed some information, but yes.

output from UFO_LOG=debug:

[24-07-18 11:13:14] [INFO] manager.lua:202 : apply fold rowPairs: {}
[24-07-18 11:13:38] [DEBUG] init.lua:125 : attach bufnr: 634
[24-07-18 11:13:39] [DEBUG] init.lua:125 : attach bufnr: 634
[24-07-18 11:13:39] [INFO] init.lua:86 : providers: { <function 1> }
[24-07-18 11:13:39] [DEBUG] init.lua:53 : requestFoldingRange({ <function 1> }, 634) has elapsed: 0ms
[24-07-18 11:13:39] [INFO] init.lua:93 : selected provider: external
[24-07-18 11:15:05] [DEBUG] init.lua:125 : attach bufnr: 1
[24-07-18 11:15:06] [INFO] init.lua:86 : providers: { <function 1> }
[24-07-18 11:15:07] [DEBUG] init.lua:37 : using nvim as a lsp provider
[24-07-18 11:15:08] [DEBUG] init.lua:53 : requestFoldingRange({ <function 1> }, 1) has elapsed: 2020ms
[24-07-18 11:15:08] [INFO] init.lua:93 : selected provider: external
[24-07-18 11:15:08] [INFO] manager.lua:201 : apply fold ranges: { {
    endLine = 14,
    startLine = 5
  }, {
    endLine = 13,
    startLine = 6
  }, {
    endLine = 12,
    startLine = 7
  }, {
    endLine = 31,
    startLine = 17
  }, {
    endLine = 29,
    startLine = 19
  }, {
    endLine = 28,
    startLine = 21
  }, {
    endLine = 27,
    startLine = 22
  }, {
    endLine = 26,
    startLine = 23
  }, {
    endLine = 35,
    startLine = 34
  } }
[24-07-18 11:15:08] [INFO] manager.lua:202 : apply fold rowPairs: {}
[24-07-18 11:15:14] [DEBUG] init.lua:125 : attach bufnr: 2
[24-07-18 11:15:15] [INFO] init.lua:86 : providers: { "indent" }
[24-07-18 11:15:15] [DEBUG] init.lua:53 : requestFoldingRange({ "indent" }, 2) has elapsed: 3ms
[24-07-18 11:15:15] [INFO] init.lua:93 : selected provider: indent

Which buffer is index out of bounds from your log? If you load ufo without lazy event, is there an issue?

@BrunoKrugel
Copy link
Author

It seems that the issue doesn't happen if I use lazy=false, however, this issue started to happen in the last month because I have been using BufRead for almost a year without issues.

@kevinhwang91
Copy link
Owner

Which buffer is index out of bounds from your log? What's the content? Actually, I have no idea to fix.

@BrunoKrugel
Copy link
Author

In this example my buffer is the bufnr 2.

Untitled.mov

Log:

[24-07-18 12:15:09] [DEBUG] init.lua:125 : attach bufnr: 2
[24-07-18 12:15:09] [INFO] init.lua:86 : providers: { <function 1> }
[24-07-18 12:15:11] [DEBUG] init.lua:37 : using nvim as a lsp provider
[24-07-18 12:15:11] [DEBUG] init.lua:53 : requestFoldingRange({ <function 1> }, 2) has elapsed: 1995ms
[24-07-18 12:15:11] [INFO] init.lua:93 : selected provider: external
[24-07-18 12:15:11] [INFO] manager.lua:201 : apply fold ranges: { {
    endLine = 14,
    startLine = 5
  }, {
    endLine = 13,
    startLine = 6
  }, {
    endLine = 12,
    startLine = 7
  }, {
    endLine = 31,
    startLine = 17
  }, {
    endLine = 29,
    startLine = 19
  }, {
    endLine = 28,
    startLine = 21
  }, {
    endLine = 27,
    startLine = 22
  }, {
    endLine = 26,
    startLine = 23
  }, {
    endLine = 35,
    startLine = 34
  } }
[24-07-18 12:15:11] [INFO] manager.lua:202 : apply fold rowPairs: {}
[24-07-18 12:15:13] [DEBUG] init.lua:125 : attach bufnr: 3
[24-07-18 12:15:13] [INFO] init.lua:86 : providers: { "indent" }
[24-07-18 12:15:13] [DEBUG] init.lua:53 : requestFoldingRange({ "indent" }, 3) has elapsed: 0ms
[24-07-18 12:15:13] [INFO] init.lua:93 : selected provider: indent
[24-07-18 12:15:25] [DEBUG] init.lua:125 : attach bufnr: 245
[24-07-18 12:15:25] [INFO] init.lua:86 : providers: { "indent" }
[24-07-18 12:15:25] [DEBUG] init.lua:53 : requestFoldingRange({ "indent" }, 245) has elapsed: 0ms
[24-07-18 12:15:25] [INFO] init.lua:93 : selected provider: indent

@kevinhwang91
Copy link
Owner

Leave this issue here, no ability to solve it.

@kevinhwang91 kevinhwang91 added the help wanted Extra attention is needed label Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants