quangnguyen30192 / cmp-nvim-ultisnips

nvim-cmp source for ultisnips
Apache License 2.0
145 stars 19 forks source link

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

Closed SingularisArt closed 1 year ago

SingularisArt commented 1 year ago

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:

https://user-images.githubusercontent.com/57925294/211375592-93431f93-49c3-4c15-865b-4247b44c86fb.mp4

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

quangnguyen30192 commented 1 year ago

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 https://github.com/neovim/neovim/issues/8085

You can also check what is the output from :checkhealth

SingularisArt commented 1 year ago

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

quangnguyen30192 commented 1 year ago

Did you install the plugin 'SirVer/ultisnips'?

SingularisArt commented 1 year ago

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

quangnguyen30192 commented 1 year ago

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 https://github.com/SirVer/ultisnips/issues/244

SingularisArt commented 1 year ago

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",
  },
})
quangnguyen30192 commented 1 year ago

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?

SingularisArt commented 1 year ago

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.

smjonas commented 1 year ago

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

SingularisArt commented 1 year ago

I still get the error.

SingularisArt commented 1 year ago

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.

smjonas commented 1 year ago

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

SingularisArt commented 1 year ago

Sure. Here's the link.

quangnguyen30192 commented 1 year ago

@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",
  },

})
SingularisArt commented 1 year ago

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

quangnguyen30192 commented 1 year ago

Great to hear 😸

SingularisArt commented 1 year ago

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.

quangnguyen30192 commented 1 year ago

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

SingularisArt commented 1 year ago

yeah.

SingularisArt commented 1 year ago

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

SingularisArt commented 1 year ago

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.