folke / lazy.nvim

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

feature: Don't process dependencies if spec is disabled #868

Closed UtkarshVerma closed 1 year ago

UtkarshVerma commented 1 year ago

Did you check the docs?

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

I am organizing my plugin spec based on the feature they implement. For example, completion.lua has the following snippet:

  {
    "hrsh7th/cmp-nvim-lsp",
    dependencies = {
      {
        "nvim-lspconfig",
        opts = function(_, opts)
          return vim.tbl_deep_extend("force", opts, {
            capabilities = require("cmp_nvim_lsp").default_capabilities(),
          })
        end,
      },
    },
  }

If, for some reason, I wanted to disable this specific spec, I can do it through enabled = false. However, even when I disable the spec, lazy still tries to process the dependencies and tries to initialize nvm-lspconfig with cmp-nvim-lsp. This fails because the plugin has not been loaded.

/home/subaru/.config/nvim/lua/plugins/completion.lua:24: module 'cmp_nvim_lsp' not found:
    no field package.preload['cmp_nvim_lsp']
cache_loader: module cmp_nvim_lsp not found
cache_loader_lib: module cmp_nvim_lsp not found
    no file './cmp_nvim_lsp.lua'
    no file '/usr/share/luajit-2.1.0-beta3/cmp_nvim_lsp.lua'
    no file '/usr/local/share/lua/5.1/cmp_nvim_lsp.lua'
    no file '/usr/local/share/lua/5.1/cmp_nvim_lsp/init.lua'
    no file '/usr/share/lua/5.1/cmp_nvim_lsp.lua'
    no file '/usr/share/lua/5.1/cmp_nvim_lsp/init.lua'
    no file './cmp_nvim_lsp.so'
    no file '/usr/local/lib/lua/5.1/cmp_nvim_lsp.so'
    no file '/usr/lib/lua/5.1/cmp_nvim_lsp.so'
    no file '/usr/local/lib/lua/5.1/loadall.so'

# stacktrace:
  - ~/.config/nvim/lua/plugins/completion.lua:24 _in_ **values**
  - vim/_editor.lua:0 _in_ **cmd**
  - /persistence.nvim/lua/persistence/init.lua:57 _in_ **load**
  - lua/:1
  - vim/_editor.lua:0 _in_ **cmd**
  - /dashboard-nvim/lua/dashboard/theme/doom.lua:23

Describe the solution you'd like

If any spec has enabled = false set, then lazy should completely ignore all config associated with it, including the dependencies.

Describe alternatives you've considered

N/A

Additional context

No response

AlexMasterov commented 1 year ago

The same problem with the keys property. Plugin is disabled but its key mappings are loaded.

folke commented 1 year ago

@AlexMasterov that's not correct. When using cond then yes, that's on purpose, but not when enabled=false

folke commented 1 year ago

As for OP's issue, that's how dependencies work.

Dependencies just specify what deps need to be loaded when the plugin loads. It does not do anything special to the specs of the dependencies.

Specs get merged to one spec per plugin.

As long as a plugin is not disabled, it will be loaded.

Merging part of a spec only when the dependent is enabled is not supported.