hrsh7th / vim-vsnip

Snippet plugin for vim/nvim that supports LSP/VSCode's snippet format.
MIT License
876 stars 37 forks source link

Can not get vsnip to work #238

Closed Q-Xue closed 2 years ago

Q-Xue commented 2 years ago

I installed vim-vsnip, nvim-cmp, vim-vsnip-integ. Below is my cmp configuration.

Tabnine and lsp both work. But vsnip does not work.

I am using Window OS.

I config vsnip: let g:vsnip_snippet_dir = 'C:\Users\eidan\AppData\Local\nvim-data\site\vsnip'

Then I create a python.json file there and copy a very simple snippet in the file.

{ "try/except": { "prefix": "try/except", "body": [ "try:", "\t${1:pass}", "except ${2:expression} as ${3:identifier}:", "\t${4:pass}" ], "description": "Code snippet for a try/except statement" } }

I open a python file, type try, I can see tabnine and lsp completion item, but no vsnip completion item.

What did I miss?

My cmp config:

set completeopt=menu,menuone,noselect

lua <<EOF -- Setup nvim-cmp. local cmp = require'cmp'

-- local luasnip = require("luasnip") -- require("luasnip/loaders/from_vscode").lazy_load()

--local check_backspace = function() --local col = vim.fn.col "." - 1 --return col = 0 or vim.fn.getline("."):sub(col, col):match "%s" --end

local lspkind = require('lspkind')

local source_mapping = { buffer = "[Buffer]", nvim_lsp = "[LSP]", vsnip = "[Vsnip]", nvim_lua = "[Lua]", cmp_tabnine = "[TN]", path = "[Path]", }

local tabnine = require('cmp_tabnine.config') tabnine:setup({ max_lines = 1000; max_num_results = 20; sort = true; run_on_every_keystroke = true; snippet_placeholder = '..'; ignored_file_types = { -- default is not to ignore -- uncomment to ignore in lua: -- lua = true }; })

cmp.setup({ snippet = { -- REQUIRED - you must specify a snippet engine expand = function(args) vim.fn"vsnip#anonymous" -- For vsnip users. -- luasnip.lsp_expand(args.body) -- For luasnip users. -- vim.fn"UltiSnips#Anon" -- For ultisnips users. -- require'snippy'.expand_snippet(args.body) -- For snippy users. end, }, mapping = { [''] = cmp.mapping.select_prev_item(), [''] = cmp.mapping.select_next_item(),

  ['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
  ['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
  ['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
  ['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
  ['<C-e>'] = cmp.mapping({
    i = cmp.mapping.abort(),
    c = cmp.mapping.close(),
  }),
  -- Accept currently selected item. If none selected, `select` first item.
  -- Set `select` to `false` to only confirm explicitly selected items.
  ['<CR>'] = cmp.mapping.confirm({ select = true }),
  --['<Tab>'] = cmp.mapping(
    --function(fallback)
      --if cmp.visible() then
        --cmp.select_next_item()
      --elseif luasnip.expandable() then
        --luasnip.expand()
      --elseif luasnip.expand_or_jumpable() then
        --luasnip.expand_or_jump()
      --elseif check_backspace() then
        --fallback()
      --else
        --fallback()
      --end
    --end, {"i", "s",}
  --),
  --['<S-Tab>'] = cmp.mapping(
    --function(fallback)
      --if cmp.visible() then
        --cmp.select_prev_item()
      --elseif luasnip.jumpable(-1) then
        --luasnip.jump(-1)
      --else
        --fallback()
      --end
    --end, {"i", "s",}
  --),
},
sources = cmp.config.sources({                            
{ name = 'cmp_tabnine' },            
{ name = 'nvim_lsp' },               
{ name = 'vsnip' },                  
{ name = 'nvim_lua' },               
-- { name = 'treesitter' },          
{ name = 'buffer' },              
{ name = 'path' },                
{ name = 'emoji' },                  
{ name = 'calc' },                   
{ name = 'fuzzy_path'},              

}),
--sources = cmp.config.sources( --{ --{ name = 'cmp_tabnine' }, --}, --{ --{ 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' }, --} --) formatting = { fields = {"abbr", "kind", "menu"}, format = function(entry, vim_item) -- kind icons vim_item.kind = lspkind.presets.default[vim_item.kind] local menu = source_mapping[entry.source.name] if entry.source.name == 'cmp_tabnine' then if entry.completion_item.data ~= nil and entry.completion_item.data.detail ~= nil then menu = entry.completion_item.data.detail .. ' ' .. menu end vim_item.kind = '' end vim_item.menu = menu return vim_item end }, documentation = true, experimental = { ghost_text = true, native_menu = false, }, })

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

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

EOF

hrsh7th commented 2 years ago

I can't understand. Did you install hrsh7th/cmp-vsnip?

Q-Xue commented 2 years ago

That was the problem : P I forgot to install cmp-vsnip... It is working now! Thanks.