Why is my neovim plugin not loaded despite lazy telling me it is
Asked Answered
R

2

8

I just switched - or tried to - from Vim-Plug to Lazy. I thought this should not be too complicated. It turned out I was completely wrong. I am already trying to figure out for hours why some plugins just don't get loaded.

I don't want to paste the entire configuration (the entire configuration is huge) but some of the relevant part is within the setup of lazy:

require ('lazy').setup ({
...
    {
        'neovim/nvim-lspconfig',
        config = function () require 'config.lsp-config-conf' end
    },
    {
        'p00f/clangd_extensions.nvim', -- !! THIS DOES NOT GET LOADED !!
        dependencies = {'neovim/nvim-lspconfig'},
        config = function () require 'config.clangd-extensions' end,
    },
...
})

My setup was working with Vim-Plug for quite some time - there are no changes in those configurations and if I switch back to Vim-Plug (I am doing this in another branch so I can jump back and forth) everything works again.

I am completely puzzled - I've read the quickstart and introduction up and down, absolutely nothing points me to the problem.

Does anyone have an idea where to start, why is the plugin clangd_extensions not loaded/not active?

I even just realized that my lsp configuration does not work either, there is very awkward different behavior in my on_attach - it seems that part of the function is not executed (keymaps I setup work but vim.lsp.buf.document_highlight does not work - or lsp behaves different - depending on a package manager? 😜). To be precise: When I switch my repo back to Vim-Plug, this behavior is not reproducible, everything works as expected. As soon as I use lazy things do not work anymore.

When I enter :Lazy I can see all the plugins listed. I can see the time consumed loading for every plugin - but the plugins (or just some) are not loaded. E.g. clangd_extensions defines a command :ClangdSwitchSourceHeader, the command does not exist when I use lazy. It does exist when I load the plugin with Vim-Plug.

It also does not change anything if I manually hit :Lazy load clangd_extensions.nvim, nothing happens.

Or is it simply that the plugin is not compatible with lazy?... Or do I have to do something after setup?

I have read the documentation up and down, I could not find any hint about anything else needed besides setup. I tried by setting the attribute lazy to false, nothing I tried had any notable effect.

Roswald answered 11/4, 2023 at 15:47 Comment(1)
In my case lualine wasn't even being installed. The configuration was inside lazy/lualine.lua, after I renamed the file to lazy/nvim-lualine.lua (the repository name is nvim-lualine) then it finally appeared in the install list in :Lazy.Glennieglennis
U
8
  • The better/elegent/prefered way to manage plugins in nvim using lazy.nvim is through ~/.config/lua/plugins directory and download, configure every plugin in their own file and return the contents of that file as a lua table.

eg:

return {
  "lukas-reineke/indent-blankline.nvim",
  config = function ()
    require("indent_blankline").setup {
      char = "▏",
      show_trailing_blankline_indent = false,
      show_first_indent_level = true,
      use_treesitter = true,
      show_current_context = false,
      buftype_exclude = { "terminal", "nofile" },
      filetype_exclude = {
        "help",
        "packer",
        "NvimTree",
      },
    }
  end
}
  • Now second question might be is that how will lazy get know that this ~/.config/lua/plugins directory is containing all the plugins, so for that you can configure lazy in a file under ~/.config/lua/core/lazy-setup.lua and put configuration like this.
require("lazy").setup("plugins", {}) -- here you are telling lazy to look for a plugins dir and in {} this lua table you put all configuration related to lazy.
  • After that require lazy-setup file in ~/.config/nvim/init.lua like so.
require "lazy-setup"
  • And for more understading you can take reference from my nvim config.
Upraise answered 14/4, 2023 at 18:46 Comment(0)
R
2

I don't know what exactly the problem was - most probably I did not correctly state all dependencies correctly but the trouble is now gone.

What I did was to split all plugin specs to separate files within lua/plugins and call lazy setup with {{import = 'plugins'}} as suggested. This way I ended up having plugins and sort of plugin groups all in separate drop-in files all specifying exactly their dependencies and configuration. So if I want to install or remove a plugin all I have to do is create or delete the corresponding file.

Furthermore I discovered that if I specify a plugin (with a config function) and somewhere else I list that plugin as a dependency, the dependency gets loaded (and configured) beforehand. If no corresponding specification exists, the plugin is simply installed. As long as no circular dependency exists, all dependencies are correctly resolved. This feels like dependency injection the nice way.

Roswald answered 12/4, 2023 at 7:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.