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

bug: Error executing vim.schedule lua callback: .../.local/share/nvim/lazy/lazydev.nvim/lua/lazydev/buf.lua:151: bad argument #1 to 'ipairs' (table expected, got nil) #10

Closed
3 tasks done
yavorski opened this issue Jun 2, 2024 · 11 comments · Fixed by #8
Labels
bug Something isn't working

Comments

@yavorski
Copy link

yavorski commented Jun 2, 2024

Did you check docs and existing issues?

  • I have read all the lazydev.nvim docs
  • I have searched the existing issues of lazydev.nvim
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

0.10

Operating system/version

Arch Linux 6.9.3-arch1-1

Describe the bug

The plugin throws error when starting with nvim ~/.config/nvim/init.lua, but it works correctly when I am editing the init.lua in my repository directory. I think it throws when there isn't a lua directory e.g. ~/.config/nvim/lua/, e.g. when you have only single init.lua file there. Here is the error.

Error executing vim.schedule lua callback: .../.local/share/nvim/lazy/lazydev.nvim/lua/lazydev/buf.lua:151: bad argument #1 to 'ipairs' (table expected, got nil)
stack traceback:
	[C]: in function 'ipairs'
	.../.local/share/nvim/lazy/lazydev.nvim/lua/lazydev/buf.lua:151: in function ''
	vim/_editor.lua: in function <vim/_editor.lua:0>

Steps To Reproduce

  1. delete lua dir if any rm -r ~/.config/nvim/lua/
  2. start nvim with nvim ~/.config/nvim/init.lua

Expected Behavior

To not throw error and to work correctly.

Repro

-- DO NOT change the paths and don't remove the colorscheme
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath, })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  "folke/lazydev.nvim",
  -- add any other plugins here
  {
    "folke/lazydev.nvim",
    dependencies = {{ "bilal2453/luvit-meta" }},
    ft = "lua",
    opts = {
      library = { "luvit-meta/library" }
    }
  }
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
-- nothing else
@yavorski yavorski added the bug Something isn't working label Jun 2, 2024
@folke folke closed this as completed in 41e5bb1 Jun 2, 2024
@folke
Copy link
Owner

folke commented Jun 2, 2024

Should be fixed, but would be great if you can confirm!

@yavorski
Copy link
Author

yavorski commented Jun 2, 2024

It does not throw, but it is not working either... Also it is printing directories now. It works when I create the ~/.config/nvim/lua/ dir manually. See screenshots.

screenshot-02-06-2024-23-56-25

screenshot-02-06-2024-23-55-11

folke added a commit that referenced this issue Jun 2, 2024
@folke folke reopened this Jun 2, 2024
@folke
Copy link
Owner

folke commented Jun 2, 2024

Just removed that debug.
Now I understand what you mean with init.lua. Will check

@folke
Copy link
Owner

folke commented Jun 2, 2024

What does :=vim.lsp.buf.list_workspace_folders() show?

@folke
Copy link
Owner

folke commented Jun 2, 2024

I think this is the problem: https://github.com/neovim/nvim-lspconfig/blob/master/lua/lspconfig/server_configurations/lua_ls.lua#L22

Your LuaLS is in single file mode, no workspace.

When you create the lua folder, you're in a workspace.

@folke
Copy link
Owner

folke commented Jun 2, 2024

Although, even in that case it still works for me....

@yavorski
Copy link
Author

yavorski commented Jun 2, 2024

What does :=vim.lsp.buf.list_workspace_folders() show?

Empty table {}
I have added workaround to my config now to create the dir if it does not exists, so it's not a big deal.

Lazy.use {
  "folke/lazydev.nvim",
  -- dir = "~/dev/open-sos/lazydev.nvim",
  dependencies = {{ "bilal2453/luvit-meta" }},
  ft = "lua",
  opts = {
    library = { "luvit-meta/library" }
  },
  init = function()
    local luadir = vim.fn.expand("~/.config/nvim/lua/")
    if not vim.loop.fs_stat(luadir) then
      vim.fn.mkdir(luadir)
    end
  end
}

This is my lua_ls setup if it does matter

require("lspconfig").lua_ls.setup({
  capabilities = LSP.capabilities(),
  settings = {
    Lua = {
      format = { enable = true },
      runtime = { version = "LuaJIT" },
      diagnostics = { globals = { "vim" } },
      completion = { callSnippet = "Replace" },
      workspace = { checkThirdParty = "Disable" }
    }
  }
})

@folke
Copy link
Owner

folke commented Jun 2, 2024

And this? :=vim.lsp.get_clients({name = "lua_ls"})[1].root_dir

@yavorski
Copy link
Author

yavorski commented Jun 2, 2024

nil,

screenshot-03-06-2024-01-08-18

@folke folke closed this as completed in 0592c8f Jun 2, 2024
@folke
Copy link
Owner

folke commented Jun 2, 2024

Should work now with single file support

@yavorski
Copy link
Author

yavorski commented Jun 3, 2024

It is working now. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants