folke / lazy.nvim

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

Is it possible to setup some plugins in the setup and then load module and submodules of plugins? #52

Closed datwaft closed 1 year ago

datwaft commented 1 year ago

Is your feature request related to a problem? Please describe. Hello!

I am thinking about migrating my Neovim configuration to this package manager but my Neovim configuration uses Fennel with hotpot.nvim. That means that I have some plugins that I must have installed before the plugins module can be compiled.

My idea is to do something like...

-- init.lua
require("lazy").setup({
  "rktjmp/hotpot.nvim",
  "conf.plugins",
})

...which would always install hotpot.nvim for me and then would use the compiled conf.plugins module.

Describe the solution you'd like It would be ideal to be able to specify some plugins inside the init.lua file and a module containing plugins to load.

Describe alternatives you've considered I have considered bootstrapping hotpot.nvim but I am not sure of what the best practice for this would be.

If I am able to do that I could load lazy.nvim inside fnl/conf/init.fnl.

Additional context I have already setup a Lua demo configuration and I am loving this plugin. 😄

folke commented 1 year ago

That's not possible with lazy and would require too many loopholes to make this work.

datwaft commented 1 year ago

I found a workaround:

init.lua

-- Bootstrap lazy.nvim
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,
  })
end

-- Add lazy.nvim to rtp
vim.opt.runtimepath:prepend(lazypath)

-- Configure lazy.nvim
require("lazy").setup("conf.plugins", {
  performance = {
    cache = {
      enabled = false,
    },
  },
})

if pcall(require, "hotpot") then
  -- Initialize hotpot
  require("hotpot").setup({
    provide_require_fennel = true,
    enable_hotpot_diagnostics = false,
  })
  -- Compile plugin configurations
  -- This is required because Lazy requires in some way those plugins and hotpot doesn't detect that they have been required
  for file in vim.fs.dir(vim.fn.stdpath("config") .. "/fnl/conf/plugins") do
    file = file:match("^(.*)%.fnl$")
    require("conf.plugins." .. file)
  end
  -- Execute configuration
  require("conf")
else
  vim.notify(table.concat({
    "Plugin `hotpot.nvim` could not be required.",
    "Make sure that hotpot is installed using `:Lazy`.",
    "The configuration won't be loaded."
  }, "\n"), vim.log.levels.WARN)
end

lua/conf/plugins/hotpot.lua

return {
  "rktjmp/hotpot.nvim",
  dependencies = {
    "datwaft/themis.nvim",
  },
}

This works perfectly (for anything that is a plugin module) but I am having two issues with Lazy using Fennel plugin modules:

  1. Hotpot doesn't detect when Lazy requires the plugin modules so it doesn't compile those files. For that I found this workaround:
    -- Compile plugin configurations
    -- This is required because Lazy requires in some way those plugins and hotpot doesn't detect that they have been required
    for file in vim.fs.dir(vim.fn.stdpath("config") .. "/fnl/conf/plugins") do
      file = file:match("^(.*)%.fnl$")
      require("conf.plugins." .. file)
    end
  2. But that workaround doesn't fix the problem. Lazy is still not finding my compiled .fnl files.

Here is the compiled output of fnl/conf/plugins/treesitter.fnl:

local function config()
  local treesitter = require("nvim-treesitter.configs")
  return treesitter.setup({ensure_installed = "all", highlight = {enable = true}, rainbow = {enable = true}, context_commentstring = {enable = true}, indent = {enable = false}, yati = {enable = true}})
end
return {{build = ":TSUpdate", config = config, dependencies = {"p00f/nvim-ts-rainbow", "JoosepAlviste/nvim-ts-context-commentstring", "yioneko/nvim-yati"}, "nvim-treesitter/nvim-treesitter"}}

It can be found in ~/.cache/nvim/hotpot/Users/datwaft/.config/nvim.lazy/fnl/conf/plugins/treesitter.lua.

I know it is not being detected because :Lazy doesn't show treesitter.

image

Should I open a new issue?

folke commented 1 year ago

Both lazy and fennel add package loaders, which probably interfer.

You can try disabling the lazy cache and see if that works.

datwaft commented 1 year ago

As you can see in the example I have the cache disabled:

-- Configure lazy.nvim
require("lazy").setup("conf.plugins", {
  performance = {
    cache = {
      enabled = false,
    },
  },
})