lewis6991/pckr.nvim

Seemingly random require order sometimes causes errors

Closed this issue · 1 comments

  • nvim --version: v0.10.0
  • git --version: 2.45.2
  • Operating system/version: Archlinux
  • Terminal name/version: st terminal (own patch)

Steps to reproduce

Start neovim by requiring my plugins.lua file in the init.lua.

Actual behaviour

Sometimes I get this error that pops up, after which none of my LSP-related features work. I can fix this by restarting neovim 1 or more times until it starts up without having the error pop up.

[pckr.nvim[ERROR 09:17:02] loader.lua:10: Error running config for nvim-lspconfig:
^I/home/jjr/.config/nvim/lua/config/lspconfig.lua:26: module 'cmp_nvim_lsp' not found:
^Ino field package.preload['cmp_nvim_lsp']
^Ino file './cmp_nvim_lsp.lua'
^Ino file '/usr/share/luajit-2.1/cmp_nvim_lsp.lua'
^Ino file '/usr/local/share/lua/5.1/cmp_nvim_lsp.lua'
^Ino file '/usr/local/share/lua/5.1/cmp_nvim_lsp/init.lua'
^Ino file '/usr/share/lua/5.1/cmp_nvim_lsp.lua'
^Ino file '/usr/share/lua/5.1/cmp_nvim_lsp/init.lua'
^Ino file './cmp_nvim_lsp.so'
^Ino file '/usr/local/lib/lua/5.1/cmp_nvim_lsp.so'
^Ino file '/usr/lib/lua/5.1/cmp_nvim_lsp.so'
^Ino file '/usr/local/lib/lua/5.1/loadall.so'

My theory for this is that Pckr does not import the plugins in any specific order. However, some of my plugins do use each either's module in their config, causing the module 'cmp_nvim_lsp' not found error if the plugin that requires it was loaded before the cmp_nvim_lsp.

I only started seeing this behavior after I migrated from Packer to Pckr recently.

Expected behaviour

For this error to not occur, and the plugin configs to load correctly.

pckr files

Plugin specification file(s)
local function bootstrap_pckr()
  local pckr_path = vim.fn.stdpath("data") .. "/pckr/pckr.nvim"

  if not vim.uv.fs_stat(pckr_path) then
    vim.fn.system({
      'git',
      'clone',
      "--filter=blob:none",
      'https://github.com/lewis6991/pckr.nvim',
      pckr_path
    })
  end

  vim.opt.rtp:prepend(pckr_path)
end

bootstrap_pckr()

require('pckr').add{
    {
        "tpope/vim-fugitive",
        config = function()
            require('config.fugitive')
        end
    },
    {
        "ctrlpvim/ctrlp.vim",
        config_pre = function()
            require('config.ctrlp')
        end
    },
    "tpope/vim-commentary",
    {
        "preservim/nerdtree",
        config = function()
            require('config.nerdtree')
        end
    },
    "jiangmiao/auto-pairs",
    "editorconfig/editorconfig-vim",
    {
        "marko-cerovac/material.nvim",
        config = function()
            vim.cmd("colorscheme material")
            -- color material
            nmap("<leader>c", [[<Cmd>lua require('material.functions').toggle_style()<CR>]])
        end
    },
    {
        'hrsh7th/nvim-cmp',
        config = function()
            require('config.cmp')
        end
    },
    'hrsh7th/cmp-nvim-lsp',
    'hrsh7th/cmp-buffer',
    'hrsh7th/cmp-path',
    'hrsh7th/cmp-cmdline',
    {
        "neovim/nvim-lspconfig",
        config = function()
            require('config.lspconfig')
        end
    },
    {
        "nvim-treesitter/nvim-treesitter",
        run = ":TSUpdate",
        config = function()
            require("config.treesitter")
        end
    },

    -- Toggleable terminals
    {
       "akinsho/toggleterm.nvim",
        config = function()
            require('config.toggleterm')
        end
    },
    {
        "ms-jpq/coq_nvim",
        config = "config.coq"
    },
    "L3MON4D3/LuaSnip",
    "saadparwaiz1/cmp_luasnip"
}

cmp_nvim_lsp depends on nvim-cmp.

You need to add it as:

  {'hrsh7th/nvim-cmp', config = function()
    require('config.cmp')
  end},

  -- nvim-cmp sources require nvim-cmp since they depend on it in there plugin/
  -- files
  { 'hrsh7th/cmp-nvim-lsp', requires = 'hrsh7th/nvim-cmp' },
  { 'hrsh7th/cmp-buffer', requires = 'hrsh7th/nvim-cmp' },
  { 'hrsh7th/cmp-path', requires = 'hrsh7th/nvim-cmp' },
  { 'hrsh7th/cmp-cmdline', requires = 'hrsh7th/nvim-cmp' },