folke / lazy.nvim

💤 A modern plugin manager for Neovim
https://lazy.folke.io/
Apache License 2.0
14.32k stars 344 forks source link

bug: E484 cannot find file when nested inside spec folder, even though i have the file and the plugin is loaded #1722

Closed hrqmonteiro closed 1 month ago

hrqmonteiro commented 1 month ago

Did you check docs and existing issues?

Neovim version (nvim -v)

NVIM v0.10.1

Operating system/version

openSUSE tumbleweed

Describe the bug

I am getting the message

E484: Can't open file /home/hrq/.config/nvim/lua/modules/tools/neogit/neogit.octo

Even though i have that file, and the plugin is loaded

~/.config/nvim/lua on  main [✘!?] via  v5.3.6   tree
.
├── config
│   ├── globals.lua
│   ├── icons.lua
│   ├── keys.lua
│   ├── lazy.lua
│   ├── options.lua
│   ├── servers.lua
│   └── tools.lua
├── modules
│   ├── completion
│   │   ├── cmp
│   │   │   ├── config.lua
│   │   │   └── init.lua
│   │   └── telescope
│   │       └── init.lua
│   ├── editor
│   │   ├── parinfer
│   │   │   └── init.lua
│   │   └── tangerine
│   │       └── init.lua
│   ├── lsp
│   │   ├── lspconfig
│   │   │   └── init.lua
│   │   ├── mason
│   │   │   └── init.lua
│   │   └── nvim-lightbulb
│   │       └── init.lua
│   ├── term
│   │   └── toggleterm
│   │       └── init.lua
│   ├── tools
│   │   ├── colorizer
│   │   │   └── init.lua
│   │   ├── conjure
│   │   │   └── init.lua
│   │   ├── neogit
│   │   │   ├── init.lua
│   │   │   └── octo.lua
│   │   ├── neorg
│   │   │   └── init.lua
│   │   ├── tmux-navigator
│   │   │   └── init.lua
│   │   └── treesitter
│   │       └── init.lua
│   └── ui
│       ├── alpha
│       │   └── init.lua
│       ├── auto-dark-mode
│       │   └── init.lua
│       ├── colorscheme
│       │   └── init.lua
│       ├── gitsigns
│       │   └── init.lua
│       ├── hydra
│       │   └── init.lua
│       ├── indent-lines
│       │   └── init.lua
│       ├── lualine
│       │   └── init.lua
│       ├── neo-tree
│       │   └── init.lua
│       ├── noice
│       │   └── init.lua
│       ├── todo-comments
│       │   └── init.lua
│       ├── web-devicons
│       │   └── init.lua
│       └── which-key
│           └── init.lua
├── packages.lua
└── tangerine_vimrc.lua

35 directories, 37 files

image

Steps To Reproduce

I am loading lazy, and defining it to recognize any folder inside modules folder and put it to spec

config/lazy.lua

local lazypath = (vim.fn.stdpath("data") .. "/lazy/lazy.nvim")
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({"git", "clone", "--filter=blob:none", "--single-branch", "https://github.com/folke/lazy.nvim.git", lazypath})
else
end
do end (vim.opt.runtimepath):prepend(lazypath)
local lazy = require("lazy")
local modules = require("packages")
local function should_include_file(filename)
  return not filename:match("config%.fnl$")
end
local function process_directory(base_path, category, module, current_spec)
  local function process_file(file_path, relative_path)
    local file_name = vim.fn.fnamemodify(file_path, ":t")
    local module_name = relative_path:gsub("%.fnl$", ""):gsub("%.lua$", "")
    if vim.loop.fs_stat(file_path) then
      if vim.loop.fs_stat((file_path .. "/init.lua")) then
        return table.insert(current_spec, {import = ("modules." .. category .. "." .. module .. "." .. module_name)})
      elseif (file_name:match("%.fnl$") and should_include_file(file_name)) then
        return table.insert(current_spec, {import = ("modules." .. category .. "." .. module .. "." .. module_name)})
      else
        return nil
      end
    else
      return nil
    end
  end
  local function explore_directory(path, current_spec0)
    local items = vim.fn.readdir(path)
    for _, item in ipairs(items) do
      local item_path = (path .. "/" .. item)
      local relative_path = item:gsub("%.fnl$", ""):gsub("%.lua$", "")
      if vim.loop.fs_stat(item_path) then
        if (vim.fn.isdirectory(item_path) == 1) then
          explore_directory(item_path, current_spec0)
        else
          process_file(item_path, relative_path)
        end
      else
      end
    end
    return nil
  end
  return explore_directory(base_path, current_spec)
end
local function create_spec_from_map(map)
  local spec = {}
  for category, module_list in pairs(map) do
    for _, module in ipairs(module_list) do
      local module_path = (vim.fn.stdpath("config") .. "/fnl/modules/" .. category .. "/" .. module)
      process_directory(module_path, category, module, spec)
    end
  end
  return spec
end
return lazy.setup({spec = create_spec_from_map(modules)})

And on packages.lua i define which ones i want

return {completion = {"cmp", "telescope"}, editor = {"parinfer", "tangerine"}, lsp = {"lspconfig", "mason", "nvim-lightbulb"}, term = {"toggleterm"}, tools = {"conjure", "colorizer", "neogit", "neogit.octo", "neorg", "tmux-navigator", "treesitter"}, ui = {"alpha", "auto-dark-mode", "colorscheme", "gitsigns", "hydra", "indent-lines", "lualine", "neo-tree", "noice", "todo-comments", "web-devicons", "which-key"}}

So this way it is loading

lua/modules/tools/neogit/init.lua and lua/modules/tools/neogit/octo.lua

But it is still accusing me of not having neogit.octo

And also, what i wanted was for it to load

lua/modules/tools/neogit/octo/init.lua

But if i do like this, it complains the same error AND not load the plugin on lazy

for reference, this is neogit/init.lua

return {{"NeogitOrg/neogit", config = true, dependencies = {"nvim-lua/plenary.nvim", "sindrets/diffview.nvim", "nvim-telescope/telescope.nvim"}}}

and neogit/octo.lua

local function _1_()
  local octo = require("octo")
  return octo.setup({})
end
return {{"pwntester/octo.nvim", config = _1_}}

Expected Behavior

To not return the error, since the file exists

And, most importantly, to allow me to have a modules/tools/neogit/octo/init.lua file instead

Which is what i want

Repro

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()

require("lazy.minit").repro({
  spec = {
    -- add any other plugins here
  },
})
max397574 commented 1 month ago

I'm sorry but I can't easily understand your setup (lua syntax highlighting would help a lot already) but this error looks correct to me it seems like an issue in the custom function stuff you do there to get the specs because this file /home/hrq/.config/nvim/lua/modules/tools/neogit.octo definitely doesn't exist it should be /home/hrq/.config/nvim/lua/modules/tools/neogit/octo (notice the / instead of the .)

hrqmonteiro commented 1 month ago

I'm sorry but I can't easily understand your setup (lua syntax highlighting would help a lot already) but this error looks correct to me it seems like an issue in the custom function stuff you do there to get the specs because this file /home/hrq/.config/nvim/lua/modules/tools/neogit.octo definitely doesn't exist it should be /home/hrq/.config/nvim/lua/modules/tools/neogit/octo (notice the / instead of the .)

That was a typo, sorry

It is complaining about modules/tools/neogit.octo

image

As soon as i open Nvim. But, as i said, octo is loaded fine.

But if i move to modules/tools/neogit/octo/init.lua, then it keeps complaining AND doesn't load octo

max397574 commented 1 month ago

doesn't look like a typo to me in the error messages it also is neogit.octo instead of neogit/octo

also not sure if I read your code correctly but you should use only . for paths to modules which is perhaps what causes the issue

either way this really likely just is an issue with your custom script and not lazy.nvim therefor you should perhaps move this to a discussion where people can help you with your custom stuff