quangnguyen30192/cmp-nvim-ultisnips

E5108: Error executing lua Vim:E117: Unknown function: `UltiSnips#CanJumpForwards`, `UltiSnips#CanJumpBackwards`, and `UltiSnips#CanExpand`

SingularisArt opened this issue · 21 comments

Here's my current config:

local cmp = require("cmp")
local cmp_ultisnips_mappings = require("cmp_nvim_ultisnips.mappings")
local neogen_ok, neogen = pcall(require, "neogen")

local icons = require("lazyvim.config.global").icons
local kind_icons = icons.kind
local duplicates = {
  buffer = 1,
  path = 1,
  nvim_lsp = 0,
}

local source_names = {
  nvim_lsp = "(LSP)",
  ultisnips = "(Snippets)",
  calc = "(Calc)",
  path = "(Path)",
  buffer = "(Buffer)",
  emoji = "(Emoji)",
  nvim_lua = "(Lua)",
}

local cmp_sources = {
  { name = "nvim_lsp" },
  { name = "ultisnips" },
  { name = "calc" },
  { name = "path" },
  { name = "buffer" },
  { name = "emoji" },
  { name = "nvim_lua" },
}

cmp.setup({
  snippet = {
    expand = function(args)
      vim.fn["UltiSnips#Anon"](args.body)
    end,
  },

  mapping = cmp.mapping.preset.insert({
    ["<CR>"] = cmp.mapping({
      i = function(fallback)
        cmp_ultisnips_mappings.compose { "expand" } (fallback)
      end,
    }),

    ["<C-j>"] = cmp.mapping({
      i = function(fallback)
        cmp_ultisnips_mappings.compose { "jump_forwards" } (function()
          if neogen_ok and neogen.jumpable() then
            neogen.jump_next()
          else
            fallback()
          end
        end)
      end,
    }),

    ["<C-k>"] = cmp.mapping({
      i = function(fallback)
        cmp_ultisnips_mappings.compose { "jump_forwards" } (function()
          if neogen_ok and neogen.jumpable(true) then
            neogen.jump_prev()
          else
            fallback()
          end
        end)
      end,
    }),
  }),

  formatting = {
    fields = { "kind", "abbr", "menu" },

    format = function(entry, vim_item)
      local max_width = 50
      if max_width ~= 0 and #vim_item.abbr > max_width then
        vim_item.abbr = string.sub(vim_item.abbr, 1, max_width - 1) .. icons.ui.Ellipsis
      end

      vim_item.menu = ({
        omni = (vim.inspect(vim_item.menu):gsub('%"', "")),
        buffer = "[Buffer]",
      })[entry.source.name]
      vim_item.kind = kind_icons[vim_item.kind]
      vim_item.menu = source_names[entry.source.name]
      vim_item.dup = duplicates[entry.source.name]
      return vim_item
    end,
  },
  sources = cmp_sources,
})

Here's the error:

2023-01-09_09-53-59.mp4

As you can see in the video, when I type Ctrl+{j,k} and Enter, I get those errors.

Thank you for reporting the error.

I suspect the issue was from your environment configuration

From the functions you mentioned, they are in https://github.com/SirVer/ultisnips/blob/master/autoload/UltiSnips.vim#L8
And seems py3 is not installed on your machine.

You can check by opening your vim and entering the following commands:

:py3 import vim
:py3 import UltiSnips
:py3 from UltiSnips import UltiSnips_Manager

If these commands do not work, then try install py3 module for neovim, maybe this link will help neovim/neovim#8085

You can also check what is the output from :checkhealth

Running :py3 import vim works, but when I run :py3 import UltiSnips, it doesn't work, saying ModuleNotFound. How can I install UltiSnips?

Did you install the plugin 'SirVer/ultisnips'?

Yeah. I have it installed, via lazy.lua.

UltiSnips module will bootstrap when the plugin manager loads 'SirVer/ultisnips' properly. The module is here if you're curious https://github.com/SirVer/ultisnips/tree/master/pythonx

Then it seems the problem is your plugin manager. Can you check the UltiSnips plugin is properly loaded by check the command: :UltiSnipsAddFiletypes?

A similar problem reported here SirVer/ultisnips#244

When I run that, I get the following error: E471: Argument required. I use lazy.vim to load. Here's the snippet that I use to load UltiSnips, and this plugin:

require("lazy").setup({
  {
    "hrsh7th/nvim-cmp",
    config = function()
      local cmp = require("cmp")
      ...
    end,
    dependencies = {
      "quangnguyen30192/cmp-nvim-ultisnips",
      ...
    },
    event = "InsertEnter",
  },

  {
    "SirVer/ultisnips",
    config = function()
      vim.g.UltiSnipsRemoveSelectModeMappings = 0
      vim.g.UltiSnipsEditSplit = "tabdo"
      vim.g.UltiSnipsSnippetDirectories = {
        "~/.config/nvim/UltiSnips", "UltiSnips"
      }
    end,
    event = "InsertEnter",
  },
})

I expect "SirVer/ultisnips" is loaded before "hrsh7th/nvim-cmp" and "quangnguyen30192/cmp-nvim-ultisnips". And it had better be without the event - it should load eagerly.

Could you update and try again?

Now, I tried the following code:

require("lazy").setup({
  {
    "hrsh7th/nvim-cmp",
    config = function()
      local cmp = require("cmp")
      ...
    end,
    lazy = false,
    -- event = "InsertEnter",
  },

  -- snippets
  {
    "SirVer/ultisnips",
    config = function()
      vim.g.UltiSnipsRemoveSelectModeMappings = 0
      vim.g.UltiSnipsEditSplit = "tabdo"
      vim.g.UltiSnipsSnippetDirectories = {
        "~/.config/nvim/UltiSnips", "UltiSnips"
      }
    end,
    dependencies = {
      "quangnguyen30192/cmp-nvim-ultisnips",
    },
    lazy = false,
    -- event = "InsertEnter",
  },
})

But I'm still getting the error.

Can you try loading UltiSnips manually (vim.cmd("runtime! plugin/UltiSnips.vim")) and see if that helps?

I still get the error.

It was working, until about a week ago, when I updated all my plugins, I kept getting that error. I don't know if it's a problem with how I'm using my plugin manager, or if I'm doing something wrong on my end. Would you like me to send you my neovim config link? It's relatively small.

Sure, feel free to share that. It might be caused by lazy.nvim and the way it handles caching / lazy-loading.

Sure. Here's the link.

@SingularisArt can you try with loading "SirVer/ultisnips" first, and cmp-nvim-ultisnips should be a dependencies of nvim-cmp?

require("lazy").setup({
  -- snippets
  {
    "SirVer/ultisnips",
    config = function()
      vim.g.UltiSnipsRemoveSelectModeMappings = 0
      vim.g.UltiSnipsEditSplit = "tabdo"
      vim.g.UltiSnipsSnippetDirectories = {
        "~/.config/nvim/UltiSnips", "UltiSnips"
      }
    end,
    lazy = false,
    -- event = "InsertEnter",
  },
  {
    "hrsh7th/nvim-cmp",
    config = function()
      local cmp = require("cmp")
      ...
    end,
    dependencies = {
      "quangnguyen30192/cmp-nvim-ultisnips",
    },
    lazy = false,
    -- event = "InsertEnter",
  },

})

It works. For some reason, after I put UltiSnips above CMP, and then run Lazy sync, it works now.

Great to hear 😸

NVM, LOL. After exiting neovim and coming back, I still get the same issue. I'll just open a question lazy.nvim, because I feel like it's the way lazy.nvim is loading the plugin.

Did you put quangnguyen30192/cmp-nvim-ultisnips as the dependencies of nvim-cmp?

yeah.

Alright. Here's the link to the issue I created.

Alright. I found my issue. I had some funny autocmd issue that was conflicting with lazy.nvim. So, I just removed it. Now, it works fine.