0

So I installed and created the respective configuration according to the official github repo. I'm using NVIM v0.9.1

When I run :CmpStatus it throws me this error

Error executing Lua callback: /home/user/.local/share/nvim/lazy/nvim-cmp/plugin/cmp.lua:58: loop or previous error loading module 'cmp'
stack traceback:
        [C]: in function 'require'
        /home/user/.local/share/nvim/lazy/nvim-cmp/plugin/cmp.lua:58: in function </home/user/.local/share/nvim/lazy/nvim-cmp/plugin/cmp.lua:57>
Press ENTER or type command to continue

This is my ~/.config/nvim/init.lua

--------------------
-- Lazy Bootstrap --
--------------------
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",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable", -- latest stable release
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

-------------
-- Plugins --
-------------
local opts = {}
local plugins = {
  ----------------
  -- Aesthetics --
  ----------------
  -- Color Scheme
  "EdenEast/nightfox.nvim",
  -- Contrast tab lines
  "lukas-reineke/indent-blankline.nvim",
  -- UI Focus
  "Pocco81/true-zen.nvim",
  -- Colored Delimeters
  "HiPhish/rainbow-delimiters.nvim",

  -----------
  -- Utils --
  -----------
  -- Treesitter
  {"nvim-treesitter/nvim-treesitter", build = ":TSUpdate"},
  "nvim-treesitter/nvim-treesitter-textobjects",
  -- Fuzzy finder
  {
    "nvim-telescope/telescope.nvim",
    tag = "0.1.2",
    dependencies = { "nvim-lua/plenary.nvim" }
  },
  -- Manipulating delimeters (parenthesis, brackest, quotes, etc)
  "kylechui/nvim-surround",
  -- Comments
  "numToStr/Comment.nvim",
  -- Auto pairs
  {
    'windwp/nvim-autopairs',
    event = "InsertEnter",
    opts = {} -- this is equalent to setup({}) function
  },

  ----------------
  -- Completion --
  ----------------
  -- CMP
  "neovim/nvim-lspconfig",
  "hrsh7th/cmp-nvim-lsp",
  "hrsh7th/cmp-buffer",
  "hrsh7th/cmp-path",
  "hrsh7th/cmp-cmdline",
  "hrsh7th/nvim-cmp",

  ---------------
  -- Snippets ---
  ---------------
  {
    "L3MON4D3/LuaSnip",
    -- follow latest release.
    version = "2.*", -- Replace <CurrentMajor> by the latest released major (first number of latest release)
    -- install jsregexp (optional!).
    build = "make install_jsregexp"
  }

}


-------------
-- Imports --
-------------
require("lazy").setup(plugins, opts)
require("keymaps")
require("options")
require("ui")
require("delimeters")
require("comment")
require("surround")
require("rainbow_deli")
require("zen")
require("cmp")

And my ~/.config/nvim/lua/cmp.lua

-- Set up nvim-cmp.
local cmp = require'cmp'

cmp.setup({
snippet = {
  -- REQUIRED - you must specify a snippet engine
  expand = function(args)
    vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
    require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
    -- require('snippy').expand_snippet(args.body) -- For `snippy` users.
    -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
  end,
},
window = {
  -- completion = cmp.config.window.bordered(),
  -- documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
  ['<C-b>'] = cmp.mapping.scroll_docs(-4),
  ['<C-f>'] = cmp.mapping.scroll_docs(4),
  ['<C-Space>'] = cmp.mapping.complete(),
  ['<C-e>'] = cmp.mapping.abort(),
  ['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
}),
sources = cmp.config.sources({
  { name = 'nvim_lsp' },
  -- { name = 'vsnip' }, -- For vsnip users.
  { name = 'luasnip' }, -- For luasnip users.
  -- { name = 'ultisnips' }, -- For ultisnips users.
  -- { name = 'snippy' }, -- For snippy users.
}, {
  { name = 'buffer' },
})
})

-- Set configuration for specific filetype.
cmp.setup.filetype('gitcommit', {
sources = cmp.config.sources({
  { name = 'git' }, -- You can specify the `git` source if [you were installed it](https://github.com/petertriho/cmp-git).
}, {
  { name = 'buffer' },
})
})

-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline({ '/', '?' }, {
mapping = cmp.mapping.preset.cmdline(),
sources = {
  { name = 'buffer' }
}
})

-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
  { name = 'path' }
}, {
  { name = 'cmdline' }
})
})

-- Set up lspconfig.
local capabilities = require('cmp_nvim_lsp').default_capabilities()
-- Replace <YOUR_LSP_SERVER> with each lsp server you've enabled.
require('lspconfig')['clangd'].setup {
capabilities = capabilities
}

And when I run nvim it shows me this message:

Error detected while processing /home/user/.config/nvim/init.lua:
E5113: Error while calling lua chunk: /home/user/.config/nvim/init.lua:94: loop or previous error loading module 'cmp'
stack traceback:
        [C]: in function 'require'
        /home/user/.config/nvim/init.lua:94: in main chunk
Press ENTER or type command to continue

I then press enter and it continues with this error message:

Error detected while processing /home/user/.config/nvim/init.lua:
E5113: Error while calling lua chunk: /home/user/.config/nvim/init.lua:94: loop or previous error loading module 'cmp'
stack traceback:
        [C]: in function 'require'
        /home/user/.config/nvim/init.lua:94: in main chunk
Press ENTER or type command to continue

Then the same error message but for cmp_buffer.lua and cmp_cmdline.lua.

When I try to enter some text in NeoVim it shows me this

Error detected while processing InsertEnter Autocommands for "*":
Error executing lua callback: ...l/share/nvim/lazy/cmp-nvim-lsp/lua/cmp_nvim_lsp/init.lua:102: loop or previous error loading m
odule 'cmp'
stack traceback:
        [C]: in function 'require'
        ...l/share/nvim/lazy/cmp-nvim-lsp/lua/cmp_nvim_lsp/init.lua:102: in function <...l/share/nvim/lazy/cmp-nvim-lsp/lua/cmp
_nvim_lsp/init.lua:101>

What do you think could be the problem, an installation problem perhaps? I tried uninstalling neovim and installing everything again with no success at all!

1
  • Two suggestions: (1) don't post your whole config; use How to debug my vimrc to see how to find a minimal config that reproduces the problem. Once you have that, edit to replace the long config block with just the minimal example. (2) Try to get some support from the plugin maintainers (often via GitHub or a similar site). They know the code best.
    – D. Ben Knoble
    Commented Aug 7, 2023 at 14:59

1 Answer 1

0

All problems were gone when i uninstalled neovim completely and instead of naming it cmp.lua i used plg_cmp.lua i guess cmp.lua is used by the plugin itself and that's why it was causing errors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.