asyncedd / dots.nvim

My neovim dotfiles.
MIT License
30 stars 2 forks source link

Unable to import plugins from its subfolders #121

Closed ghost closed 1 year ago

ghost commented 1 year ago

Intro

Hi @asyncedd, I @Swayam25 a full-stack developer. I was previously using vscode then I switched to neovim it's just because I have a pc with Ubuntu v23.04, 2GB ram, 500 GB HDD. Intel Pentium G2030 processor. I coded all my projects on this pc via vscode. Just before some months I got to know about vim. Yeah I am too using lazy.nvim. I had installed LazyVim but it wasn't too customizable for me and they also gave some plugins which I don't need just It slows down neovim after some research I found out your repo and I customized some of your codes to meet my need and changed the plugins folder structure, but now Im getting this error.

The Issue

Error Message

Error detected while processing /home/swayam25/.config/nvim/init.lua:
E5113: Error while calling lua chunk: .../.local/share/nvim/lazy/lazy.nvim/lua/l
azy/core/util.lua:222: attempt to call method 'gsub' (a nil value)
stack traceback:
        .../.local/share/nvim/lazy/lazy.nvim/lua/lazy/core/util.lua:222: in func
tion 'get_unloaded_rtp'
        .../.local/share/nvim/lazy/lazy.nvim/lua/lazy/core/util.lua:246: in func
tion 'find_root'
        .../.local/share/nvim/lazy/lazy.nvim/lua/lazy/core/util.lua:258: in func
tion 'lsmod'
        ...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/plugin.lua:275: in func
tion 'import'
        ...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/plugin.lua:250: in func
tion 'normalize'
        ...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/plugin.lua:238: in func
tion 'normalize'
        ...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/plugin.lua:35: in funct
ion 'parse'
        ...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/plugin.lua:395: in func
tion 'load'
        ...local/share/nvim/lazy/lazy.nvim/lua/lazy/core/loader.lua:36: in funct
ion 'setup'
        ...yam25/.local/share/nvim/lazy/lazy.nvim/lua/lazy/init.lua:75: in funct
ion 'setup'
        /home/swayam25/.config/nvim/lua/plugins/init.lua:18: in main chunk
        [C]: in function 'require'
        /home/swayam25/.config/nvim/init.lua:9: in main chunk

File Structure

.config/nvim
├── init.lua
├── lazy-lock.json
├── lua
│   ├── autocmds.lua
│   ├── keymaps.lua
│   ├── options.lua
│   └── plugins
│       ├── code
│       │   ├── coc.lua
│       │   ├── comment.lua
│       │   ├── copilot.lua
│       │   ├── luasnip.lua
│       │   ├── nvim_cmp.lua
│       │   ├── ultimate_autopair.lua
│       │   └── vim_illuminate.lua
│       ├── init.lua
│       ├── langs
│       ├── ui
│       │   ├── alpha.lua
│       │   ├── bufferline.lua
│       │   ├── catpuccin.lua
│       │   ├── gitsigns.lua
│       │   ├── mini_animate.lua
│       │   ├── neoscroll.lua
│       │   ├── neo_tree.lua
│       │   ├── nvim_treesitter.lua
│       │   ├── telescope.lua
│       │   ├── vim_illuminate.lua
│       │   └── which_key.lua
│       └── version_control
│           └── lazygit.lua
└── stylua.toml

6 directories, 26 files

File: nvim/lua/plugins/init.lua

-- Vim.fn.stdpath("data") is in Linux systems: ~/.local/nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"

-- If it's not found - indicating that it's not found - Git clone it (~)_(~)
if not vim.loop.fs_stat(lazypath) then
    -- Show a lovely message indicating that we're boostrapping lazy :)
    print(" Bootstrapping lazy.nvim!")

    --  lazy.nvim recommends to use vim.fn.system but, via `vim.cmd("!...")` we can know the progress ;)
    vim.cmd("!git clone --filter=blob:none https://github.com/folke/lazy.nvim.git --branch=stable " .. lazypath)
    print(" Done!")
end

-- Add it to RTP. So, we can require it later on
vim.opt.rtp:prepend(lazypath)

-- Import plugins from `lua/plugins`
require("lazy").setup(
    { 
        import = {
            "plugins.ui",
            "plugins.code",
            "plugins.langs",
            "plugins.version_control"
        }

    }, {
    defaults = {
        -- Lazy-load by default
        lazy = true,
        -- Use the latest version of the plugin (screw semantic versioning)
        version = false,
    },
    install = {
        -- Install missing plugins.
        missing = true,
        colorscheme = {
            -- These are a list of plugins to load when installing a plugin
            -- It's listed on order. catppuccin -> habamax
            "catppuccin",
            "habamax",
        },
    },
    performance = {
        rtp = {
            disabled_plugins = {
                -- I can disable more plugins such as `rplugin` and `netrw`, it'll decrease functionality.
                "gzip",
                "tarPlugin",
                "tohtml",
                "zipPlugin",
                "matchit",
                "matchparen",
                "netrwPlugin",
                "rplugin",
                "nvim",
                "tutor",
                -- "spellfile",
            },
        },
    },
})

File: nvim/init.lua

-- Enable the experimental new loader.
vim.loader.enable()

-- Set some options.
require("options")
require("autocmds")

-- Require lazy.nvim.
require("plugins")

-- Theme
vim.cmd.colorscheme("catpuccin")

vim.schedule(
    function()
        require("keymaps")
    end
)

What I got to know from this

When I do import = "plugins.ui" it works but when I do multi import import = {} it sucks.

Steps To Reproduce

Run nvim

Expected Behavior

It should load all the plugins with its subfolders

asyncedd commented 1 year ago

Hey, Nice to meet you! I'd love it if you provide your dotfiles so, I can test it locally. But anyways, thanks for the (large) amount of info!

Nevertheless, I'm pretty sure that lazy.nvim assumes that anything inside a import (e.g import = "x") is a string. So, lazy won't loop inside the array to import it. (I assume)

Anyways, try replacing your lua/plugins/init.lua with this:

-- Vim.fn.stdpath("data") is in Linux systems: ~/.local/nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"

-- If it's not found - indicating that it's not found - Git clone it (~)_(~)
if not vim.loop.fs_stat(lazypath) then
  -- Show a lovely message indicating that we're boostrapping lazy :)
  print(" Bootstrapping lazy.nvim!")

  --  lazy.nvim recommends to use vim.fn.system but, via `vim.cmd("!...")` we can know the progress ;)
  vim.cmd("!git clone --filter=blob:none https://github.com/folke/lazy.nvim.git --branch=stable " .. lazypath)
  print(" Done!")
end

-- Add it to RTP. So, we can require it later on
vim.opt.rtp:prepend(lazypath)

-- Import plugins from `lua/plugins`
require("lazy").setup(
  {
    { import = "plugins.ui" },
    { import = "plugins.code" },
    { import = "plugins.langs" },
    { import = "plugins.version_control" },
  },
  {
    defaults = {
      -- Lazy-load by default
      lazy = true,
      -- Use the latest version of the plugin (screw semantic versioning)
      version = false,
    },
    install = {
      -- Install missing plugins.
      missing = true,
      colorscheme = {
        -- These are a list of plugins to load when installing a plugin
        -- It's listed on order. catppuccin -> habamax
        "catppuccin",
        "habamax",
      },
    },
    performance = {
      rtp = {
        disabled_plugins = {
          -- I can disable more plugins such as `rplugin` and `netrw`, it'll decrease functionality.
          "gzip",
          "tarPlugin",
          "tohtml",
          "zipPlugin",
          "matchit",
          "matchparen",
          "netrwPlugin",
          "rplugin",
          "nvim",
          "tutor",
          -- "spellfile",
        },
      },
    },
  }
)

Try and test this.

The things I changed is:

Let me know if it works!

ghost commented 1 year ago

A heartfelt thanks to you! Yeah, It worked!

asyncedd commented 1 year ago

I'm glad it worked! I'll go ahead and close this issue for now. If you have any more questions, feel free to ask!

ghost commented 1 year ago

Do you have any discord id so that I can talk with you personally?

asyncedd commented 1 year ago

Yeah! async#8467

ghost commented 1 year ago

Yeah! async#8467

Check your DMs please.

asyncedd commented 1 year ago

Sorry, I'm quite busy.