Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vim-vsnip not working on Neovim nightly! #219

Closed
ndavd opened this issue Oct 6, 2021 · 46 comments
Closed

vim-vsnip not working on Neovim nightly! #219

ndavd opened this issue Oct 6, 2021 · 46 comments

Comments

@ndavd
Copy link

ndavd commented Oct 6, 2021

Hi, I have the following config:

plugins.lua:

(...)
  use {'hrsh7th/nvim-cmp', requires = {
    'hrsh7th/cmp-nvim-lsp',
    'hrsh7th/cmp-buffer',
    'hrsh7th/cmp-vsnip',
    'hrsh7th/vim-vsnip',
    'hrsh7th/vim-vsnip-integ',
    'rafamadriz/friendly-snippets'
  }}
(...)

cmp_config.lua:

local cmp = require'cmp'
cmp.setup {
  snippet = {
    expand = function(args)
      vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` user.
    end,
  },
  mapping = {
    ['<C-Space>'] = cmp.mapping.complete(),
    ['<CR>'] = cmp.mapping.confirm({ select = true }),
    ['<C-e>'] = cmp.mapping.close(),
    ['<C-f>'] = cmp.mapping.scroll_docs(4),
    ['<C-d>'] = cmp.mapping.scroll_docs(-4),
    ['<Tab>'] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 's' }),
  },
  sources = {
    { name = 'nvim_lsp' },
    { name = 'vsnip' },
    { name = 'buffer' },
  }
}

Shouldn't Friendly-Snippets work with this config or am I missing something?

@ndavd
Copy link
Author

ndavd commented Oct 8, 2021

@hrsh7th

@marwan38
Copy link

marwan38 commented Oct 9, 2021

Same issue here, it stopped working awhile ago, I don't remember when exactly.

EDIT: I get this when i try to run :VsnipOpen. I am running the nightly version of nvim.
image

@ndavd
Copy link
Author

ndavd commented Oct 9, 2021

I don't actually get that message but yeah Friendly-Snippets are not working ...

@jeroenbourgois
Copy link

@marwan38 @ndav1d works here but I had to go back from the nightly version of Neovim to the stable 0.5.1.

@ndavd
Copy link
Author

ndavd commented Oct 9, 2021

oh that's probably why. I'm using NVIM v0.6.0-dev+446-g0fc8597f0 atm!

EDIT: yup, just checked with the official stable release of neovim and it works

@ndavd ndavd changed the title Can't get Friendly-Snippets to work vim-vsnip not working on Neovim nightly! Oct 9, 2021
@hrsh7th
Copy link
Owner

hrsh7th commented Oct 9, 2021

OK. I will update my environment and checks it.

@hrsh7th
Copy link
Owner

hrsh7th commented Oct 9, 2021

vim-vsnip and friendly-snippets works perfectly to me on nightly neovim.

NVIM v0.6.0-dev+446-g0fc8597f0
Build type: Release
LuaJIT 2.1.0-beta3```

@ndavd
Copy link
Author

ndavd commented Oct 9, 2021

I tried the same config on both stable releases and nightly and I don't get any snippets on the nightly... any checks or something I can do?

@ndavd
Copy link
Author

ndavd commented Oct 9, 2021

does my config look right?

EDIT: or perhaps share yours for me to try :)

@hrsh7th
Copy link
Owner

hrsh7th commented Oct 9, 2021

My minimal config is here.

if has('vim_starting')
  set encoding=utf-8
endif
scriptencoding utf-8

if &compatible
  set nocompatible
endif

let s:plug_dir = expand('/tmp/plugged/vim-plug')
if !filereadable(s:plug_dir .. '/plug.vim')
  execute printf('!curl -fLo %s/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim', s:plug_dir)
end

execute 'set runtimepath+=' . s:plug_dir
call plug#begin(s:plug_dir)
Plug 'hrsh7th/vim-vsnip'
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-vsnip'
Plug 'rafamadriz/friendly-snippets'
call plug#end()
PlugInstall | quit

imap <expr><C-l> vsnip#available(1)    ? '<Plug>(vsnip-expand)'         : '<C-l>'
smap <expr><C-l> vsnip#available(1)    ? '<Plug>(vsnip-expand)'         : '<C-l>'
imap <expr><Tab> vsnip#available(1)    ? '<Plug>(vsnip-expand-or-jump)' : '<Tab>'
smap <expr><Tab> vsnip#jumpable(1)     ? '<Plug>(vsnip-jump-next)'      : '<Tab>'
imap <expr><S-Tab> vsnip#available(-1) ? '<Plug>(vsnip-jump-prev)'      : '<S-Tab>'
smap <expr><S-Tab> vsnip#available(-1) ? '<Plug>(vsnip-jump-prev)'      : '<S-Tab>'

lua<<EOF
local cmp = require('cmp')
cmp.setup {
  mapping = {
    ['<CR>'] = cmp.mapping.confirm({ select = true })
  },
  sources = {
    { name = 'vsnip' }
  }
}
EOF

Sorry. I don't use packer.nvim so I can't test with your config...

@ndavd
Copy link
Author

ndavd commented Oct 9, 2021

with that config it works... maybe another plugin is messing things up?.......

@hrsh7th
Copy link
Owner

hrsh7th commented Oct 10, 2021

@ndav1d Do you get correct result without vim-vsnip-integ?

@ndavd
Copy link
Author

ndavd commented Oct 10, 2021

It doesn't work as well...

@ndavd
Copy link
Author

ndavd commented Oct 10, 2021

here are all the plugins I am using:

  -- Packer --
  use 'wbthomason/packer.nvim'

  -- Icon support --
  use {
    'yamatsum/nvim-web-nonicons',
    requires = {'kyazdani42/nvim-web-devicons'}
  }

  -- Smooth Scrolling --
  use 'psliwka/vim-smoothie'

  -- Scrollbar --
  use 'dstein64/nvim-scrollview'

  -- Better start screen --
  use {'mhinz/vim-startify'}

  -- Better matchit --
  use 'andymass/vim-matchup'

  -- Indentation --
  use 'tpope/vim-sleuth'

  -- Auto comment --
  use 'tpope/vim-commentary'

  -- Easy Align --
  use {'junegunn/vim-easy-align', keys = {{'x', '<plug>(LiveEasyAlign)'}}}

  -- Hop --
  use {
    'phaazon/hop.nvim',
    as = 'hop',
    config = function()
      require'hop'.setup { keys = 'etovxqpdygfblzhckisuran' }
    end
  }

  -- Surround text --
  use 'tpope/vim-surround'

  -- Complete brackets --
  use 'jiangmiao/auto-pairs'

  -- Startuptime --
  use 'dstein64/vim-startuptime'

  -- RFC --
  use 'mhinz/vim-rfc'

  -- Cheat.sh --
  use 'dbeniamine/cheat.sh-vim'

  -- Md previewer --
  use {'iamcco/markdown-preview.nvim', run = 'cd app && yarn install'}

  -- Colorizer --
  use {'norcalli/nvim-colorizer.lua'}

  -- Git --
  use 'tpope/vim-fugitive'
  use 'mhinz/vim-signify'

  -- Sql.nvim --
  use 'tami5/sql.nvim'

  -- Lua Scratchpad --
  use 'rafcamlet/nvim-luapad'

  -- View tags --
  use 'liuchengxu/vista.vim'

  -- Telescope --
  use {'nvim-telescope/telescope.nvim', requires = {
    'nvim-lua/popup.nvim',
    'nvim-lua/plenary.nvim',
    'nvim-telescope/telescope-fzy-native.nvim',
    'nvim-telescope/telescope-fzf-writer.nvim',
    'nvim-telescope/telescope-symbols.nvim',
    'nvim-telescope/telescope-frecency.nvim',
  }}

  -- Treesitter --
  use {'nvim-treesitter/nvim-treesitter', run = ':TSUpdate', requires =
    'windwp/nvim-ts-autotag'}
  use 'nvim-treesitter/playground'

  -- LSP --
  use {'neovim/nvim-lspconfig', requires = 'mfussenegger/nvim-jdtls'}
  use 'hrsh7th/vim-vsnip'
  use 'hrsh7th/nvim-cmp'
  use 'hrsh7th/cmp-vsnip'
  use 'rafamadriz/friendly-snippets'
  use 'hrsh7th/cmp-nvim-lsp'
  use 'hrsh7th/cmp-buffer'
  use 'hrsh7th/cmp-path'
  use 'ray-x/cmp-treesitter'
  use 'f3fora/cmp-spell'

@ndavd
Copy link
Author

ndavd commented Oct 10, 2021

can't figure out what's wrong with my config

@hrsh7th
Copy link
Owner

hrsh7th commented Oct 10, 2021

If I met the plugin combination bug, I usually binary search with disabling plugins one by one...

@jebaum
Copy link

jebaum commented Oct 10, 2021

I'm having similar issues, the plugin causing issues for me was vim-matchup, which I noticed you also have @ndav1d

somehow vim-matchup was messing with the completion menu for nvim-cmp in showing snippets, although they still won't expand. continuing to tinker with it

@hrsh7th
Copy link
Owner

hrsh7th commented Oct 10, 2021

I will check what is happend here.

@jebaum
Copy link

jebaum commented Oct 10, 2021

It's definitely some kind of plugin or setting interaction, since your minimal config file works perfectly for me. I'm doing a binary search through my config

edit: something I'm realizing - I'm not seeing the same behavior between what I think are lsp snippets and the ones installed by friendly snippets. think I need to setup the capabilities config of the language server for the lsp snippets

@ndavd
Copy link
Author

ndavd commented Oct 10, 2021

somehow vim-matchup was messing with the completion menu for nvim-cmp in showing snippets, although they still won't expand. continuing to tinker with it

Just tried removing it but the issue still persists...

@marwan38
Copy link

It's definitely some kind of plugin or setting interaction, since your minimal config file works perfectly for me. I'm doing a binary search through my config

edit: something I'm realizing - I'm not seeing the same behavior between what I think are lsp snippets and the ones installed by friendly snippets. think I need to setup the capabilities config of the language server for the lsp snippets

I realised that I had forgotten to add the capabilities to my lsp configs, but, that did not bring back my snippets.

Snippets work with lua, but for php and tsserver, they're still not working.
Removing vim-matchup is not bringing it back either. It's def. some other plugin that I'm running.

@ndavd
Copy link
Author

ndavd commented Oct 10, 2021

@marwan38 could you try it with html? you should get an html5 snippet for example

@marwan38
Copy link

@marwan38 could you try it with html? you should get an html5 snippet for example

Nope, nothing.

@ndavd
Copy link
Author

ndavd commented Oct 10, 2021

same... let's keep trying... if the minimal config works then it has got to be some sort of plugin incompatibility

@ndavd
Copy link
Author

ndavd commented Oct 10, 2021

Something weird is going... the issue seems to be related with a plugin because the minimal reproduce works. But... it also works with my config if I use stable neovim... Confusing...

@jebaum
Copy link

jebaum commented Oct 11, 2021

possibly related andymass/vim-matchup#186

@ndavd
Copy link
Author

ndavd commented Oct 11, 2021

hmm the thing is.. even if I remove matchup the issue still persists

@hrsh7th
Copy link
Owner

hrsh7th commented Oct 11, 2021

Has anyone tried binary search?

@ndavd
Copy link
Author

ndavd commented Oct 11, 2021

I did but I wasn't able to pinpoint what's causing the issue

@ndavd
Copy link
Author

ndavd commented Oct 11, 2021

@hrsh7th could I send you my config and you try it? I have literally tried isolating every plugin and I still can't figure out what's wrong... Do you have a place I could send you my configs?

@wimstefan
Copy link

You could try loading friendly-snippets after cmp-vsnip ... worked for me with the following config snippet:

use {
  'hrsh7th/cmp-vsnip',
  after = 'nvim-cmp',
  requires = {
    'hrsh7th/vim-vsnip',
    {
      'rafamadriz/friendly-snippets',
      after = 'cmp-vsnip'
    }
  }
},

@ndavd
Copy link
Author

ndavd commented Oct 11, 2021

woah that indeed works!! Is there a perhaps more simple way of getting the same output?

@ndavd
Copy link
Author

ndavd commented Oct 11, 2021

@wbthomason any thoughts on that ^ ^ ^

@ndavd
Copy link
Author

ndavd commented Oct 11, 2021

I currently have this on my config and it is working...

  use 'hrsh7th/nvim-cmp'
  use 'hrsh7th/cmp-nvim-lsp'
  use 'hrsh7th/cmp-buffer'
  use 'hrsh7th/cmp-path'
  use 'ray-x/cmp-treesitter'
  use 'f3fora/cmp-spell'
  use {
    'hrsh7th/cmp-vsnip',
    after = 'nvim-cmp',
    requires = {
      'hrsh7th/vim-vsnip',
      {
        'rafamadriz/friendly-snippets',
        after = 'cmp-vsnip'
      }
    }
  }

But maybe it would be better if every cmp-* plugin was loaded after nvim-cmp to avoid future errors... Any idea how to do so without specifying it individually?

@wbthomason
Copy link

wbthomason commented Oct 11, 2021

@ndav1d You could write a loop like:

local cmp_plugins = {
  'hrsh7th/cmp-nvim-lsp',
  'hrsh7th/cmp-buffer',
  'hrsh7th/cmp-path',
  'ray-x/cmp-treesitter',
  'f3fora/cmp-spell',
  {
    'hrsh7th/cmp-vsnip',
    after = 'nvim-cmp',
    requires = {
      'hrsh7th/vim-vsnip',
      {
        'rafamadriz/friendly-snippets',
        after = 'cmp-vsnip',
      },
    },
  },
}

for _, spec in ipairs(cmp_plugins) do
  if type(spec) == 'string' then
    spec = { spec }
  end

  if spec.after == nil then
    spec.after = 'nvim-cmp'
  else
    if type(spec.after) == 'string' then
      spec.after = {spec.after}
    end

    spec.after[#spec.after + 1] = 'nvim-cmp'
  end

  use(spec)
end

Though I'll note that this is probably overkill for a small set of plugins. It would be interesting if packer let you specify a context of settings which should be applied to a set of plugin specs, but we don't currently - maybe this is a worthwhile feature to add?

@ndavd
Copy link
Author

ndavd commented Oct 11, 2021

Though I'll note that this is probably overkill for a small set of plugins. It would be interesting if packer let you specify a context of settings which should be applied to a set of plugin specs, but we don't currently - maybe this is a worthwhile feature to add?

@wbthomason it would be a killer feature! pls implement it <33

@marwan38
Copy link

marwan38 commented Oct 11, 2021

Has anyone tried binary search?

What do you mean? How do you apply a binary search against a plugin list? I tried disabling all my plugins, only thing remained was the completion and LSP.

You could try loading friendly-snippets after cmp-vsnip ... worked for me with the following config snippet:

use {
  'hrsh7th/cmp-vsnip',
  after = 'nvim-cmp',
  requires = {
    'hrsh7th/vim-vsnip',
    {
      'rafamadriz/friendly-snippets',
      after = 'cmp-vsnip'
    }
  }
},

Unfortunately, that doesn't work for me either.

I will try luasnip after work and see if that one works for me.

@ndavd
Copy link
Author

ndavd commented Oct 11, 2021

@marwan38
It worked for me. Try disabling all your plugins, keep completion and LSP like you did before, and then use that method:

use {
  'hrsh7th/cmp-vsnip',
  after = 'nvim-cmp',
  requires = {
    'hrsh7th/vim-vsnip',
    {
      'rafamadriz/friendly-snippets',
      after = 'cmp-vsnip'
    }
  }
},

@hrsh7th
Copy link
Owner

hrsh7th commented Oct 11, 2021

I believe the LuaSnip will work for you :)

@marwan38
Copy link

I believe the LuaSnip will work for you :)

It was indeed the version of nvim. 0.5.1 is displaying the snippets just fine. It does not work as intended on nightly though.

@wimstefan
Copy link

Hmmm interesting - it works for me on Nightly without a problem ...

NVIM v0.6.0-dev+453-gd288daac2
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
This is my nvim-cmp configuration:
use {
  'hrsh7th/nvim-cmp',
  requires = {
    {
      'hrsh7th/cmp-nvim-lua',
      after = 'nvim-cmp'
    },
    {
      'hrsh7th/cmp-nvim-lsp',
      after = 'nvim-cmp',
    },
    {
      'hrsh7th/cmp-vsnip',
      after = 'nvim-cmp',
      requires = {
        'hrsh7th/vim-vsnip',
        {
          'rafamadriz/friendly-snippets',
          after = 'cmp-vsnip'
        }
      }
    },
    {
      'f3fora/cmp-spell',
      after = 'nvim-cmp'
    },
    {
      'hrsh7th/cmp-buffer',
      after = 'nvim-cmp'
    },
    {
      'hrsh7th/cmp-calc',
      after = 'nvim-cmp'
    },
    {
      'hrsh7th/cmp-path',
      after = 'nvim-cmp'
    },
  },
  config = function()
    local has_words_before = function()
      local line, col = unpack(vim.api.nvim_win_get_cursor(0))
      return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match('%s') == nil
    end
    local feedkey = function(key, mode)
      vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
    end
    local cmp = require('cmp')
    cmp.setup {
      documentation = {
        border = 'rounded'
      },
      formatting = {
        format = function(entry, vim_item)
          vim_item.menu = ({
            buffer = '[Buffer]',
            calc = '[Calc]',
            vsnip = '[Snippet]',
            nvim_lsp = '[LSP]',
            nvim_lua = '[Lua]',
            path = '[Filesystem]',
            spell = '[Spelling]',
          })[entry.source.name]
          vim_item.kind = vim.lsp.protocol.CompletionItemKind[vim_item.kind] .. ' ' .. vim_item.kind
          return vim_item
        end
      },
      mapping = {
        ['<Tab>'] = cmp.mapping(function(fallback)
          if cmp.visible() then
            cmp.select_next_item()
          elseif vim.fn['vsnip#available']() == 1 then
            feedkey('<Plug>(vsnip-expand-or-jump)', '')
          elseif has_words_before() then
            cmp.complete()
          else
            fallback()
          end
        end, { 'i', 's' }),
        ['<S-Tab>'] = cmp.mapping(function()
          if cmp.visible() then
            cmp.select_prev_item()
          elseif vim.fn['vsnip#jumpable'](-1) == 1 then
            feedkey('<Plug>(vsnip-jump-prev)', '')
          end
        end, { 'i', 's' }),
        ['<C-d>'] = cmp.mapping.scroll_docs(-4),
        ['<C-f>'] = cmp.mapping.scroll_docs(4),
        ['<C-Space>'] = cmp.mapping.complete(),
        ['<C-e>'] = cmp.mapping.close(),
        ['<CR>'] = cmp.mapping.confirm({
          behavior = cmp.ConfirmBehavior.Insert,
          select = true,
        }),
      },
      snippet = {
        expand = function(args)
          vim.fn["vsnip#anonymous"](args.body)
        end
      },
      sources = {
        {name = 'nvim_lua'},
        {name = 'nvim_lsp'},
        {name = 'buffer',
          opts = {
            get_bufnrs = function()
              local bufs = {}
              for _, win in ipairs(vim.api.nvim_list_wins()) do
                bufs[vim.api.nvim_win_get_buf(win)] = true
              end
              return vim.tbl_keys(bufs)
            end
          }
        },
        {name = 'vsnip'},
        {name = 'spell'},
        {name = 'path'},
        {name = 'calc'},
      }
    }
  end,
}

@oncomouse
Copy link

I was also having this problem with nightly but not 0.5.1 (but I don't use nvim-cmp). I had to explicitly tell packer to load vim-vsnip-integ and friendly-snippets after vim-vsnip, like this:

use {
	"hrsh7th/vim-vsnip",
	requires = {
		{ "hrsh7th/vim-vsnip-integ", after = "vim-vsnip" },
		{ "rafamadriz/friendly-snippets", after = "vim-vsnip" },
	},
}

Before doing this, I disabled all other plugins and the problem persisted. For me, it was not a plugin interaction problem.

@hrsh7th
Copy link
Owner

hrsh7th commented Oct 13, 2021

I think it's not a vsnip problem. What do you think about it...?

@ndavd
Copy link
Author

ndavd commented Oct 13, 2021

yeah it's probably not. It seems to be related with the order the plugin manager is loading the various plugins... so I think I'm going to close this issue

@ndavd ndavd closed this as completed Oct 13, 2021
@marwan38
Copy link

Found my issue, it was the one thing I forget to disable because it existed in the root of my config. It was impatient.nvim. Snippets work just fine now with the above loading methods. Thank you everyone

@ndavd
Copy link
Author

ndavd commented Oct 13, 2021

Good to know! :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants